Reputation: 1457
I am working on implementing Piwik on my website. I've included the tracking code just before the </body>
on each page and have Piwk appropriately (I think) on my server. It doesn't work, and I'm starting the process of finding out why. I have two current questions:
First, the tracking code is:
<!-- Piwik --> <script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://terryliittschwager.com/analytics/" : "http://terryliittschwager.com/analytics/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
<!-- End Piwik Code -->
I see that the code is split into two <script></script>
sections. Why is that necessary? Would it not work as a single script?
Second, rather than placing the tracking code in each web page, would it also work if there was a <script src='trackingcode.js'></script>
just before the </body>
?
I've tried these alternate ways while attempting to get it to work, but as of yet no success.
Thank you for your time!
Upvotes: 1
Views: 5413
Reputation: 546
I would try moving to the ASYNC code which is the new code. It should also improve performance
<!-- Piwik --> <script type="text/javascript">
var _paq = _paq || [];
(function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/");
_paq.push(['setSiteId', {$IDSITE}]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
s.parentNode.insertBefore(g,s); })();
</script>
<!-- End Piwik Code -->
http://piwik.org/docs/javascript-tracking/#toc-where-can-i-find-the-piwik-tracking-code
Upvotes: 3