Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Owner

dominikzogg commented Feb 14, 2012

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

This comment has been minimized.

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