Integrate Kameleoon with Google Analytics 4 – Event Streaming

Written by Julie Trenque

Updated on 05/07/2025

4 min

Advanced

Manage your integrations

Analytics

Automation

CDP

CMP

CMS/CRM/E-commerce

Data Warehouses

Developers

Was this content useful?

This feature is in open beta and is in active development. Contact the Kameleoon support team for support with this integration.

Description

The Kameleoon Google Analytics 4 Event Streaming integration allows you to automatically send events to your Google Analytics 4 account whenever visitors are exposed to one of your Kameleoon experiments. This enables enriched analytics in Google Analytics 4, providing insights on experiment exposure to help you better understand user behavior and engagement.

This integration uses Kameleoon’s event dispatcher to send server side events to your Google Analytics 4 account in batches using the /batch endpoint of the Google Analytics 4 HTTP API.

Key benefits

  • Precise Behavior Insights: The integration sends specific events to third-party tools for visitors exposed to web experiments and feature flags on SDK-based projects, such as apps. This detailed tracking enables a clearer view of how different variations impact user actions. For example, you can observe which variation drives more clicks, conversions, or other desired outcomes, helping you determine the most effective approach.
  • Real-time Decision Making: The integration provides data in real time, enabling on-the-fly decision making. Armed with up-to-date insights into ongoing experiments, you can swiftly adjust strategies if a variation isn’t performing as expected.
  • Effortless setup: Enable third-party integrations directly from the Kameleoon app with no need for custom code or SDK changes.

Considerations

Event delivery timing: Kameleoon server’s dispatched events to Google Analytics 4 with a minimum 30-minute delay.

Prerequisites

To configure this integration, you need the following information:

  • Kameleoon SDK must be installed on your server-side project.
  • Api Secret: The API SECRET generated in Google Analytics documented here.
  • Measurement ID: For Web SDK, the identifier for a Data Stream documented here.
  • Firebase App ID: For Mobile SDK, the identifier for a Firebase app documented here.

Setup

This integration can be activated for Web experiments and Feature Flags Experiments.

For Web experiments

Enable the integration from the Integrations page.

1. Identify GA4 client ID

You’ll need to send an instance identifier to the Kameleoon backend on each visit. The exact identifier depends on your GA4 setup. If you’re using GA4 with the gtag.js method, send the client_id. Below is an example of a gtag.js implementation using our Automation API.

2. Set up the Custom data

  • Name: “ga4_client_id**”.**
  • Select your project.
  • Choose the retrieval method: Kameleoon Activation API.
  • Select Type: Single.
  • Select Format: String.
  • Select Scope: Visit.

3. Add this code in the Global script

// first create a ga4ClientId variable and obtain your GA4 client id
let gaClientId = null;

gtag('get', 'G-XXXXXXXXXX', 'client_id', function(clientId) {
  gaClientId = clientId;
  console.log('GA4 Client ID:', gaClientId);
});

// then set your Kameleoon "ga_client_id" custom data to this value with our Automation API
Kameleoon.API.Data.setCustomData("ga4_client_id", ga4ClientId);

4. Activate the integration for your campaigns

Add the integration while finalizing your web experiment.

For Feature experiments

Set up the integration in the feature flag environment under the Integrations section. Enable it for each environment where you want it to be active.

For Mobile

If you’re using GA4 analytics with a Firebase app, you’ll need to send the Firebase app instance ID.

Here’s an example of how to do that with the Kameleoon Android SDK.

1. Identify GA4 Firebase app instance ID

2. Set up a Custom data

  • Name: “ga4_app_instance_id**”.**
  • Select your project.
  • Choose the retrieval method: Kameleoon SDK method.
  • Select Type: Single.
  • Select Format: String.
  • Select Scope: Visit.

Java example using the Kameleoon Android SDK

First, get your Firebase app instance ID and store it in a variable.

Next, use the Kameleoon SDK to set your “ga4_app_instance_id” custom data to this value, making sure to use the correct index for the “ga4_app_instance_id” custom data, which you can find in the Kameleoon interface.

In this example, the index is 12.

kameleoonClient.addData(new CustomData(12, appInstanceId));

Once the integration is activated and your experiment is live, Kameleoon will begin sending experiment events to Google Analytics 4 whenever a visitor is exposed. These events include key details such as:

  • User ID
  • Exposure Time
  • Kameleoon Experiment ID
  • Kameleoon Variation ID

Event Payload example

Kameleoon sends events to Google Analytics 4 in the following format:

{
"userId": "xf54dd2thdd5",
"event": "[Company] Experiment",
"properties": 
{ 
"experimentId": 12345,
"variationId": 15685 
},
"timestamp": 1730194985000
}

By default userId will contain the visitor’s Kameleoon visitor code. If you have set up Kameleoon cross device history reconciliation then the identifier put into the cross device reconciliation custom data will be taken instead of the visitor code.

Please note that any custom data specific to your business, typically included in your Google Analytics 4 events, will not be present in the events sent by Kameleoon from the server. If you need to enrich the payload with data not tracked natively by Kameleoon, you can submit a feature request.

  • In this article :