-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of the ga-cookie script.
- Loading branch information
Aaron Crowder
committed
Mar 13, 2015
1 parent
28e61fd
commit 0fae750
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
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
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; | ||
})(); |