Skip to content

Commit

Permalink
Initial commit of the ga-cookie script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Crowder committed Mar 13, 2015
1 parent 28e61fd commit 0fae750
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ga-cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var ga_cookie = (function () {
var ga_cookie = function () {
var self = this;

var utmz = readCookie('__utmz');
var pairs = utmz.split('.').slice(4).join('.').split('|');
for (var i = 0; i < pairs.length; i++) {
var temp = pairs[i].split('=');
self[temp[0]] = temp[1];
}

// readCookie(name)
// Read the cookie (taken from: http://www.quirksmode.org/js/cookies.html)
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

return self;
};

return ga_cookie;
})();

0 comments on commit 0fae750

Please sign in to comment.