Search API Connector Documentation
Import Google Analytics (UA) Data to Google Sheets
In this guide, we’ll walk through how to pull Google Analytics data data directly into Google Sheets, using the API Connector add-on for Sheets.
Google Analytics is, of course, an extremely popular web analytics tool, so there are many other, specialized connection tools like Google’s official Google Analytics spreadsheet add-on. So definitely go give that one a try if you’d prefer not to work with the API directly.
Still here? Nice 🙂 This article will show how to access the following Google Analytics reporting APIs:
- Core Reporting API v3 (Universal Analytics)
- Reporting API v4 (Universal Analytics)
(The new GA4 Data API is discussed here: Import Google Analytics GA4 Data to Google Sheets)
Contents
- Before You Begin
- Part 1: Connect to Google Analytics
- Part 2: Fetch Data from Google Analytics
- Part 3: Create a Custom Request to the V4 Google Analytics API
- Part 4: Create a Custom Request to the V3 Core Reporting API
- Part 4: Handle Non-US Currency Formats
- Part 5: API Documentation
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Connect to Google Analytics
The easiest way to get started with the Google Analytics API is through API Connector’s built-in integration.
- Select Google Analytics (UA) from the drop-down list of applications
- Under Authorization, click Connect to Google Analytics (UA)
- You will be asked to allow API Connector to view your Google Analytics data. Click Allow.
- You’ll then be returned to your Google Sheet, and can verify that your Google Analytics connection is active.
Part 2: Fetch Data from Google Analytics
Now that we’re connected, let’s pull some data into Sheets.
- Under Endpoint, choose the data you’d like to retrieve. The
/data/ga
endpoint will return your GA data. - Set all required parameters, including your view ID, the fields in your report, date range, and so on. Get your view ID while logged into the admin section of GA, or by running a request to the other available endpoint (
/management/accountSummaries
). - Optionally set any optional parameters such as filters and sorting.
- Select a destination sheet, name your request, and click Run.
- To give your column headers more human-friendly names, click Edit Fields and name your fields in the field editor.
Part 3: Create a Custom Request to the V4 Google Analytics API
Alternatively, you can run a custom request instead of using API Connector’s built-in integration.
- In API Connector, click Create, choose POST from the dropdown menu, and paste
https://analyticsreporting.googleapis.com/v4/reports:batchGet
into the URL field. All V4 requests use the same URL. - Choose Google Analytics from the OAuth dropdown menu.
- Under headers enter Key = content-type, Value = application/json
- All details of the request, e.g. metrics, dimensions, and filters, are specified in the request body, like this:
{"reportRequests":[{"viewId":"XXXX","dateRanges":[{"startDate":"2021-09-01","endDate":"2021-09-30"}],"metrics":[{"expression":"ga:users"}]}]}
- Create a new tab and click Set current to use that tab as your data destination.
- Name your request and click Run. A moment later you’ll see user counts populate your sheet.
- That’s pretty cool.. but also quite messy looking. The GA v4 Reporting API returns data in a rather strange format, where metrics and dimension names are returned separately from the actual values. To simplify, let’s use the following JMESPath expression:
reports[].data.rows[]
. This will become even more useful as our queries become more complex, so we’ll keep a JMESPath filter in place for all our requests.
More Example V4 API Requests
- Multiple metrics
{
"reportRequests":
[
{
"viewId": "100425068",
"dateRanges": [{"startDate": "2021-09-01", "endDate": "2021-09-30"}],
"metrics": [
{"expression": "ga:users"},
{"expression": "ga:sessions"}
],
}
]
}
- Multiple metrics and dimensions (the “pageSize” parameter indicates how many records to retrieve)
{
"reportRequests":
[
{
"viewId": "100425068",
"dateRanges": [{"startDate": "2021-09-01", "endDate": "2021-09-30"}],
"metrics": [
{"expression": "ga:users"},
{"expression": "ga:sessions"}
],
"dimensions": [
{"name": "ga:browser"},
{"name": "ga:country"}
],
"pageSize":5000
}
]
}

To rename your columns, click Edit Fields.
- With filters
{
"reportRequests":
[
{
"viewId": "100425068",
"dateRanges": [{"startDate": "2021-09-01", "endDate": "2021-09-30"}],
"metrics": [
{"expression": "ga:users"},
{"expression": "ga:sessions"}
],
"dimensions": [{"name": "ga:browser"}, {"name": "ga:country"}],
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:browser",
"operator": "EXACT",
"expressions": ["Chrome"]
}
]
}
],
"pageSize":5000
}
]
}
Part 4: Create a Custom Request to the V3 Core Reporting API
As an alternative to connecting through the V4 API, you can get Universal Analytics data through Google Analytics’ older V3 Core Reporting API.
Reasons to use V3 instead of V4:
- Easier to construct queries. Fields are listed as URL parameters rather than in the request body.
- Access metadata like the view and property ID. The V4 API doesn’t return these fields.
- Migrate from or merge data with other systems pulling from GA. Google supports both V3 and V4, so some BI tools still provide data through the V3 API.
Instructions:
First, click connect on Google Analytics from the Connections menu, as shown above. Now, set up your request like this:
- Method: GET
- Request URL: https://www.googleapis.com/analytics/v3/data/ga?ids=ga:100425068&start-date=2021-09-01&end-date=2021-10-01&metrics=ga:users,ga:newusers,ga:sessions,ga:transactions,ga:transactionRevenue&dimensions=ga:isoYearIsoWeek,ga:channelGrouping
âžśsubstitute in your own property ID where it says 100425068, as well as your metrics and dimensions - OAuth: Google Analytics
- Headers: Key = Content-Type, Value = application/json
- JMESPath:
{id:id,profileInfo:profileInfo,rows:rows}

Part 5: Handle Non-US Currency Formats
The Google Analytics API returns revenue data using the standard American format , where periods .
represent the decimal place and commas ,
separate thousands. This is the case even if data in your view displays in the correct format for your locale.
To address this, you can either navigate to File > Settings > Locale and change your sheet to the United States locale, or add a formula to convert data back to your local format, e.g. =substitute(substitute(substitute(A1;",";"#");".";",");"#";".")
would replace commas with periods and periods with commas.

Add this formula to column A and set the data destination to column B to avoid overwriting your formula when you refresh the query.
Part 6: API Documentation
Official Universal Analytics API V4 documentation: https://developers.google.com/analytics/devguides/reporting/core/v4/basics
Official Core API Reporting V3 documentation:
https://developers.google.com/analytics/devguides/reporting/core/v3/reference
How do you extract data from your Google Ads campaign?
Hey Rami, you can use our Google Ads connection.
My Google analytics Oauth connection seems to be resetting very frequently making me unable to schedule my api to run, do you know why this may be happening?
Sorry, there was an issue – fixed now!
There no longer is a View or View ID for GA4. What GA4 field should be used to connect to the data?
Looks like the Google analytics Reporting API doesn’t support GA4 accounts. You will need to use the new analytics data api There is currently very little documentation for this api but im sure it will arrive in the coming months. ( https://developers.google.com/analytics/devguides/reporting/data/v1 )
Thanks, John! Yeah this article is for Universal Analytics, the Google Analytics Reporting API v4 doesn’t work for the new GA4, which is a bit confusing. GA4 uses the new Data API, which is still in Beta. I’ll investigate it and update this article.
Update: API Connector’s Google Analytics connection now supports GA4, I’ve created a new article with info on that.
You are amazing, this was the final piece to a huge Google Analytics puzzle, and yours was the easiest to follow and complete. You’re a genius! Thank you, thank you, thank you!
What a nice comment, thank you!