Skip to content

Instantly share code, notes, and snippets.

@takatama
Last active December 15, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takatama/5263715 to your computer and use it in GitHub Desktop.
Save takatama/5263715 to your computer and use it in GitHub Desktop.
Cohort Anarisis in Google Analytics
try {
var f = function (d) {
return d.getFullYear() + ("0" + (d.getMonth() + 1)).slice(-2) + ("0" + d.getDate()).slice(-2);
};
var c = document.cookie;
var i = c.indexOf('__utma');
var s = null;
if (i < 0) {
s = f(new Date());
} else {
var utma = c.substring(i, c.indexOf(';', i));
if (utma) {
var v = utma.split('.');
if (v[2]) {
var date = new Date();
date.setTime(v[2] * 1000);
s = f(date);
}
}
}
if(s) {
_gaq.push(['_setCustomVar', 1, 'FirstVisit', s, 1]);
}
} catch (e) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment