Piwik page load tracking


#1

Hi,

Thanks once again for the support provided.
I am having a small query regarding the pasting of the tracking code provided below.

var page_load_start = new Date(); alert(page_load_start); var _paq = _paq || []; window.onload = (function(){ var page_load_end = new Date(); var load_time = page_load_end.getTime() - page_load_start.getTime(); //load_time = parseInt( load_time / 100 )*100; alert(page_load_end); alert(load_time); var u=(("https:" == document.location.protocol) ? "https://10.232.35.109/piwik/" : "https://10.232.35.109/piwik/"); _paq.push(['setSiteId',4]); _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setCustomVariable',3,'landingPageTime',load_time,'page']); _paq.push([ function() { var customVariable = this.getCustomVariable(3); }]); _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); })(); This code includes the function for calculating the page load time. But since it is triggered during page load, is it ok if we paste that part of code just before the tag. If so how can we split the code. I have gone through the ga forum where they have actually splitted the code and pasted it in the head and the body tag. I used the same principle but when splitting, the tracking of visit itself is not happenening. Please help me fix this issue. Thanks :)

(Matthieu Aubry) #2

What is the problem?


(vipsoft) #3

Remove the () at the end. This causes the function to be executed right away instead.of when the onload is.triggered.