Google Analytics is a web analytics service offered by Google that tracks and reports website traffic, as a platform inside Google Marketing. The Google Analytics import integration enables the import of your Google Analytics reports.
Sample workflows are available for many integrations through Treasure Boxes on Github.
This feature only uses Universal Analytics(UA) which was deprecated on July 1, 2023. For more information visit this page. To continue your service without disruption, consider using Google Analytics 4 (GA4) with the Google Analytics Data API Import Integration.
- Basic knowledge of Treasure Data
- Basic knowledge of Google Analysis
- A Google Analytics account with dimensions and metrics specified
To fetch report data on Google Analytics, your service account requires "Read & Analyze" or a higher level of permission.
Typically, TD partitions data by time. Choose the long or timestamp column as the partitioning time. By default, the Partition key seed uses the time column, specifically the upload_time column through the add_time filter. In Google Analytics, the partition key seed becomes "ga: date" or "date_hour" specified in the time_series section.
As part of creating your data connector, you register Treasure Data using the Google API Console.
The method you use to authenticate Treasure Data with Google Analytics affects the steps you take to enable the data connector to import from Google Analytics.
| Authentication Method | |
|---|---|
| Google User Account: OAuth | Using OAuth is the most common method. This method requires fewer setup steps. You can skip the rest of this section and go directly to TD Console. |
| Google Service Account—JSON | Using JSON might be required for your implementation. This method requires the setup steps using the Google API. |
The Google Analytics data connector uses an API connector to access Google Analytics data.
Click here to expand
Open the Google API Console: https://console.developers.google.com/
Log in to the Google Analytics account that you want to access through the API.
You log into the Google Analytics account so that you have permission to access API services.
- Navigate to the Library.

- Select Create project.

- Select the organization.

- Select New Project.

Name your project.

- Select Create.
Create a New Service Account
Access Service Account to create a new account. The service account permits access by the API to the Google Analytics account. The service account is created within a project and is from the Google account that you logged into to access Google API services.
Select APIs & Services.

Select Service Accounts.
Select Create Service Account.


- Complete the fields to create a service account named "treasure-data".

Skip the optional parameters.
Select Done.
Select the Actions menu.

- Select Manage keys.

- Select Add key.

- Select Create new key.

- Select Create.
The JSON file downloads to the machine you are on.

