Skip to content

Instantly share code, notes, and snippets.

@alvinsj
Created April 16, 2012 08:27
Show Gist options
  • Save alvinsj/2397067 to your computer and use it in GitHub Desktop.
Save alvinsj/2397067 to your computer and use it in GitHub Desktop.
webapp unique id for analytics
function adbotGetCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name){return unescape(y);}
}
}
function adbotSetCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function guidGenerator() {
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function adbotGetSessionId()
{
var sid=adbotGetCookie("__adbot_sid");
if (sid!=null && sid!="") {
return sid;
}
else {
sid = new Date().getTime().toString()+"."+guidGenerator();
adbotSetCookie("__adbot_sid",sid,365);
return sid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment