Documentation
Plugins
Sources
Google Analytics
Configuration

Google Analytics Source Plugin Configuration Reference

Example

This example syncs from Google Analytics to a Postgres destination. The (top level) source spec section is described in the Source Spec Reference.

kind: source
# Common source-plugin configuration
spec:
  name: googleanalytics
  path: cloudquery/googleanalytics
  version: "v3.0.12"
  tables: ["*"]
  destinations: ["postgresql"]
  backend_options:
    table_name: "cq_state_googleanalytics"
    connection: "@@plugins.postgresql.connection"

  # Google Analytics specific configuration
  spec:
    property_id: "<YOUR_PROPERTY_ID_HERE>"
    oauth:
      access_token: "<YOUR_OAUTH_ACCESS_TOKEN>"
    reports:
    - name: example
      dimensions:
      - date
      - language
      - country
      - city
      - browser
      - operatingSystem
      - year
      - month
      - hour
      metrics:
      - name: totalUsers
      - name: new_users
        expression: newUsers
      - name: new_users2
        expression: "newUsers + totalUsers"
        invisible: true
      keep_empty_rows: true

Note that if backend_options is omitted, by default no backend will be used. This will result in all items being fetched on every sync.

For more information about managing state for incremental tables, see Managing Incremental Tables.

Google Analytics Spec

This is the (nested) spec used by the Google Analytics source plugin:

  • property_id (string) (required):

    A Google Analytics GA4 property (opens in a new tab) identifier whose events are tracked. To learn more, see where to find your Property ID (opens in a new tab).

    Supported formats:

    • A plain property ID (example: 1234)

    • Prefixed with properties/ (example: properties/1234)

  • reports ([]report) (required):

    Reports to be fetched from Google Analytics.

  • start_date (string) (optional) (default: date 7 days prior to the sync start):

    A date in YYYY-MM-DD format (example: 2023-05-15). If not specified, the start date will be the one that is 7 days prior to the sync start date.

  • oauth (OAuth spec) (optional) (default: empty)

    OAuth spec for authorization in Google Analytics.

  • concurrency (integer) (optional) (default: 10000):

    The best effort maximum number of Go routines to use. Lower this number to reduce memory usage.

Google Analytics OAuth spec

OAuth spec to authenticate with Google Analytics. Google Analytics Data API v1 (opens in a new tab) requires OAuth authorization for https://www.googleapis.com/auth/analytics.readonly scope to run reports.

  • access_token (string) (optional) (default: "")

    An access token that you generated authorizing for https://www.googleapis.com/auth/analytics.readonly scope (e.g., by using OAuth 2.0 Playground (opens in a new tab)).

  • client_id (string) (optional) (default: "")

    OAuth 2.0 Client ID. Required if access_token is empty.

  • client_secret (string) (optional) (default: "")

    OAuth 2.0 Client secret. Required if access_token is empty.

Google Analytics Report spec

Report specification will be transformed into a Google Analytics Data API v1 report (opens in a new tab). The option structure follows:

  • name (string) (required):

    Name of the report. It will be translated into a table name as ga_ prefix followed by report name in snake case.

  • dimensions ([]string) (optional) (default: empty)

    A list of Google Analytics Data API v1 dimensions (opens in a new tab). At most 9 dimensions can be specified per report.

  • metrics ([]metric) (required)

    A list of Google Analytics Data API v1 metrics (opens in a new tab). Expressions are supported, too.

  • keep_empty_rows (boolean) (optional) (default: false)

    Whether empty rows should be captured, too.

Google Analytics metric spec

Metric spec that is based on Google Analytics Data API v1 Metric (opens in a new tab) parameter.

  • name (string) (required)

    A name or alias (if expression is specified) of the requested metric.

  • expression (string) (optional) (default: "")

    A mathematical expression for derived metrics.

  • invisible (boolean) (optional) (default: false)

    Indicates if a metric is invisible in the report response. This allows creating more complex requests, while also not saving the intermediate results.