Keep the file containing authentication in a safe place. You use the private key information of the JSON file in the data connector configuration file.
For example, the generated file might look similar to:
{
"type": "service_account",
"project_id": "central-stream-314923",
"private_key_id": "94d03bf7dd9c05bc122c695d1aa13f2a8a28f88e",
"private_key": "-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w**********************AoIBAQCNhAICLr/dozCQ
TW9ZNMNJ6RF+fVqhd0FUbw0VBIwy6BWu/LuaocJrzl2DHChAl0PNvGCDUAObBTRz
bUT/HOu47q**********7ENGK
Oir9VChG+Qubq25bAtOq/yTVEPJgnj*******AGVjojVnK4f
2YtW6ti7xBPwFBF1RPY56yTDeVQVko+KK3x+LFS+lTj1+jBBjvedWHrpQQfRHqV/
VtXyKyDybQlnfAOucMHzMxjQVLN4f9D7JVxCe52Wp7RaALCIdkKDqN/ffkNMF9QT
CjffudeTAgMBAAECggEAFMQnS0yy6QI2cSZ7zXpZofHqmEYq04DdfFdjcw8cx6eY
7vm1Seas0gcRX9j06y2HTJx1CS/np4rm/H0vX8RNrvCPYXrOJzUG2DOnW9pwi9Hl
Kb1Z0VErenzy/em78BI958fXIJ4vv5pjNUZ94njEBE4tbuWEJyTODMyuCfoXpye4
kCDY6DJFxDKUA7tZOTcK3t0YiVV0O2MwcUhJdr107kw4F1HXY/mlh87ki5z3tMy0
ISBKjvau2aWf0SVLZHtlo88JZGUak7tkuxnWaXQN+dUo1rZWKj867pBT4KWXzAbJ
UVQ7pBrDFri90fNQ5XFsQdS//dO2pFEn+1Aum86Q0QKBgQDB4RHjBWdJ3eMyvWWi
ipdCx4gC6G5Hqjt+icKv9yddyV/WvuMH82xDAHUJJBzaj9I45O5D+07O6TZO8CkZ
6Tqq92N3HEkHZWiUTo91C4qbO4ai5SXxpnWn5gsYc+JYPqNp1b+T1gZjA4Pj8l+t
eJ7VDGxu0tjK17Vj13turImXCQKBgQC629KRpvq9FAIWuA8NAXBSeqNyzktPVdOZ
5GJvwCevVzIapvwZPoZTaJ6xehta1hrR859ZReZx/j7ntoOjAjGw1rS//T5N98Hf
t+JpCemAa5ApcoUBAXmlb80jIHysRBgMUTLcTKnZuFT3RwsD1xtXjRct0doIF8EC
d8RLE7FkuwKBgQCJSuGIuwXWqBtAjiBPxwawUm29aWzWsPTqeZF1XHbzEiwc/RX2
Rmmu1L8MFxebqmb6xRr45xh6q2k64xSn9aIG+aLk8RHB/AzfoPYzs1WW8cM4zT5e
bjs5B01qJn3tcYX051l/zfq92Ppny/X2+Mi5I9ARdpvwoGoh5rDQwbu5SQKBgHx8
aGtKsC75Pm7+TmCevcLlGzEoCHohNqiGw6GphYbF84ZYCwmSYxD8WQTp0YGRtCp9
QILME7uL40KhkE8v7gTe9WoWf8SXs5ykt/y8cshwYImMVtmVrwItWp/1S7nEX7UM
/3JOzLVUnZ5jwQ3c58VLJM8MyFGt6ZMIUUinJP5zAoGAICmOlDqPWR2RXPo+9SkN
ok82AjvsjeUMDsiCkEVsAQMBZkYbND0047BAg7STqVjIaJg0zYFvQ5oow5zgu1lk
46nxtfQm3U58lILErGsmClxcOZR2nO7kvm0PJMUgENADGhP5pqE+8w+e4JC45Ojw
X7X+hhL/a7pu2Un9O/rXZVM=
-----END PRIVATE KEY-----
",
"client_email": "meg-td-service-account@central-stream-314923.iam.gserviceaccount.com",
"client_id": "117460147437348814027",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/meg-td-service-account%40central-stream-314923.iam.gserviceaccount.com"
}- Navigate back to Service accounts and locate your key ID.

- Select your service account.

Expand Show Domain Wide Delegation.
Select Enable Google Workspace Domain-wide Delegation.
Type Treasure Data as the product name.

- Select Save.
The service account that you created also creates a service account ID. The service account ID is given API access authentication.
You now have a project and account ID in Google API. Next, you enable specific APIs to be used in this project. In this step, you register the two APIs related to Google Analytics.
- In Google Cloud Platform, navigate to APIs & Services > Library.

- Use the search bar and find:
Analytics API Reporting

Select Google Analytics Reporting API.
Select Enable.

When you enable the API, from the Dashboard menu, you can see a list of all APIs that have been registered, and the monitoring of the API starts.
Two APIs in your project in Google API are enabled to send data. The service account ID is allowed access to Google Analytics data.
Add permissions for your service account that you created in Google API.
To fetch report data on Google Analytics, your service account requires "Read & Analyze" or a higher level of permission.
Verify that you are still logged into Google Analytics with your Google account. At: https://analytics.google.com/
Select Admin.
Select Account User Management.
Define "Read & Analyze" or a higher level of permission on your service account.
Your service account now has adequate access to use Google Analytics through the Google Analytics APIs.
You must have the view ID to create the authentication to Treasure Data.
Each unique view of data has an associated View ID. You must know the View ID of the data that you want to access.
- Navigate to the Home page of Google Analytics. For example:
analytics.google.com/

