How to Measure Activity Frequency in Google Analytics
After reading Li Jin and Andrew Chen’s post about power user curves I wanted to try out the concept with Google Analytics data. It turned out to be harder than expected because, surprisingly, GA doesn’t have a view or query that reveals how many users visited x days in a given date range.
How many users visited every day this week sounds like a simple question but GA can’t answer it.
The closest question we can answer with GA is how many users had x sessions in a given date range. So this doesn’t exactly give us the “L30” day-based histogram mentioned in their post, but it gives us something pretty close.
GA’s Frequency > Count of Sessions Isn’t Helpful
GA has a Count of Sessions view under the Frequency & Recency tab, but this is one of those GA things that doesn’t do what you might expect it to. It ignores the date range and shows lifetime session counts for users. It also doesn’t de-dupe between the buckets, so a user with 10 sessions is also represented in the 9, 8, 7, etc buckets.
To find out how many users had 30 sessions last month we have to use a segment. To calculate how many users had 30, 29, 28, etc sessions we need to use dynamic segments, which means we have to use the API.
I have some example code below but first here are a few examples of the sort of data this can produce.
This is based on the L7 histogram mentioned in Jin and Chen’s post. Again, instead of showing the number of days that users were active it shows the user’s number of sessions in a 7-day period.
Comparing Segments and Cohorts
We can plot different segments, cohorts, or products to see how the user activity frequency compares.
Another example, using a 30-day timeframe:
API Code Example
The only thing of note going on here in the query is the dynamic segment. For
each request we need a
users::condition::ga:sessions==x segment. To prevent
users from appearing in multiple groups we use the == operator instead of >.
We’ll often want to know the number of users whose session count exceeded the upper bound so the loop switches the operator on the last step.
This prints out an array that you can drop into a charting tool or Google Sheets to graph.
This was just a short post explaining how to work out the GA mechanics. To understand the purpose and why these frequency curves are interesting, make sure to read Li Jin and Andrew Chen’s post.