Skip to content

Setting up Google Analytics integration

This tutorial will explain the process of leveraging data from Google Analytics 4 (GA4) in Ecommerce Search. After following this guide, you will know how to use GA4 metrics as commercial parameters.

Prerequisites

Before configuring the Ecommerce Search integration with GA4, a few things need to be in place:

Configure the Ecommerce Search integration with GA4 requires the following steps:

  1. Connect a segment to a GA4 property with service account credentials
  2. Connect parameters to GA4 metrics

The integration to GA4 is configured through the Courier API.

Segment settings

Ecommerce Search must be provided with a property ID and corresponding service account credentials to access Google Analytics.

The credentials consist of a serviceAccountId, which refers to the service account email, and a privateKey, which can be obtained by following one of these guides.

Example

Adding service account credentials to a segment named b2b-dk-da

POST /courier-api/b2b-dk-da/google-analytics-4
1
2
3
4
5
{
    "property": "213025502",
    "serviceAccountId": "demo-account@ga4-demo-project.iam.gserviceaccount.com",
    "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDhpbB7yS/oF1A8\nETLmvwjwbMn21sxcrTAFPCLo36TQPWxUfcM7Car2cjBOgLmelkdE0yV6eFAO3iFO\nACIdPJtbfK0GVqe07hFy06FDfb6UUOgYhdpyvhpQCytQrZelDV52DkYkpL5n9oPU\nLHr2AkJrwQBeDsaO5ZNwif5nMKRP6UkA9y9KN1g+T8AeaPgauFLzz/34t1ke1biY\nWsvJz6tVoZE1ODGWVcxdcIvX4hWjQgK39nEaCpQ6GSyFKwlQ7s8OQ+Ug+oCUQDuo\nNgKT38PhhLY6AIX1roasqh4yzPcnn/0Dyjqmr4qaRw9gVATatKa8dADX+CfRRp6L\nJlnKpLfBAgMBAAECggEAI8NR9FyPpjZDtjF3otC2RvzHCcNDgpDEYqAEXGpNwd9q\nUv3Xunyuxv6UH20RfkwNIaBheUamUaTtHGKzBXU8nkRlW/LSA8ATreJS1dKRKQql\nrnVQiQ0OOI98nv3UYgl7ZjSe82HU978/Z5phJqp3AoMFXuLyn2VNd/G3C33PHQbt\nJELtMH5qnbUgc0KpjxAt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the entire private key in the request without any modifications. The '\n' characters must be included.

Parameter settings

Once the GA4 credentials have been configured, Ecommerce Search can be configured to ingest commercial parameter values.

Example

Populating SKUs with a parameter, sales-7d, containing the total number of purchases of that SKU in the last 7 days.

POST /courier-api/{segmentId}/google-analytics-4/commercial-parameters/sales-7d
1
2
3
4
5
6
{
    "dimension": "itemId",
    "metric": "itemsPurchased",
    "startDate": "7daysAgo",
    "endDate": "yesterday"
}

The dimension and metric are the GA4 dimension and metric to ingest. Please refer to the dimension and metric explorer for a list of valid dimensions and metrics. In the above example, the dimension itemId is used to get the metric itemsPurchased for each SKU.

The startDate and endDate fields determine the timespan of the data. In the example the range is from yesterday to 7 days ago, resulting in a weeks worth of data. See the official Google documentation of date ranges for more information.

Migrating from Universal Analytics

Warning

Previously configured Universal Analytics settings will still ingest data. Data ingested from Universal Analytics may conflict with data ingested from Google Analytics 4. This can be avoided by deleting old Universal Analytics settings.

Dimensions and metrics have new names in Google Analytics 4. A guide for converting Universal Analytics dimensions and metrics to Google Analytics 4 is available from Google. Note that dimensions and metrics with similar names may not share semantics. See API reference for detailed descriptions.

Next steps