Skip to content

Instantly share code, notes, and snippets.

@robertjmoore
robertjmoore / push CV.js
Created August 11, 2012 18:13
Pushing custom variables to GA to store the created month and year of a website visitor
_gaq.push(['_setCustomVar', 1, 'Join month', <%= "'#{cohort_month}'" %>, 1]);
_gaq.push(['_setCustomVar', 2, 'Join year', <%= "'#{cohort_year}'" %>, 1]);
@robertjmoore
robertjmoore / generatecohortstring.php
Created August 11, 2012 18:50
Generate a string detailing all the cohorts a given user belongs to
<?php
function getQuarter() {
$monthNumber = intval(date("m"));
return floor(($monthNumber - 1) / 3) + 1;
}
function buildWeek() {
if (date('l') == "Sunday") {
$sundayTime = time();
}
else {
@robertjmoore
robertjmoore / pushcohort.js
Created August 11, 2012 18:53
pushing cohort string to ga
_gaq.push(['_setCustomVar', 1, 'cohort_data', {{cohortString}}, 1]);
@robertjmoore
robertjmoore / gist:3960013
Created October 26, 2012 17:12
Sample Query for Raw Cohort Analysis Data
SELECT orders.customerid,
orders.transactiondate,
orders.transactionamount,
cohorts.cohortdate
FROM orders
JOIN (SELECT customerid,
Min(transactiondate) AS cohortDate
FROM orders
GROUP BY customerid) AS cohorts
ON orders.customerid = cohorts.customerid;