czwartek, lutego 17, 2011

UTMU Google Analytics Request Parameter

During creation of backend PHP component to track page views with use Google Analytics without user knowledge I have encountered interesting problem. GIF request contains parameter which seems to be unrelated to page or view parameters. I have analyzed ga.js code and found that this parameter is created basing on table filled with true/false values. Nothing less, nothing more. Only true/false.

Code responsible for creation of utmu parameter basing on this table can be presented in this form (distributed on WTFPL license):

var usage = []; function setUsage(index) { usage[index] = true; }; function getUsage() { var allChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; var temp = []; for (h = 0; h < usage.length; h++) if (usage[h]) { temp[Math.floor(h / 6)] ^= 1 << h % 6; } for (h = 0; h < temp.length; h++) temp[h] = allChars.charAt(temp[h] || 0); return temp.join("") };
It's looks like that above parameter is not required or validated, it is used only for statistical purposes (analytics inside of analytics). List of functions with their codes found in ga.js file:

It is important to mention that, like everything else this code is not guaranteed to always work as it has been described by me. Google can change this anytime in the way which fit they needs the best. When it is currently not checked it can be checked against validity in the future.