Skip to content

Instantly share code, notes, and snippets.

@dominikzogg
Created January 8, 2012 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominikzogg/1578450 to your computer and use it in GitHub Desktop.
Save dominikzogg/1578450 to your computer and use it in GitHub Desktop.
Load Contao Piwik tracking after window load
<!-- indexer::stop -->
<!-- Piwik -->
<script type="text/javascript">
<!--//--><![CDATA[//><!--
window.addEvent('load', function()
{
var pkBaseURL = 'https:' == document.location.protocol ? 'https://www.<domain>.<tld>/' : 'http://www.<domain>.<tld>/';
Asset.javascript(pkBaseURL + 'piwik.js',
{
onLoad: function(){
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + 'piwik.php', <id>);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
}
});
});
//--><!]]>
</script>
<!-- End Piwik Tag -->
<!-- indexer::continue -->
@rocco
Copy link

rocco commented Feb 14, 2012

I'm wondering if that negatively affects Piwik's time counters (window.onload is set off from loading piwik.js if not done like this)?

@dominikzogg
Copy link
Author

the mootools window.addEvent('load', function(){}); loads not on dom ready, it loads after all images are loaded to, so theres no usable time tracking if you include it this way.

@rocco
Copy link

rocco commented Feb 14, 2012

True, that's why I was asking. Btw. this not only the case for mootools but for window.onload in general (load event fires at the end of the document loading process, cf. MDN).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment