Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a google analytics domain hash

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?

like image 619
Alex Wayne Avatar asked Jan 27 '11 20:01

Alex Wayne


2 Answers

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

like image 94
brian_d Avatar answered Sep 25 '22 16:09

brian_d


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();
    }
like image 45
Nico Westerdale Avatar answered Sep 23 '22 16:09

Nico Westerdale