Skip to content
Snippets Groups Projects
Commit f1e0c891 authored by Markus Mächler's avatar Markus Mächler Committed by Demian Katz
Browse files

Introduces piwik tracker object to be able to have multiple piwik backends

parent dcc8f5fb
No related merge requests found
...@@ -288,12 +288,14 @@ class Piwik extends \Zend\View\Helper\AbstractHelper ...@@ -288,12 +288,14 @@ class Piwik extends \Zend\View\Helper\AbstractHelper
protected function getOpeningTrackingCode() protected function getOpeningTrackingCode()
{ {
return <<<EOT return <<<EOT
var _paq = _paq || [];
(function(){ function initVuFindPiwikTracker(){
_paq.push(['setSiteId', {$this->siteId}]); var VuFindPiwikTracker = Piwik.getTracker();
_paq.push(['setTrackerUrl', '{$this->url}piwik.php']);
_paq.push(['setCustomUrl', location.protocol + '//' VuFindPiwikTracker.setSiteId({$this->siteId});
+ location.host + location.pathname]); VuFindPiwikTracker.setTrackerUrl('{$this->url}piwik.php');
VuFindPiwikTracker.setCustomUrl(location.protocol + '//'
+ location.host + location.pathname);
EOT; EOT;
} }
...@@ -306,12 +308,14 @@ EOT; ...@@ -306,12 +308,14 @@ EOT;
protected function getClosingTrackingCode() protected function getClosingTrackingCode()
{ {
return <<<EOT return <<<EOT
_paq.push(['enableLinkTracking']); VuFindPiwikTracker.enableLinkTracking();
};
(function(){
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.defer=true; g.async=true; g.type='text/javascript'; g.defer=true; g.async=true;
g.src='{$this->url}piwik.js'; g.src='{$this->url}piwik.js';
g.onload=initVuFindPiwikTracker;
s.parentNode.insertBefore(g,s); })(); s.parentNode.insertBefore(g,s); })();
EOT; EOT;
} }
...@@ -338,7 +342,7 @@ EOT; ...@@ -338,7 +342,7 @@ EOT;
$value = $escape($value); $value = $escape($value);
$code .= <<<EOT $code .= <<<EOT
_paq.push(['setCustomVariable', $i, '$key', '$value', 'page']); VuFindPiwikTracker.setCustomVariable($i, '$key', '$value', 'page');
EOT; EOT;
} }
...@@ -362,7 +366,7 @@ EOT; ...@@ -362,7 +366,7 @@ EOT;
// Use trackSiteSearch *instead* of trackPageView in searches // Use trackSiteSearch *instead* of trackPageView in searches
return <<<EOT return <<<EOT
_paq.push(['trackSiteSearch', '$searchTerms', '$searchType', $resultCount]); VuFindPiwikTracker.trackSiteSearch('$searchTerms', '$searchType', $resultCount);
EOT; EOT;
} }
...@@ -375,7 +379,7 @@ EOT; ...@@ -375,7 +379,7 @@ EOT;
protected function getTrackPageViewCode() protected function getTrackPageViewCode()
{ {
return <<<EOT return <<<EOT
_paq.push(['trackPageView']); VuFindPiwikTracker.trackPageView();
EOT; EOT;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment