Skip to content

Instantly share code, notes, and snippets.

@printminion
Created April 26, 2013 20:00
Show Gist options
  • Save printminion/5470062 to your computer and use it in GitHub Desktop.
Save printminion/5470062 to your computer and use it in GitHub Desktop.
function testGA() {
doTrack_('UA-NNNNNN-1', 'YORR_KEY', 'YOUR_SERVICE', 'YOUR_ID');
}
function doTrack_(utmac, key, service, user) {
var path = '/' + key + '/' + service + '/' + user;
try {
var host = 'YOUR_HOST';
var utmGifLocation = "http://www.google-analytics.com/__utm.gif";
// Construct the gif hit url.
var url = utmGifLocation + "?" +
"utmwv=4.4sa" +
//"&utmcn=1"+ //added - extra - not required
"&utmn=" + (new Date().getTime())+ //unique - cache buster
"&utmhn=" + host +
"&utmr=" + '-' +
"&utmp=" + encodeURIComponent(path) +
"&utmac=" + utmac +
"&utmcc=__utma%3D999.999.999.999.999.1%3B" +
"&utmvid=" + Math.random() +
"&utmip=" + '-';
Logger.log('GA:' + url);
var response = UrlFetchApp.fetch(url);
} catch(e) {
Logger.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment