Created
November 24, 2010 15:25
-
-
Save getify/713809 to your computer and use it in GitHub Desktop.
create an auto-loader for Google Analytics (using LABjs)
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
/*! LAB.js v1.0.3 (c) Kyle Simpson MIT License */ | |
/* INCLUDE THE MINIFIED LAB.js CODE HERE */ | |
$LAB | |
.script('https:'==document.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js') | |
.wait(function(){ | |
var scripts = document.getElementsByTagName("script"), | |
src, i, len, | |
acct = "UA-XXXXX-X", | |
pageTracker | |
; | |
try { | |
for (i=0, len=scripts.length; i<len; i++) { | |
if (scripts[i] && scripts[i].src && | |
(src = scripts[i].src.match(/auto-ga\.js(?:\?[^#]*)?#(?:(?:.*?&)*?)acct=([^&]+)/i)) && | |
src[1]) | |
{ | |
acct = src[1]; | |
break; | |
} | |
} | |
} catch (err) {} | |
pageTracker = _gat._getTracker(acct); | |
pageTracker._trackPageview(); | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>LABjs Demo - auto-ga.js</title> | |
</head> | |
<body> | |
<!-- some stuff --> | |
<script src="/js/auto-ga.js#acct=UA-XXXXX-X"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment