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.
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.
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.
2. Use the search bar and find:
Analytics API Reporting
3. Select Google Analytics Reporting API.
4. 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.
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/
2. Select Admin.
3. Select View Settings. For example:
4. Locate the View ID field on the page.
5. 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.
4. Select Create Authentication.
5. Choose one of the following authentication methods:
6. Enter a name for your connection.
7. 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.
4. 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.
5. 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:
|
Metrics | Metrics measure the things contained in dimensions and provide the numeric scale and data series for the chart. For example:
|
Incremental | When run repeatedly, attempt to only import new data since the last import |
6. Select Next.
The Data Settings page can be modified for your needs or you can skip the page.
7. Optionally, edit the parameters on the Data Settings page.
8. Select Next.
Data Preview
You can see a preview of your data before running the import by selecting Generate Preview.
Data shown in the data preview is approximated from your source. It is not the actual data that is imported.
Click Next.
Data preview is optional and you can safely skip to the next page of the dialog if you want.To preview your data, select Generate Preview. Optionally, click Next.
Verify that the data looks approximately like you expect it to.
Select Next.
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.
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.
- Run once:
Select Off.
Select Scheduling Timezone.
Select Create & Run Now.
Repeat the query:
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.
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.