-
-
Save fmoliveira/fd6a8dca086ee7f7ff153e2c109f06f6 to your computer and use it in GitHub Desktop.
Google Analytics in Atom Shell
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
// Pretend that cookies work | |
(function (document) { | |
var cookies = {}; | |
document.__defineGetter__('cookie', function () { | |
var output = []; | |
for (var cookieName in cookies) { | |
output.push(cookieName + "=" + cookies[cookieName]); | |
} | |
return output.join(";"); | |
}); | |
document.__defineSetter__('cookie', function (s) { | |
var indexOfSeparator = s.indexOf("="); | |
var key = s.substr(0, indexOfSeparator); | |
var value = s.substring(indexOfSeparator + 1); | |
cookies[key] = value; | |
return key + "=" + value; | |
}); | |
document.clearCookies = function () { | |
cookies = {}; | |
}; | |
// Pretend that we're hosted on an Internet Website | |
document.__defineGetter__('location', function() { | |
return { | |
href: 'http://atom-shell.local/', | |
protocol: 'http:', | |
host: 'atom-shell.local', | |
port: '', | |
pathname: '/', | |
search: '', | |
hash: '', | |
username: '', | |
password: '', | |
origin: 'http://atom-shell.local' | |
}; | |
}); | |
// Nobody sets location | |
document.__defineSetter__('location', function() {}) | |
})(document); | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); | |
ga('create', '****** YOUR TOKEN HERE*****', 'auto'); | |
ga('send', 'pageview'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment