跳到主要内容

Google Analytics 4 (GA4)

This page contains the setup guide and reference information for Google Analytics 4 (GA4).

Prerequisites

  • A Google Analytics account with access to the GA4 property you want to sync
  • Google Service Account JSON Key
  • Google Analytics Property ID

Features

FeatureSupported?
Full Refresh SyncYes
Incremental SyncYes
NamespacesNo

Setup guide

Step 1: Create a GA4 Service Account for authentication

  1. Sign in to the Google Account you are using for GA as an admin.

  2. Go to the Service Accounts page in the Google Developers console. GA4 Service Accounts

  3. Select the project you want to use (or create a new one).

  4. Click + Create Service Account at the top of the page. GA4 Create Service Account

  5. Enter a name for the service account, and click Create and Continue. GA4 Service Account Details

  6. Choose the role for the service account. We recommend the Viewer role (Read & Analyze permissions). Click Continue. And then click Done. GA4 Service Account Role

  7. Select your new service account from the list, and open the Keys tab. Click Keys > Add Key. GA4 Service Account Add Key

  8. Select JSON as the Key type. Then click Create. This will generate and download the JSON key file that you'll use for authentication.

Step 2: Enable the Google Analytics APIs

  1. Go to the Google Analytics Reporting API dashboard. Make sure you have selected the associated project for your service account, and Enable the API. You can also set quotas and check usage. GA4 Reporting API

  2. Go to the Google Analytics API dashboard. Make sure you have selected the associated project for your service account, and Enable the API. GA4 API

  3. Go to the Google Analytics Data API dashboard. Make sure you have selected the associated project for your service account, and Enable the API. GA4 Data API

Step 3: Obtain your GA4 property id

  1. Sign in to the Google Analytics account as an admin.

  2. On the left sidebar, click Admin. GA4 Admin

  3. Click Property. GA4 Property

  4. Click Property details and you will find your Property ID on the top right corner. This ID should be a numeric value, such as 123456789. Copy it for later use. GA4 Property ID

Step 4: Grant Service Account GA4 property access

  1. Following Step 3, inside the Admin area of your GA4 account, click Account Access Management. GA4 Account Access

  2. Click the blue + button in the right top corner of your screen. And click Add Users. GA4 Add User

  3. Enter the email address of your Service Account user you created in Step 1. You can find the email listed in Service accounts in your Google Cloud Platform. GA4 Service Account Email

  4. Assign a role to the Service Account user. Daspire only needs the Viewer role. And click Add. GA4 Roles

Step 5: Set up GA4 in Daspire

  1. Select Google Analytics 4 (GA4) from the Source list.

  2. Enter a Source Name.

  3. Select Service Account Key Authenication dropdown list and enter Service Account JSON Key you obtained from Step 1.

  4. Enter the GA4 Property ID you obtained from Step 3.

  5. (Optional) In the Start Date field, enter a date in the format YYYY-MM-DD. All data added from this date onward will be replicated. Note that this setting is not applied to custom Cohort reports.

    Note: If the start date is not provided, the default value will be used, which is two years from the initial sync.

  6. (Optional) In the Custom Reports field, you may optionally provide a JSON array describing any custom reports you want to sync from GA4. See the Custom Reports section below for more information on formulating these reports.

  7. (Optional) In the Data Request Interval (Days) field, you can specify the interval in days (ranging from 1 to 364) used when requesting data from the Google Analytics API. The bigger this value is, the faster the sync will be, but the more likely that sampling will be applied to your data, potentially causing inaccuracies in the returned results. We recommend setting this to 1 unless you have a hard requirement to make the sync faster at the expense of accuracy. This field does not apply to custom Cohort reports. See the Data Sampling section below for more context on this field.

  8. Click Save & Test.

Supported streams

This source is capable of syncing the following streams:

Integration-specific features

Custom Reports

Custom reports in GA4 allow for flexibility in querying specific data tailored to your needs. You can define the following components:

  • Name: The name of the custom report.
  • Dimensions: An array of categories for data, such as city, user type, etc.
  • Metrics: An array of quantitative measurements, such as active users, page views, etc.
  • CohortSpec: (Optional) An object containing specific cohort analysis settings, such as cohort size and date range. More information on this object can be found in the GA4 documentation.
  • Pivots: (Optional) An array of pivot tables for data, such as page views by city, etc. More information on pivots can be found in the GA4 documentation.

A full list of dimensions and metrics supported in the API can be found here. To ensure your dimensions and metrics are compatible for your GA4 property, you can use the GA4 Dimensions & Metrics Explorer.

Custom reports should be constructed as an array of JSON objects in the following format:

[
{
"name": "<report-name>",
"dimensions": ["<dimension-name>", ...],
"metrics": ["<metric-name>", ...],
"cohortSpec": {/* cohortSpec object */},
"pivots": [{/* pivot object */}, ...]
}
]

The following is an example of a basic User Engagement report to track sessions and bounce rate, segmented by city:

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

By specifying a cohort with a 7-day range and pivoting on the city dimension, the report can be further tailored to offer a detailed view of engagement trends within the top 50 cities for the specified date range.

[
{
"name": "User Engagement Report",
"dimensions": ["city"],
"metrics": ["sessions", "bounceRate"],
"cohortSpec": {
"cohorts": [
{
"name": "Last 7 Days",
"dateRange": {
"startDate": "2023-07-27",
"endDate": "2023-08-03"
}
}
],
"cohortReportSettings": {
"accumulate": true
}
},
"pivots": [
{
"fieldNames": ["city"],
"limit": 50,
"metricAggregations": ["TOTAL"]
}
]
}
]

Data Sampling and Data Request Intervals

Data sampling in GA4 refers to the process of estimating analytics data when the amount of data in an account exceeds Google's predefined compute thresholds. To mitigate the chances of data sampling being applied to the results, the Data Request Interval field allows users to specify the interval used when requesting data from the Google Analytics API.

By setting the interval to 1 day, users can reduce the data processed per request, minimizing the likelihood of data sampling and ensuring more accurate results. While larger time intervals (up to 364 days) can speed up the sync, we recommend choosing a smaller value to prioritize data accuracy unless there is a specific need for faster synchronization at the expense of some potential inaccuracies. Please note that this field does not apply to custom Cohort reports.

Refer to the Google Analytics documentation for more information on data sampling.

Data type mapping

Integration TypeDaspire Type
stringstring
numbernumber
arrayarray
objectobject

Troubleshooting

  1. The Google Analytics integration is subject to Google Analytics Data API quotas. Please refer to Google's documentation for specific breakdowns on these quotas.

  2. Max number of tables that can be synced at a time is 6,000. We advise you to adjust your settings if it fails to fetch schema due to max number of tables reached.