Cohort Analysis In Google Analytics
You might have heard of Cohort Analysis – it’s a time-tested segmentation technique used to understand user behavior.
Cohort analysis has never been a core part of Google Analytics – it’s always been a bit of a hack. I wanted to discuss how to do cohort analysis with Google Analytics today and what it might look like in the future.
What is a Cohort?
Let’s use a definition from Wikipedia:
A cohort is a group of people who share a common characteristic or experience> within a defined period (e.g., are born, are exposed to a drug or vaccine or pollutant, or undergo a certain medical procedure). Thus a group of people who were born on a day or in a particular period, say 1948, form a birth cohort.
Cohort analysis really comes into its own when you analyze groups of similar people in some deeper/more relevant, business context.
Here’s an example. We want to create a cohort based on first purchase date. We would need to set a visitor scoped custom variable that contains the date when a visitor made their first purchase.
We would need to use the following code:
_gaq.push(['setCustomVar', 1,'FPD', 'YYYYMMDD', 1]);
The custom variable is named FPD (for First purchase Date). The date is formatted using the four-digit year, two-digit month and two-digit day. This format will let us create a lot of different cohorts using advanced segments. More on this below.
Remember, the code above needs to be placed on the site’s thank you page. But, it can only be added when a person makes their first purchase. We don’t want to set this cookie when people make their second or third purchase.
Obviously you’ll need some code to identify if the purchase is a first purchase or a repeat purchase.
It is possible that this data could be erased if the user deletes their cookies. You could always create some more code to keep resetting this cookie when the user logs into the site.
Using Events to create Cohorts
Another way to add user data to Google Analytics is via an event. You can send the same data, but you just need to do it more often.
Here’s the event code:
_gaq.push(['trackEvent', 'Cohorts','FirstPurchase', 'YYYYMMDD']);
Because an event is not stored as a cookie you need to fire an event every single time the user visits the site. This means that you need to know that the user is a customer and insert the event code on a page the user will see. You might put it on the login page or you might just include it in the standard page tag. Depending on your site, this could be a lot of coding.
I’m not a fan of this method. It takes too much work.
I prefer to use a custom variable because it will persist and provide more reliable data.However, I would hedge my bets and try to add a little code that identifies when a user logs in and checks and resets the cookie.
The Future of Cohorts in Google Analysis
Cohort Analysis is going to get a lot better in Google Analytics.
You may have used the new Remarketing feature. This tool does true user segmentation. This includes the option to create a cohort using various date dimensions. This is going to be the future of segmentation in analytics.
User segmentation, and the ability to create cohorts, will be the gateway to many different types of new analysis.
Cohort analysis really comes into its own when you analyze groups of similar people in some deeper/more relevant, business context.