Skip to main content

Google Analytics

Prerequisites for Configuring Google Analytics Data Source

Account Requirements

  • A Google Analytics account with access to the GA Property(Property Ids) you want to sync

Create a Service Account

  1. Sign in to your Google Account as an admin
  2. Go to the Service Accounts page in Google Developers console
  3. Select/create project and click Continue
  4. Click + Create Service Account
  5. Enter name and description, click Create and Continue
  6. Choose role (recommended: Viewer role)
  7. In Keys tab, click Add Key > Create New Key
  8. Select JSON as Key type and download the file

Enable Required APIs

Enable the following APIs in your project:

  • Google Analytics Reporting API
  • Google Analytics API
  • Google Analytics Data API

Service Account JSON Key

  1. Go to API Console/Credentials
  2. Select the service account email
  3. Click Actions > Manage Keys
  4. Add Key > JSON
  5. Download the generated key

Client ID & Client Secret Setup

  1. Create OAuth Consent Screen:

    • Go to API Console/Credentials > OAUTH Consent Screen
    • Choose External/Internal
    • Fill required information
    • Add developer contact email
  2. Create OAuth 2.0 Credentials:

    • Go to Credentials > Create Credentials
    • Select OAuth 2.0 Client ID
    • Choose Web application
    • Fill required fields
    • Save Client ID and Secret

Generate Authorization Code

Use the following URL format:

https://accounts.google.com/o/oauth2/auth?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=code&scope=https://www.googleapis.com/auth/analytics.readonly&access_type=offline

Exchange Authorization Code for Refresh Token

Make a POST request:

curl --request POST \
--data "code=AUTHORIZATION_CODE&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&redirect_uri=YOUR_REDIRECT_URI&grant_type=authorization_code" \
https://oauth2.googleapis.com/token

Example response:

{
"access_token": "ACCESS_TOKEN",
"expires_in": 3600,
"refresh_token": "REFRESH_TOKEN",
"scope": "https://www.googleapis.com/auth/analytics.readonly",
"token_type": "Bearer"
}

Get Property ID

  1. Navigate to Google Analytics Console
  2. Select Account and Property
  3. Go to Admin > Property Settings > Property Details
  4. Copy the Property ID

Custom Report Specification

Example custom report:

[
{
"name": "User Engagement Report",
"dimensions": ["city"],
"metrics": ["sessions", "bounceRate"]
}
]

Configuring Google Analytics Data Source

  1. Select the Source Type as Google Analytics (Universal Analytics)

  2. Fill in the required details:

OAuth Authentication

Google Analytics OAuth Configuration
Google Analytics OAuth Configuration
  • Client ID
  • Client Secret
  • Refresh Token
  • Access Token
  • Property ID

Service Account Authentication

Google Analytics Service Account Configuration
Google Analytics Service Account Configuration
  • Service Account JSON Key

Additional Configuration

  • Replication Start Date - Format: YYYY-MM-DD

    • Example: 2021-01-01
  • View ID - The ID for the Google Analytics View

  • Custom Reports - JSON array describing custom reports

  • Data request time increment in days - Time increment for API requests (1-364 days)

    • Example values: 30, 60, 90, 120, 200, 364
    • Recommended: 1 for accuracy
  1. Click on Test Connection to verify if the connection is established successfully.