Google Analytics Connector CLI Setup Guide

Steps to add this connector to your installation

The steps to launch your connector are:

  1. Generate Google API keys
  2. Specify the connector config
  3. Add the Google Analytics connector

1. Generate Google API keys

Setup requirements

Before getting started please make sure to have the following information:

  • Access to an active Google account

Setup instructions

  1. Get Google Analytics OAuth credentials

    1. Log into Google Developer Console for your account and select (or create) project https://console.developers.google.com/apis/api/analyticsreporting.googleapis.com/overview

    2. Click on Credentials to create OAUTH2 Client Ids.

    3. Click on the created client id to store it in a json file.

    4. Use the client_id obtained in step 3 in the following url and go to this url in a browser(safari is better with error messages):

    https://accounts.google.com/o/oauth2/auth?client_id=<CLIENT_ID>&response_type=code&scope=https://www.googleapis.com/auth/analytics&redirect_uri=https://localhost/oauth
    1. You will be prompted to log in with your google credentials and also prompted to allow access to Google access the url with your credentials

      You will then be redirected to with a page like this:

    https://localhost/oauth?code=4/AACm8QL8-Vi7BoXwPPjb9Ey4MRB79fv-LiVmIhb1dkkPS70MoAIha8mcNDcJrppxCuN6SwmguYM9SR7sjxwzheA#

    Save the code parameter. The code can be redeemed only once. If it is already redeemed, it will throw an error and step 4 needs to be repeated to get a valid code.

    1. Now, run the following command using a terminal:
    curl -X POST https://accounts.google.com/o/oauth2/token \
    -d "grant_type=authorization_code&code=<AUTHORIZATION_CODE>&client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&redirect_uri=https://localhost/oauth"

    The response will be like:

    {
    "access_token" : "<ACCESS_TOKEN>",
    "expires_in" : 3600,
    "refresh_token" : "<REFRESH_TOKEN>",
    "token_type" : "Bearer"
    }

    You will need to use client id, client secret, access token and refresh token.

  2. Provide View Id of the project

    In Google Analytics web console

    Click Admin > View > View Settings > Id

    This Id needs to be saved in the runtimeConfig file as view_id.

2. Specify the connector config

To get a template for the Google Analytics connector configuration save the output of the describe --input-parameters command as follows:

datacoral collect describe --slice-type googleanalytics \
--input-parameters > googleanalytics_parameters_file.json

Necessary input parameters:

  • view_id - The Consumer Key from the connected app definition.
  • client_id - OAuth client id
  • client_secret - OAuth client secret
  • access_token - OAuth access token
  • refresh_token - OAuth refresh token
  • loadunits - for each load unit you can specify the following parameters: ( Please refer to https://developers.google.com/analytics/devguides/reporting/core/dimsmets to get the list of load units and the supported metrics and dimensions for each load unit )
  • metrics - The list of metrics to be fetched for the load unit.
  • dimensions - The list of dimensions to be fetched for the load unit.

Optional input parameters:

for datasource:

for loadunit:

  • schedule - cron format. You can define a different schedule for the table from the global schedule set above.

  • filters: dimensions filters

    Example templates:

{
"view_id": "2134343545",
"schedule": "0 0 * * *",
"loadunits": {
"sessions": {
"metrics": "ga:sessions, ga:bounces, ga:bounceRate, ga:sessionDuration, ga:avgSessionDuration, ga:hits",
"dimensions": "ga:browser, ga:browserVersion, ga:operatingSystem, ga:operatingSystemVersion"
},
"users": {
"metrics": "ga:users, ga:newUsers, ga:percentNewSessions, ga:sessionsPerUser"
}
},
"client_id": "test",
"client_secret": "test",
"access_token": "test",
"refresh_token": "test"
}

3. Add the connector

datacoral collect add --slice-type googleanalytics --slice-name <connector-name> --parameters-file <params-file>
  • connector-name Name of your connector. A schema with your connector-name is automatically created in your warehouse
  • params-file File path to your input parameters file. Ex. googleanalytics_parameters_file.json

Got questions? Interested?

Please contact Datacoral's Support Team, we'd be more than happy to answer any of your questions.