Sub topic 15
Going further with Explorations and the Data API
This chapter assumes you can read the User acquisition and Traffic acquisition reports. It also assumes you know the difference between user-scoped and session-scoped dimensions, and you know what source, medium, campaign, and default channel group mean. If any of these is unclear, review the earlier chapters first.
The standard acquisition reports are fixed tables with a few customization options. Two tools remove those limits. Explorations is a free-form analysis workspace inside GA4. The Data API lets you request the same data from your own scripts or spreadsheets. Both use the same dimensions and metrics as the standard reports, so the scope rules you already learned apply to them in full.
When the standard reports are not enough
Use a standard report when the question is simple and the table already shows it. Move to Explorations or the Data API when you need one of these:
- More than two dimensions in one table, or several metrics side by side that the report does not offer.
- Segments you define yourself, such as "users who arrived from email and viewed pricing".
- A funnel or path that starts from a traffic source.
- The same query on a schedule, or data pulled into a dashboard, spreadsheet, or script.
- More rows than the report shows on screen.
Explorations
Explorations is under Explore in the left navigation. Each exploration has two panels. The Variables panel on the left holds the building blocks: date range, segments, dimensions, and metrics. The Tab Settings panel next to it controls how the selected technique displays them.
You import a dimension or metric into Variables first. Only imported items can be dragged into Tab Settings. This is the most common reason a field seems to be missing.
Techniques useful for acquisition
| Technique | Use it to answer |
|---|---|
| Free form | Which source/medium combinations bring the most engaged sessions, split by device or country? |
| Funnel exploration | Where do visitors from each channel drop out of a sequence of steps? |
| Segment overlap | Do users from paid search and from email overlap? |
| User lifetime | How do users first acquired by one channel behave over their whole history? |
| Cohort exploration | Do users acquired in one week return more than users acquired in another? |
Building a free-form acquisition table
- Create a Blank exploration and name it, for example "Channel and source by device".
- In Variables, next to Dimensions, select + and import
Session default channel group,Session source / medium, andDevice category. - Next to Metrics, import
Sessions,Engaged sessions,Engagement rate, andKey events. - Drag
Session default channel groupinto Rows. DragSessionsandKey eventsinto Values. - Drag
Device categoryinto Columns to split the table by device. - Add a Filter such as
Session default channel groupexactly matchesOrganic Searchto focus on one channel.
Pick the scope deliberately
Explorations lists user-scoped and session-scoped dimensions side by side, with similar names. First user default channel group and Session default channel group sit next to each other in the picker. Using the wrong one is the main source of numbers that do not match the standard reports.
- Choose
First user ...dimensions to ask where users came from the first time. - Choose
Session ...dimensions to ask what brought each visit. - Choose
Manual ...or similar names only when you need the value from a campaign tag, not the value GA4 resolved.
A table that mixes a user-scoped dimension with a session-scoped one is legal, but it answers a different question. Each row then describes sessions grouped by how the user first arrived.
Segments in Explorations
Segments can be built from user, session, or event conditions. A session segment is the most direct way to isolate traffic. For example, a session segment where Session medium exactly matches email limits every metric to sessions from email. A user segment with the same condition would instead include all sessions of any user who had at least one email session, which counts more traffic.
Limits to know
- Exploration data is subject to sampling or "quota" limits on large properties. A shield icon at the top of the exploration indicates the data is sampled or that thresholds are applied.
- Explorations that use fields with Google signals can apply data thresholds, which hide small counts to protect privacy.
- Cardinality limits can move rare values into an "(other)" row when a report has too many unique values.
- Explorations are private to you until you share them. Sharing makes a read-only copy visible to others on the property.
The Data API
The Google Analytics Data API v1 returns the same data as reports, through requests you write yourself. The method used for most acquisition work is runReport. It takes a property ID, a date range, a list of dimensions, a list of metrics, and optional filters and ordering.
The request body below reproduces a Traffic acquisition style table. It uses session-scoped dimensions, so its totals should be close to the Traffic acquisition report for the same dates.
{
"dateRanges": [{ "startDate": "28daysAgo", "endDate": "yesterday" }],
"dimensions": [
{ "name": "sessionDefaultChannelGroup" },
{ "name": "sessionSourceMedium" }
],
"metrics": [
{ "name": "sessions" },
{ "name": "engagedSessions" },
{ "name": "keyEvents" }
],
"orderBys": [{ "metric": { "metricName": "sessions" }, "desc": true }],
"limit": 20
}The API uses camelCase names, which differ from the labels in the interface. The common acquisition names are listed here.
| Interface label | API name | Scope |
|---|---|---|
| First user default channel group | `firstUserDefaultChannelGroup` | User |
| First user source / medium | `firstUserSourceMedium` | User |
| Session default channel group | `sessionDefaultChannelGroup` | Session |
| Session source / medium | `sessionSourceMedium` | Session |
| Session campaign | `sessionCampaignName` | Session |
| Engagement rate | `engagementRate` | Session |
| Key events | `keyEvents` | Event |
Sending the request
The simplest way to try a request is the Query Explorer-style tools Google provides in the API documentation, where you enter a property and paste the body. In your own code, use an official client library or the REST endpoint:
POST https://analyticsdata.googleapis.com/v1beta/properties/PROPERTY_ID:runReportReplace PROPERTY_ID with the numeric property ID found under Admin > Property details. The request needs an OAuth token or a service account that has been added to the property with at least the Viewer role. A service account has an email address, and you add that address under Admin > Property access management the same way you would add a person.
Filtering in the API
Filters go in dimensionFilter. This one keeps only rows where the session medium is email:
{
"dateRanges": [{ "startDate": "28daysAgo", "endDate": "yesterday" }],
"dimensions": [{ "name": "sessionCampaignName" }],
"metrics": [{ "name": "sessions" }, { "name": "keyEvents" }],
"dimensionFilter": {
"filter": {
"fieldName": "sessionMedium",
"stringFilter": { "matchType": "EXACT", "value": "email" }
}
}
}Compatibility and quotas
The API rejects some combinations. Not every dimension can be requested with every metric, because they have different scopes. If a request fails with an incompatibility error, the API's getMetadata method and its checkCompatibility method report which fields can be combined.
Each property has a token quota that limits how many requests and how much data you can pull per hour and per day. Request only the dimensions and metrics you need and use limit and offset to page through large results. Treat a quota error as a signal to reduce the query, not to retry in a tight loop.
The API also applies the same thresholds and cardinality rules as the interface. Data from the last day or so can still change as events are processed, so a query that includes today can differ from the same query run later.
Choosing between the tools
Explorations suits a person looking at the data. The Data API suits a program that needs the same aggregate numbers every day. BigQuery, covered in the next chapter, suits questions that need individual events.
Common errors
- Numbers do not match the standard report. Check the scope of each dimension, the date range, and the filters. Then check for data thresholds or sampling indicators.
- A dimension is missing in Explorations. Import it in the Variables panel first.
- The API returns an incompatibility error. Remove fields until the request works, then add them back one at a time, or call
checkCompatibility. - The API returns a permissions error. Confirm the account or service account has access to that property, not only to the account.
(not set)appears in results. It has the same causes as in the interface: missing campaign tags, or a field that has no value for that scope. See the chapter on Direct and Unassigned traffic.
Exercise
A colleague builds a free-form exploration with First user default channel group in rows and Sessions in values, then says it is wrong because Organic Search sessions are higher than in the Traffic acquisition report. What explains the difference, and how do you fix the exploration?
Show answer
The exploration groups sessions by how each user first arrived, not by how each session arrived. A returning user who first came from Organic Search and later returned through email has all of those sessions counted under Organic Search. The Traffic acquisition report uses the session-scoped channel group. To match it, replace the row dimension with Session default channel group.
Exercise
Write the Data API dimension and metric names you would request to list, for the last 28 days, the number of users and key events by first-user source and medium. Which standard report does this resemble?
Show answer
Use the dimension firstUserSourceMedium and the metrics totalUsers and keyEvents. The result resembles the User acquisition report, because the dimension is user-scoped.
Exercise
A scheduled script that calls runReport starts failing with a quota error after you add 12 dimensions and an hourly date breakdown. What should you change?
Show answer
Reduce the request. Remove dimensions you do not use, avoid the hourly breakdown unless you need it, narrow the date range, and page results with limit and offset. Do not retry in a loop, because retries consume more quota.