i2=l.indexOf(s,i); if (i2
c=l.substring((i+i3),i2);
}
return c;
}
//Retrieve campaign and referrer info from the _utmz cookie
var z = _uGC(document.cookie, '__utmz=', ';');
var source = _uGC(z, 'utmcsr=', '|');
var medium = _uGC(z, 'utmcmd=', '|');
var term = _uGC(z, 'utmctr=', '|');
var content = _uGC(z, 'utmcct=', '|');
var campaign = _uGC(z, 'utmccn=', '|');
var gclid = _uGC(z, 'utmgclid=', '|');
//Replace empty values (marked by a dash) with an empty string
if(source=="-"){source=""};
if(medium=="-"){medium=""};
if(term=="-"){term=""};
if(content=="-"){content=""};
if(campaign=="-"){campaign=""};
//If gclid is present, explicitly set source/medium to google/cpc
if (gclid !=="-") {
source = 'google';
medium = 'cpc';
}
//Build utmString
var utmString = source;
utmString=utmString+"!"+medium;
utmString=utmString+"!"+campaign;
utmString=utmString+"!"+term;
utmString=utmString+"!"+content;
//Replace URL-encoded 'spaces' with dashes
utmString=utmString.replace('%20','-');
//RegEx to retain only whitelisted characters
utmString=utmString.replace(/[^a-zA-Z0-9-~!*_.]/g,'');
//Set string to specific length
utmString=utmString.substr(0,62);
//Set first touch information if not already there, using slot 3
var fT=pageTracker._getVisitorCustomVar(3);
if(!fT){
pageTracker._setCustomVar(3,'FT',utmString,1);
}
Finally, a word on why first-touch traffic source information can be so valuable. GA’s default attribution model gives you only one view of how valuable various traffic sources are for you. Getting another view can only help you, especially because GA’s default model tends to undervalue traffic sources that may not be as prone to immediate direct response, but could still be adding value for you. Examples of this kind of traffic commonly include display advertising (e.g. Google content network, other banner campaigns) and social networking. By storing first-touch source information, you give yourself the ability to perform a more holistic assessment of the value of these kinds of traffic.
Be aware that this does not only apply to storing first touch information in the cookie. You should always make sure that your cookie length is not too long and does not contain any special characters.
If you have questions on first-touch source information or our solution above, feel free to leave them in the comments. To get more analytics tips and tricks, don’t forget to subscribe to our feed and follow us on
Twitter!