Created
June 27, 2011 09:15
-
-
Save anselmh/1048549 to your computer and use it in GitHub Desktop.
prerender-avoid-ga
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if you have analytics, set them in pagevisibility mode to get real-user-trackig according to prerender-issues in Chrome/WebKit. | |
var viewCounted = false; | |
function handleVisibilityChange(evt) { | |
//Only count the view once we're done prerendering AND the document is done loading | |
if (document.webkitVisibilityState == 'prerender' | |
|| document.readyState != 'complete' || viewCounted) | |
return; | |
/* Implementation of view counting system starts here */ | |
// Code for Google Analytics | Change UA-XXXXX-X to be your site's ID | |
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview'],['_trackPageLoadTime']]; | |
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1; | |
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js'; | |
s.parentNode.insertBefore(g,s)}(document,'script')); | |
/* Implementation of view counting system ends here */ | |
viewCounted = true; | |
} | |
//We'll call checkCountView on load no matter what. | |
window.addEventListener('load', handleVisibilityChange, false); | |
if (document.webkitVisibilityState == 'prerender') { | |
document.addEventListener('webkitvisibilitychange', handleVisibilityChange, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://html5-demos.appspot.com/static/html5-whats-new/template/index.html#22