Created
November 8, 2012 14:10
-
-
Save brunobar79/4039015 to your computer and use it in GitHub Desktop.
analytics tracking in chrome extension
This file contains hidden or 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
| var _gaq = _gaq || []; | |
| _gaq['_setAccount'] = 'UA-XXXXX-1'; | |
| _gaq['_setDomain'] = 'youdomain.com'; | |
| function rand(from,to) | |
| { | |
| return Math.floor(Math.random()*(to-from+1)+from); | |
| } | |
| var i = 1000000000, | |
| utmn = rand(i,9999999999), //random request number | |
| cookie = rand(10000000,99999999), //random cookie number | |
| random = rand(i,2147483647), //number under 2147483647 | |
| today = new Date().getTime(), | |
| win = window.location, | |
| urchinUrl = window.location.protocol+'//www.google-analytics.com/__utm.gif?utmwv=1.3&utmn=' | |
| +utmn+'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=' | |
| +_gaq._setDomain+'&utmr='+win+'&utmp=' | |
| +'/'+document.location.href+'&utmac=' | |
| +_gaq._setAccount+'&utmcc=__utma%3D' | |
| +cookie+'.'+random+'.'+today+'.'+today+'.' | |
| +today+'.2%3B%2B__utmb%3D' | |
| +cookie+'%3B%2B__utmc%3D' | |
| +cookie+'%3B%2B__utmz%3D' | |
| +cookie+'.'+today | |
| +'.2.2.utmccn%3D(referral)%7Cutmcsr%3D' + win.host + '%7Cutmcct%3D' + win.pathname + '%7Cutmcmd%3Dreferral%3B%2B__utmv%3D' | |
| +cookie+'.-%3B'; | |
| var img = document.createElement('img'); | |
| img.src = urchinUrl; | |
| img.onload = function(){ | |
| document.getElementsByTagName('body')[0].removeChild(this); | |
| } | |
| document.getElementsByTagName('body')[0].appendChild(img); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment