Transfer · From Tasks · from_google_analytics

Purpose

Imports data from Google Analytics.

Method of use

Before you can download data from Google Analytics you have to give access to a Onesecondbefore account.
Then you need to give your Google Account access. There are two ways to do this:

Acces with Service Account

Take the steps below to download Google Analytics data with a service account.

  1. Create a service account or re-use a service account of a Google Cloud environment.
  2. Have the service account added to the Transfer connections by a Onesecondbefore staff member
  3. If you use Google Cloud, you're done. If you use another cloud, add the connection string to conn_id
  4. Give the client_email from the Service Account `Read` access to the Google Analytics view you want to import data from.
  5. You should now be able to download google analytics data.

Access with Delegated Account

Take the steps below to download Google Analytics data with a delegated account. Please take note of the security precautions needed to secure this connection method.

  1. Take the steps 1 till 3 in the Service Account flow.
  2. Enable domain-wide delegation for the service account.
  3. Give the delegated account `Read` access to the Google Analytics view you want to import data from
  4. You should now be able to download data

Configuration

Example usage

extract:
    view_id: ga:111925
    dimensions:
        - ga:date
    measures:
        - ga:sessions
        - ga:users
        - ga:pageviews
    filters_expression:
        - ga:medium==referral
    segments:
        - gaid::-3
        - sessions::condition::ga:eventLabel=@some_label
    order_bys:
        - field_name: ga:pagePath
          sort_order: ascending

Properties

propertytyperequireddescription
conn_idstringnoDefault is google_cloud_default. Connection string as handed to you by the Onesecondbefore team. If your cloud is Google Cloud, the conn_id is not obliged. It will take the client_cloud.db_conn_id.
view_idintegeryesPut the view ID of the data you want to import. Format must be like ga:123456
dimensionsarray of enumerator(full list here)noList of dimensions.
metricsarray of enumerator(full list here)noList of metrics.
include_empty_rowsyesno (boolean)noDefault is no. If the data can include empty rows.
order_bysarray of objectsnoOrder the resultset on a field and optional direction (either ascending or descending)
segmentsarray of stringsnoContains the segments. Can be segment id's (e.g. gaid::-3) or dynamic segments (e.g. sessions::condition::ga:eventLabel=@some_label).
filters_expressionarray of stringsnoContains the filters, e.g. ga:medium==referral.
page_sizeintegernoUse this if you want to limit the import.

Details

itemdescription
APIGoogle Analytics Core Reporting API v4
Pre-formatted schemaYes. Comes with a pre-formatted and described schema.
TransformsYes. Field names are all transformed with the following transform configuration:
  • {'type': 'fields_search_and_replace', 'search': 'ga:', 'replace': ''}
  • {'type': 'fields_to_snake_case'}
  • {'type': 'fields_search_and_replace', 'search': '1day_users', 'replace': 'active_1day_users'}
  • {'type': 'fields_search_and_replace', 'search': '7day_users', 'replace': 'active_7day_users'}
  • {'type': 'fields_search_and_replace', 'search': '14day_users', 'replace': 'active_14day_users'}
  • {'type': 'fields_search_and_replace', 'search': '28day_users', 'replace': 'active_28day_users'}
  • {'type': 'fields_search_and_replace', 'search': '30day_users', 'replace': 'active_30day_users'}