Getting Analytics data for designing

1st July 2015

Google Analytics is widely used to gather information about how users interact with websites. As a developer, designer or product owner it’s really useful to use the information it collects to inform decisions. However, I often find that the Google Analytics interface can get in the way of getting the right data out quickly.

Instead I prefer to use the Google Analytics Query Explorer to get information out. The Query Explorer was initially designed to help developers construct queries for the Google Analytics API. It also works really well for getting specific information out of Google Analytics when you want to do your own data analysis.

The way that the Google Analytics API works is very similar to using an OLAP cube, you define the dimensions and metrics for the data you want to retrieve. You can think of dimensions as the discrete data sets, for example: browser name, page path, custom event name. Metrics on the other hand are the measurable value to go with your dimensions, for example: pageviews, page load time, goal completion numbers.

Using dimensions and metrics along with some filters and sorting I find you can easily get a much wider array of information out than you would be able to using the Google Analytics web interface.

For example if you wanted to see what browsers your users are using you could run:

dimensions = ga:browser
metrics    = ga:users
sort       = -ga:users

Using a GOV.UK analytics profile this would get you something like: (view with your own data in the Query Explorer)

Browser Users
Chrome 7,116,379
Safari 5,946,241
Internet Explorer 5,273,044
Firefox 1,456,829
Android Browser 554,881

I like to then add onto that date or time dimensions. This then lets me plot the number of pageviews (or other metric) over time. So for example if I wanted to see IE usage over time I could extend the previous query with something like:

dimensions = ga:browser,ga:hour,ga:dayOfWeek
metrics    = ga:users
filters    = ga:browser==Internet Explorer

Which would get you something like: (view with your own data in the Query Explorer)

Browser Hour Day of Week Users
Internet Explorer 00 0 5895
Internet Explorer 00 1 6814
Internet Explorer 00 2 8115
Internet Explorer 00 3 8000
Internet Explorer 00 4 8077

Then using the TSV export button in the Query Explorer, found at the bottom of the page, I can import the results into a Google Sheets and produce a quick graph of the data.

For another example if we had a page which used a query string to let users filter by a date field. You could get back all the different dates people filtered by:

dimensions = ga:pagePath
metrics    = ga:uniquePageviews
filters    = ga:pagePath=~.*from_date=[^&$]+.*
sort       = -ga:uniquePageviews

This would get you something like: (view with your own data in the Query Explorer)

Page Pageviews
[…]&from_date=23/06/2015&[…] 44
[…]from_date=31+March+2015&[…] 43
[…]&from_date=01/01/2015&[…] 41
[…]&from_date=15/06/2015&[…] 29
[…]&from_date=25/06/2015&[…] 27
[…]&from_date=30/04/2015&[…] 23

Using the TSV export in this case I could then parse the file using Ruby to generate the information I really want. You could also add onto that some date dimensions and see if the dates people pick, relative to the date they filtered for it, changes over time.

Obviously the Query Explorer is much more powerful than I have shown in these three examples, but hopefully this gives you an example of the kinds of things you can use it for. I rarely use the Google Analytics web interface directly any more preferring to graph or otherwise parse the data coming out of the Query Explorer myself.