Select Admin.
Select View Settings. For example:

- Locate the View ID field on the page.

- Capture or copy the View ID, it is necessary for the creation of the Treasure Data authentication.
In Treasure Data, you must create and configure the data connection prior to running your query. As part of the data connection, you provide authentication to access the integration.
Open TD Console.
Navigate to Integrations Hub > Catalog.
Search for and select Google Analytics.

- Select Create Authentication.

- Choose one of the following authentication methods:
Enter the View ID and JSON key information.
Make sure that you include the private key of the service account. Make sure that the entire JSON key information is in brackets {…}.
- Locate and open the JSON file that you downloaded from the Google Cloud Platform in your favorite text editor. For example:

- Type your View ID. For example: 179999562
- Select Continue.
- Enter a name for your connection.
- Select Done.
After creating the authenticated connection, you are automatically taken to Authentications.
You must enter Dimension and Metric information from Google Analytics.
Search for the connection you created.
Select New Source.
Type a name for your Source in the Data Transfer field**.**
Select Next.
The Source Table dialog opens. You must enter Dimension and Metric information. You go to Google Analytics to obtain the information and enter the information in the Treasure Data Transfer data from Google Analytics dialog.

Edit the following parameters:
| Parameters | Description |
|---|---|
| Time Series | For the Time Series field indicate whether you want to track the hour with the date or track just the date. |
| Dimensions | Dimensions are data categories. Dimension values (the data contained by the dimension) are names, descriptions, or other characteristics of a category. For example: - ga:pagePath - ga:referralPath |
| Metrics | Metrics measure the things contained in dimensions and provide the numeric scale and data series for the chart. For example: - ga:pageviews - ga:sessions - ga:users |
| Incremental | When run repeatedly, attempt to only import new data since the last import |
- Select Next.
The Data Settings page can be modified for your needs or you can skip the page. 
Optionally, edit the parameters on the Data Settings page.
- Select Next.
You can see a preview of your data before running the import by selecting Generate Preview. Data preview is optional and you can safely skip to the next page of the dialog if you choose to.
- Select Next. The Data Preview page opens.
- If you want to preview your data, select Generate Preview.
- Verify the data.
For data placement, select the target database and table where you want your data placed and indicate how often the import should run.
Select Next. Under Storage, you will create a new or select an existing database and create a new or select an existing table for where you want to place the imported data.
Select a Database > Select an existing or Create New Database.
Optionally, type a database name.
Select a Table> Select an existing or Create New Table.
Optionally, type a table name.
Choose the method for importing the data.
- Append (default)-Data import results are appended to the table. If the table does not exist, it will be created.
- Always Replace-Replaces the entire content of an existing table with the result output of the query. If the table does not exist, a new table is created.
- Replace on New Data-Only replace the entire content of an existing table with the result output when there is new data.
Select the Timestamp-based Partition Key column. If you want to set a different partition key seed than the default key, you can specify the long or timestamp column as the partitioning time. As a default time column, it uses upload_time with the add_time filter.
Select the Timezone for your data storage.
Under Schedule, you can choose when and how often you want to run this query.
- Select Off.
- Select Scheduling Timezone.
- Select Create & Run Now.
- Select On.
- Select the Schedule. The UI provides these four options: @hourly, @daily and @monthly or custom cron.
- You can also select Delay Transfer and add a delay of execution time.
- Select Scheduling Timezone.
- Select Create & Run Now.
After your transfer has run, you can see the results of your transfer in Data Workbench > Databases.
Within Treasure Workflow, you can specify the use of this data connector as part of a workflow.
Learn more at Using Workflows to Export Data with the TD Toolbelt.