Summary - The Google Analytics Query Explorer is a way to retrieve raw web analytics data for your website. You can export data from the tool as a TSV or using an API query. Exporting data via the API is beneficial because you can rerun the query any time you want to refresh the data.
The Google Analytics Query Explorer is a fantastic way to retrieve raw web analytics data for your website. You can export data from the tool as a TSV (which you can format into a CSV) or using an API query. Exporting Google Analytics data via the API is beneficial because you can rerun the query any time you want to refresh the data. In this in-depth post, I am going to teach you how to use the Google Analytics Query Explorer to export data.
What is the Google Analytics Query Explorer?
The Google Analytics Query Explorer is an interface that lets you construct API queries which you can use to retrieve data from your Google Analytics account. You can build queries that collect data from a specific account, property, and view. The query tool lets you specify data based on pre-defined metrics and dimensions. More advanced users can even apply custom filters and segments to craft powerful queries.
Why use the Google Analytics Query Explorer?
The Query Explorer allows non-technical users to craft a URL endpoint that can be used to export data from Google Analytics. As you construct your query using the menus in the Explorer interface, it will automatically build your URL endpoint with the proper syntax, parameters, and URL encoding. You can even apply advanced operations (like Filters, see below) to export rich data sets from Google Analytics.
Why export Google Analytics data in the first place?
You might be wondering, why go through all the bother of exporting data from Google Analytics using the Query Explorer in the first place? The answer is that the Query Explorer provides unfettered access to the raw data in a way that isn’t available in the Google Analytics reporting interface. I personally like this method because I can export the data to create custom dashboards and reports.
Our customers use the Query Explorer to build rich web analytics dashboards for themselves and their clients. The benefit of this method is the ability to automate data refreshes. After configuring the dashboard, you can essentially set it and forget it.
You can also do some interesting things with the raw data that you can’t with the Google Analytics interface. For instance, we built the Google Analytics Daily Overview dashboard. What makes this dashboard unique is the expected values, which helps folks gauge whether their website is performing within norms. Here’s what it looks like:
The Google Analytics Daily Overview Dashboard is an example of using the API to build custom reports.
It’s useful to export Google Analytics data with the Query Explorer if you’re creating a custom report that requires additional data. Again, we see a lot of customers use this functionality to do things like analyze lead conversions by combining Google Analytics and Salesforce data, as just one example.
The Conversion Funnel visualization combines data from Salesforce and Google Analytics. Another interesting use-case.
Tutorial: How to use the Google Analytics Query Explorer
In this tutorial, I am going to walk you through the steps of crafting an API query that will retrieve data from your Google Analytics account. The best way to learn is to follow along in the Query Explorer. Here’s how to export data from Query Explorer:
- Select a view
- Select a date range
- Select metrics
- Select dimensions
- Run query and export data
Select a view
To start, you will need to select the View you’d like to use to export data from. For most users, a View is analogous to a website. If you’re the administrator for your Google Analytics account, you’re probably familiar with the terms Account, Property, and View.
It may be important to review how your organization has structured your Google Analytics account, since each of these can have unique properties which may impact what type of data you can retrieve.
- Click the Account menu to bring up a list of accounts.
- Select an Account
- Click the Property menu to bring up a list of properties associated with your account.
- Select a Property
- Click the View menu to bring up a list of views associated with the selected property
- Select a View
Select a date range
You will need to select a start date and end date for your query. You can select a static date range using the calendar option or you can use date values to customize your range. I recommend checking out the documentation for date values. You can basically use 3 types of date values:
- Calendar date such as 2017-01-01
- Relative date such as today or yesterday
- NdaysAgo value such as 30daysAgo or 7daysAgo
Playing around with start date and end date combinations can give some useful and common reporting ranges.
- In the start-date field, enter the value: 7daysAgo
- In the end-date field, enter the value: today
Every API query you craft with the Query Explorer needs to include at least one metric. This brings us to an important question:
What is a metric in Google Analytics?
Metrics are quantitative measurements that supply the statistics for user activity on your website, such as goals completed, number of users, or page sessions. When requested using an API query, metrics are presented as aggregate metrics. For example, if you made a request for users for the past 7 days, your result would look like this:
- In the Metrics field, select one or more metrics
- You will want to test your query to ensure the metrics you selected can be queried together
- Click the Run Query button
- If the query runs smoothly, move on to Step 4. If the query returns an error, swap out incompatible metrics
Dimensions are optional when crafting an API query, but I highly recommend including them in every request you make. If you’re data needs have matured enough to require you to go directly the core reporting API via the Query Explorer, you’re going to want to use dimensions.
What is a dimension in Google Analytics?
Dimensions are qualitative values that describe the data or metrics you’re retrieving for your website, such as date, source/medium, or user types. For example, if you made a request for users for the past 7 days and applied the date dimensions your results would look like this.
- In the Dimensions field, select one or more metrics
- You will want to test your query to ensure the dimensions you selected can be queried together
- Click the Run Query button
- If the query runs smoothly, move on to Step 5. If the query returns an error, swap out incompatible dimensions
Run query and export data
The Query Explorer is an interface used to craft an API call in the form of a URL endpoint. Technically, you could craft the URL endpoint by hand and successfully use that endpoint to retrieve data. What’s nice about the Query Explorer is that it reduces error by appending the correct parameters to your URL endpoint.
The last step in your process is to validate the query and export the data.
- Double-check all fields to make sure your request is complete
- Click the Run Query button
- Export the query using one of 3 options:
- Optional: Share a direct link to this Report so others can run it against their own data
- Optional: Export the API Query URL using a 3rd party tool such as Klipfolio by copying and pasting the URL to your clipboard.
- Optional: Download the Results as TSV, then export to Excel or Google Sheets
Tips and Tricks for the Google Analytics Query Explorer
The benefit of exporting data using the Query Explorer is the flexibility you get in crafting your API query. I’ve done some interesting things using the Query Explorer such as:
- Analyzing traffic from a single traffic source such as Twitter or Reddit
- Looking at hourly traffic patterns to determine best time to push website updates
- Analyze and bucket visitors based on average time on page and by number of visits
I use two features of the Query Explorer to export this type of data: Filters, and Segments. Let’s review some tips and tricks for each.
Using Filters in the Query Explorer
Applying a Filter to a query is useful for refining the data you get back in your call. You can apply Filters to Metrics or Dimensions. It’s important to note that there are 6 unique operators for Metrics and 6 unique operators for Dimensions. Check out the filter operators documentation for more information.
Here are some examples of how I use filters.
Analyze traffic from a specific Source/Medium
This is probably the most common way I use filters. What I do is create a query like this:
Then I run that query to make sure it works and to take a look at the Source/Medium pairs that show up in the results.
Next, I will have some fun by applying a filter to do things like only include Google / Organic results:
Just as easily, I could use that to query Facebook Advertising results by looking at Facebook / CPC.
Or even look at a specific social platform like Reddit.
Trim results for larger data sets
If I’m looking at a report like top landing pages, I rarely want to see pages that have less than 10 visits. I’ll append a filter that looks like this to thin out those results.
Analyze data based on defined user groupings
I like to a run report that only looks at the most qualified visitors to my site. I often use visits that last more than 10 seconds as a benchmark. This is a useful report because it segments out a lot bounces that come from unqualified traffic sources, such as display advertising.
Here’s an example of how I’d apply that filter:
Using Segments in the Query Explorer
You know all those segments you have in Google Analytics? Well, they are all accessible within the Query Explorer tool.
This includes custom segments, too.
I think the most powerful use-case for applying segments is when you’re combining a filter that qualifies visitors (eg: time on page > 10 seconds) with a traffic segment (eg: organic search visitors).
Of course, that’s only the beginning of what you can accomplish. I’m sure your head is swimming with new ideas that I couldn’t possibly cover in this post.
Getting familiar with the Query Explorer and marketing APIs
Digital marketers are becoming more technical by the day. The Google Analytics Query Explorer is a gentle introduction to using APIs for a practical purpose (eg: extracting data) but also to the value of APIs. Even if you don’t plan on becoming an API whiz, being familiar with the language of APIs is important as you tackle technical projects like app integrations, data exports, and website upgrades.
If you liked this post, you may also like this tutorial: Using Facebook's Graph API Explorer to retrieve Insights data
Originally published February 9, 2017, updated Jun, 08 2020