I am creating my own GA library to build a url to the tracking pixel myself since I need to use GA in a cookie-less environment. But I am stuck on create the domain hash for the cookie format.
In this cookie:
__utma=126394024.179004532335319200.1247654493.1260769004.1260878051.7
The first segment 126394024
is apparently a "domain hash", and while many sites seem to show how it's used, I cant actually figure out how to generate it from a domain. Is this only done by an internal process on google servers that is unknown to the rest of the world? Or is there a way I can hash the domain name myself to produce this token?
Does this work?
http://www.google.com/support/forum/p/Google+Analytics/thread?tid=626b0e277aaedc3c&hl=en
function hash(d){
var a=1,c=0,h,o;
if(d){
a=0;
for(h=d["length"]-1;h>=0;h--){
o=d.charCodeAt(h);
a=(a<<6&268435455)+o+(o<<14);
c=a&266338304;
a=c!=0?a^c>>21:a
}
}
return a
}
Have not verified it myself
C# version of the above if anyone wants it:
string hash(string d)
{
int a = 1;
int c = 0;
int h;
int o;
if (!String.IsNullOrEmpty(d))
{
a = 0;
for (h = d.Length - 1; h >= 0; h--)
{
o = d[h];
a = (a << 6 & 268435455) + o + (o << 14);
c = a & 266338304;
a = c != 0 ? a ^ c >> 21 : a;
}
}
return a.ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With