Last active
August 29, 2015 14:07
-
-
Save fblundun/d6f3b1d147503db3c6a1 to your computer and use it in GitHub Desktop.
Extracting the user ID from the first-party Snowplow cookie
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
| /* | |
| * Function to extract the Snowplow user ID from the first-party cookie set by the Snowplow JavaScript Tracker | |
| * | |
| * @param string cookieName (optional) The value used for "cookieName" in the tracker constructor argmap | |
| * (leave blank if you did not set a custom cookie name) | |
| * | |
| * @return string or bool The ID string if the cookie exists or false if the cookie has not been set yet | |
| */ | |
| function getSnowplowDuid(cookieName) { | |
| cookieName = cookieName || '_sp_'; | |
| var c = document.cookie.split(';'); | |
| for (var i = 0; i < c.length; i++) { | |
| if (c[i].substr(0, 6) === cookieName + 'id') { | |
| return c[i].split('=')[1].split('.')[0]; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment