# Google Analytics Import Integration 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](https://github.com/treasure-data/treasure-boxes). This feature only uses Universal Analytics(UA) which was deprecated on July 1, 2023. For more information visit [this page](https://support.google.com/analytics/answer/11583528). To continue your service without disruption, consider using Google Analytics 4 (GA4) with the [Google Analytics Data API Import Integration](https://docs.treasuredata.com/display/public/INT/Google+Analytics+Data+API+Import+Integration). ## Prerequisites - Basic knowledge of Treasure Data - Basic knowledge of Google Analysis - A Google Analytics account with dimensions and metrics specified ## Requirements To fetch report data on Google Analytics, your service account requires "Read & Analyze" or a higher level of permission. ## About Partition Key Seed 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. ## Google API Set-Up Options 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. | ## Set the Google API for JSON Authentication The Google Analytics data connector uses an API connector to access Google Analytics data. Click here to expand 1. Open the Google API Console: [https://console.developers.google.com/](https://console.developers.google.com/) 2. 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. 1. Navigate to the Library. ![](/assets/image2021-5-25_16-6-44.668f6414bd74b6bd24c0276c5e0a5bb23409909087303ccb3c65b809bec65c47.5a48ad91.png) 1. Select **Create project.** ![](/assets/image2021-5-25_16-8-21.74338e99bcc8367db2630085fe46cc25af9bafb3442ee69843e1e066a00e2729.5a48ad91.png) 1. Select the organization. ![](/assets/image2021-5-25_16-9-52.fe4e64a5029fa3216d53871203505da5c457f61c4b079a391a8e54f8a03b8e2d.5a48ad91.png) 1. Select **New Project.** ![](/assets/image2021-5-25_16-10-24.f5ee7508b3d52954cc872ddb605716585aaa44d0f941fbdb5478e5875d25c03f.5a48ad91.png) **Name your project.** ![](/assets/image2021-5-25_16-14-48.b277cc70b88e6cca1cf43c8b6277e2ad38c87f7861b31ff3f50724e5474a74a7.5a48ad91.png) 1. Select **Create.** Create a New Service Account 1. 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. 2. Select APIs & Services. ![](/assets/image2021-5-25_16-41-27.a559b5a2a6871572d74c6ed73bc6f6a456abb1f50b2e5330a9f43204d29db329.5a48ad91.png) 1. Select **Service Accounts.** 2. Select **Create Service Account.** ![](/assets/image2021-5-25_16-42-58.24dff8ed9eb0a54b30cf23b9424c02cc876695cba2e78d68a2a64c9286d5461a.5a48ad91.png) ![](/assets/image2021-5-25_16-43-50.574957bca95fecfe7ef96ab009ca69316fe0535704e91959a9210d256efd8c34.5a48ad91.png) 1. Complete the fields to create a service account named "treasure-data". ![](/assets/image2021-5-25_16-48-2.adc86d9b60d5f2641860256b8d704ad5138ed21ee1a80a78f541beaa22498b25.5a48ad91.png) 1. Skip the optional parameters. 2. Select **Done**. 3. Select the Actions menu. ![](/assets/image2021-5-25_16-51-41.4b8f0dc8cd93d274f022a59ed545e18352a68f9941d97ceaea954252837e48b7.5a48ad91.png) 1. Select **Manage keys**. ![](/assets/image2021-5-25_16-52-18.2b10ae21626168ccdc1c23da9c0396c3bb4946b8063e24e410a3a180b6f50534.5a48ad91.png) 1. Select **Add key**. ![](/assets/image2021-5-25_16-53-15.52025b8089dcd1c2c9134556c42fd3223bcc22df770a3fc678f0a48f57c01fb7.5a48ad91.png) 1. Select **Create new key**. ![](/assets/image2021-5-25_16-53-0.3f20e0e81ec0d84fd9780fd45a93c2155b2e55bada3a3c66778b6017b0413d38.5a48ad91.png) 1. Select **Create**. The JSON file downloads to the machine you are on. ![](/assets/image2021-5-25_16-55-24.36e587cb336613c205f95729aae7fa9c86927e847a118a8f28a09631885b87c9.5a48ad91.png) 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: ```json { "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" } ``` 1. Navigate back to Service accounts and locate your key ID. ![](/assets/image2021-5-25_17-23-43.fa72064a4351bbd3af78c578642033810d7dfd472810095a29b4106115f2a5c5.5a48ad91.png) 1. Select your service account. ![](/assets/image2021-6-2_16-15-41.44fd1d22c9a14c7e1993e0b93ad4d754f344178924725d3c53f40035a3d0a1d1.5a48ad91.png) 1. Expand Show Domain Wide Delegation. 2. Select Enable Google Workspace Domain-wide Delegation. 3. Type Treasure Data as the product name. ![](/assets/image2021-6-2_16-18-35.29171077d1a7f536edd7d32a30376afd3d59d6fb87c00e3f4d0ec6401e1e839e.5a48ad91.png) 1. Select Save. The service account that you created also creates a service account ID. The service account ID is given API access authentication. ## Set the Analytics API for JSON 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. ### Locate and Enable the Analytics APIs 1. In Google Cloud Platform, navigate to APIs & Services > Library. ![](/assets/image2021-6-2_16-27-4.a85148ba72ecd1882b2e4b23250b1b3fae235bae6146df650964c90befef763e.5a48ad91.png) 1. Use the search bar and find: Analytics API Reporting ![](/assets/image2021-6-2_16-30-2.43acc8f2e0eedfc36c49922b1d685ab90dafcbbacb9dadfd3d6d41c159f10642.5a48ad91.png) 1. Select Google Analytics Reporting API. 2. Select **Enable.** ![](/assets/image2021-6-2_16-31-45.04492d87c2cf4f23fb9ce53fae88a80388c34bd256791cd4619d897f3777a547.5a48ad91.png) 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. ![](/assets/image2021-6-2_16-40-49.a7cd868901f2f937287122d6be5c3c9e4b6fe38d6374521ec49c3b7b895ee204.5a48ad91.png)Two APIs in your project in Google API are enabled to send data. The service account ID is allowed access to Google Analytics data. ## Associate the Google API and Service Account with Google Analytics for JSON ### Add Permission for Service Account ID to Access Google APIs for JSON 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. 1. Verify that you are still logged into Google Analytics with your Google account. At:      https://analytics.google.com/ 2. Select  Admin. 3. Select **Account** **User Management**. 4. 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. ## Obtain the View ID from Google Analytics 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. 1. Navigate to the Home page of Google Analytics. For example: analytics.google.com/ ![](/assets/image2021-6-3_13-13-40.4e6cb13c0ddc85695cba1df1ea5295423cd9260ea1ccc4604828d54f936a68b3.5a48ad91.png) 1. Select Admin. 2. Select View Settings. For example: ![](/assets/image-20191015-193003.2e78337fd91e767a5f6b2632780f997668a8df030b8bb7cce246dece45ee0852.5a48ad91.png) 1. Locate the View ID field on the page. ![](/assets/image-20191015-193026.bcf3e36358d4fd72967031a243583756a24fb7938074c44759c7ce3d9153f948.5a48ad91.png) 1. Capture or copy the View ID, it is necessary for the creation of the Treasure Data authentication. ## Creating the Data Connector from the TD Console ### Create a New Connection 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. 1. Open **TD Console**. 2. Navigate to **Integrations Hub** >  **Catalog**. 3. Search for and select Google Analytics. ![](/assets/image2021-6-3_9-34-31.aecad98abe16bd81abc6adf96d90493c95cdcb34c7864036830971c3e5d31bf4.5a48ad91.png) 1. Select **Create Authentication**. ![](/assets/image2021-6-3_9-40-8.88aa7ff86852dc436deeaa582842fdf89d400b2afcd14949ebb78e6462339b66.5a48ad91.png) 1. Choose one of the following authentication methods: JSON Key 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 {…}. 1. Locate and open the JSON file that you downloaded from the Google Cloud Platform in your favorite text editor.  For example: ![](/assets/image2021-6-3_9-45-59.7ade25ea5d865bb97e721985bd653ee35d1628a5632c2a834438e3cdd3b55642.5a48ad91.png) 2. Type your **View ID**. For example: 179999562 3. Select **Continue**. 4. Enter a name for your connection. 5. Select **Done.** OAuth ![](/assets/image2021-6-4_11-11-8.27122d7fffdf497d6583f13ad1978d0bcc597b97f460b14c266a20505b289e2a.5a48ad91.png) 1. Select **OAuth**. 2. If you know the OAuth connection type it, otherwise you can make the selection to connect a new account. 3. If you chose to connect a new account, you are taken through a series of screens where you select the account to link and specify that you are OK granting access to that account by Treasure Data.  You are then returned to  Authentications in TD Console. 4. Search for and select **Google Analytics**. ![](/assets/image2021-6-3_9-34-31.aecad98abe16bd81abc6adf96d90493c95cdcb34c7864036830971c3e5d31bf4.5a48ad91.png) 5. Select OAuth.  Your account should show in the Authentication connection field. For example: ![](/assets/image2022-6-28_14-11-16.29f0e754731eea6590d8c43d83451dd7844a975a5ce01fe7d6d9ee09da84bb0c.5a48ad91.png) 6. Type your **View ID**. For example: 179999562 7. Select **Continue**. 8. Enter a name for your connection. 9. Select **Done.** ### Transfer Your Data to Treasure Data After creating the authenticated connection, you are automatically taken to Authentications. You must enter Dimension and Metric information from Google Analytics. 1. Search for the connection you created. 2. Select **New Source**. 3. 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. ![](/assets/image2021-6-3_13-47-28.402443af93d83839910770caefd0dae1ba7f9bbedff26a3fb903f608c3aa7890.5a48ad91.png) 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 | 1. Select **Next**. The Data Settings page can be modified for your needs or you can skip the page. ![](/assets/image2021-6-10_9-24-12.213554458bafff100344979ba180f585c8e5fbd300c1dbc54a25bda2176b7737.5a48ad91.png) Optionally, edit the parameters on the Data Settings page. 1. Select **Next**. ### Data Preview You can see a [preview](/products/customer-data-platform/integration-hub/batch/import/previewing-your-source-data) 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. 1. Select **Next**. The Data Preview page opens. 2. If you want to preview your data, select **Generate Preview**. 3. Verify the data. ### Data Placement For data placement, select the target database and table where you want your data placed and indicate how often the import should run. 1. 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. 2. Select a **Database** > **Select an existing** or **Create New Database**. 3. Optionally, type a database name. 4. Select a **Table**> **Select an existing** or **Create New Table**. 5. Optionally, type a table name. 6. 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. 7. 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. 8. Select the **Timezone** for your data storage. 9. Under **Schedule**, you can choose when and how often you want to run this query. #### Run once 1. Select **Off**. 2. Select **Scheduling Timezone**. 3. Select **Create & Run Now**. #### Repeat Regularly 1. Select **On**. 2. Select the **Schedule**. The UI provides these four options: *@hourly*, *@daily* and *@monthly* or custom *cron*. 3. You can also select **Delay Transfer** and add a delay of execution time. 4. Select **Scheduling Timezone**. 5. Select **Create & Run Now**. After your transfer has run, you can see the results of your transfer in **Data Workbench** > **Databases.** # Optionally Configure Workflow 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](https://api-docs.treasuredata.com/en/tools/cli/api/#workflow-commands).