How GA4 audiences fit into your workflow
- Set up authentication: Create a Google Cloud service account, and give it Viewer access to your GA4 property.
- Push visitor codes to GA4: Send each visitor’s Kameleoon visitor code to GA4 in a custom dimension, with gtag.js or Google Tag Manager.
- Create custom data: Add your GA4 audiences to Kameleoon as custom data, so you can select them in a segment.
Before you begin
- Administrator access: An email account with administrator access to your GA4 account. You use it to create a Google Cloud project and service account, and it needs access to every audience you want to use.
- Information for your Customer Success Manager: Send the following to your Kameleoon Customer Success Manager, who sets up the bridge in your account:
- The credentials of the service account, in JSON format.
- Your GA4 property ID.
- Your Kameleoon project’s sitecode.
Step 1: Set up authentication with a service account
A service account lets the bridge call the Google Analytics APIs automatically, without an authentication callback.Create a project in Google Cloud console
Create a Google Cloud project to hold the APIs and the service account for this integration.- Go to the Google Cloud console, and sign in with your administrator email account.
- Create a new project.
- Name the project, and choose your organization and location.

Activate the APIs
Activate the three Google Analytics APIs in your project, so the bridge can read your GA4 data.- Click APIs & Services > Library.
- Search for each of these APIs, and activate it:
- Google Analytics Reporting API
- Google Analytics Data API
- Google Analytics API

Create a service account
Create a service account, and download a JSON key for it.- Click IAM & Admin > Service accounts.

- Click Create service account.

- Enter a name and a description for the account, so its purpose is clear. Google generates the service account’s email address automatically.
- Choose the Viewer role. Kameleoon recommends this role.

- Once you create the account, click Keys.

- Click Add key > Create a new key.

- Choose the JSON format, and click Create to generate the key.

Grant the service account Viewer access to your GA4 property
Give the service account Viewer access, so it can read data from your GA4 property.- Sign in to your GA4 account, and select the property you want to manage.
- Open the Admin settings.
- Look for the Property User Management or Property Access Management option.
- Click + > Add user.

- In the Email addresses field, enter the email address of the service account.
- In the Standard roles section, select Viewer.
- Click Add.
Step 2: Push Kameleoon visitor codes to a GA4 custom dimension
Send each visitor’s KameleoonvisitorCode to GA4 through a custom dimension. Choose the method that matches how your site loads GA4.
Use gtag.js
1. Push the visitor code to GA4
Add the following code in the Kameleoon global custom script, on your project’s Scripts tab:2. Create the custom dimension in GA4
Create a custom dimension that receives the KameleoonvisitorCode for each visitor.
- Set the dimension scope to User.
- Name the dimension Kameleoon Visitor Code.
- Enter
kameleoon_visitor_codeas the user property.
Use Google Tag Manager
1. Push the visitor code in the dataLayer
Add the following code in the Kameleoon global custom script, on your project’s Scripts tab:2. Create a variable in GTM
Create a Data Layer Variable that reads the Kameleoon visitor code from the dataLayer.- Open Google Tag Manager, and navigate to your container.
- Click Variables in the left-hand menu.
- Under User-Defined Variables, click New.
- Click Variable Configuration, and choose Data Layer Variable.
- Configure the variable:
- Name:
kameleoon_visitor_code - Variable type: Data Layer Variable
- Data Layer Variable Name:
kameleoon_visitor_code
- Name:
- Click Save.

3. Create a trigger in GTM
Create a trigger that fires when the Kameleoon visitor code event reaches the dataLayer.- Click Triggers in the left-hand menu, and then click New.
- Click Trigger Configuration, and choose Custom Event.
- Configure the trigger:
- Trigger name: A descriptive name, for example, Kameleoon visitor code.
- Event name:
Kameleoon Visitor Code, which is the event the script pushes. - This trigger fires on: Choose Some Custom Events.
- Conditions: Set
kameleoon_visitor_codeto match the regular expression^[a-z0-9]{16}$, which matches the format of a visitor code.
- Click Save.
4. Attach the trigger to a tag
Create a GA4 tag that sends the visitor code to GA4, and attach the trigger to it.- Click Tags in the left-hand menu.
- Create a tag, or edit an existing one.
- In the tag configuration, scroll to the Triggering section, click Triggering, and select the trigger you created.

- Click Save.
Step 3: Create custom data to use your GA4 audiences in Kameleoon
To use your GA4 audiences in Kameleoon, create custom data that retrieves them for each visitor.Create the GA4 Audiences custom data
Create custom data that reads each visitor’s GA4 audiences.- Click Settings > Custom Data, and then click New custom data.
- Enter
GA4 Audiencesas the name, and select your project. - Set the Retrieval method to Custom JavaScript code.
- Set Type to List, Format to String, and Scope to Visit or Page. With the Page scope, Kameleoon resets the value on each new page.

- Paste the following code into the code field.
Add the audience names to the custom data
Add the audience names to the custom data, so the segment builder lists every GA4 audience. Complete these steps on the options page, which opens when you click Next.- Click Next to open the options.
- Turn on Save the values for the targeting condition associated with the custom data point. A code field appears.
- Paste the following script into the code field. Replace
[SITECODE]with your sitecode, and replace[WEB_PROPERTY]with your GA4 property ID.
- Click Create.
Build a segment from GA4 audiences
Build a segment that targets visitors in one or more GA4 audiences.- Click Settings > Segments, and then click New segment.
- Enter a name, select your project, and click Next.
- In the Conditions column, search for Custom data, and double-click it to add the condition.
- Select GA4 Audiences in the condition, choose is among the values, and then select the audiences you want to target.
- Choose whether to include or exclude the visitors who match the condition.
Use GA4 audiences with an SDK
To use GA4 audiences with a Kameleoon SDK, follow the guidance in that SDK’s documentation. The iOS SDK, for example, uses thegetRemoteData() method.