Set up Google Tag Manager to send data to Google Analytics 4

This is for:

Developer

If you have implemented the Google Analytics 4 (GA4) tag on your site via Google Tag Manager, you need to set up the trigger, variables, and GA4 tags so that Coveo Experimentation Hub (CEH) can send the GTM event and custom events to GA4.

Warning

CEH doesn’t send events to Google Universal Analytics (Google UA) and Google Analytics 4 (GA4) if any or both of the following are true:

  • the qb_dnt cookie is set to 1 or 2

  • the qb_dnt_ext cookie is set to ga

Note

When a visitor is served an experience, CEH sends a single custom event to GA4 and a single GTM event (for tags implemented via GTM).

CEH send these only once per session, when the visitor is served the experience.

Warning

These events are only sent for published experiences.

Set up the trigger

You need to create a trigger to detect when CEH sends the GTM event.

  1. Log in to your GTM account.

  2. From the left menu, select Triggers.

  3. Click the New button.

    The trigger card appears.

  4. At the top of the card, enter a trigger name.

  5. In the Trigger Configuration panel, click anywhere to open the Choose trigger type pane.

  6. Select Custom Event.

    The Trigger Configuration panel now shows trigger fields and settings.

  7. Specify the following:

    • In the Event name field, enter ceh_experience.

    • Select the Some Custom Events option.

    • Define the following trigger conditions: Event > equals > ceh_experience.

  8. Click the Save button.

Set up variables

Next, you need to create and set up variables for the experience ID and variation ID. GTM will send these variables to your GA4 tag.

  1. From the left menu, select Variables.

  2. In the User-Defined Variables section, click the New button.

    The variable card appears.

  3. Enter CEH experience ID as the variable name.

  4. In the Variable Configuration panel, click anywhere to open the Choose variable type pane.

  5. Select Data Layer Variable.

    The Variable Configuration panel now shows variable fields and settings.

  6. Specify the following:

    • In the Data Layer Variable Name, enter experience_id.

    • In the Data Layer Version menu, select Version 2.

  7. Click the Save button.

You created a CEH Experience ID to store the experience ID.

Repeat these steps to create a variable for the variation ID, but use the following values for a new variable:

  • CEH variation main ID as the variable name.

  • variation_master_id as the Data Layer Variable Name.

Set up the GA4 tag

Now you need to create and configure two GA4 tags:
  • Google Analytics: GA4 Configuration—allows GTM to send data to GA4.

  • Google Analytics: GA4 Event—allows GTM to send custom events to GA4.

    1. Create a Google Analytics: GA4 Configuration tag. Don’t specify Triggering for this tag.

    2. While being in the Tags section, click the New button.

      The tag card appears.

    3. At the top of the card, enter a trigger name.

    4. In the Tag Configuration panel, click anywhere to open the Choose tag type pane.

    5. Select Google Analytics: GA4 Event.

      The Tag Configuration panel now shows tag fields and settings.

    6. Specify the following:

      1. In the Configuration Tag menu, select the configuration tag created in step 1.

      2. In the Event name field, enter ceh_experience.

      3. In the Event parameters subsection, you need to add two rows.

        Click the Add row button.

        1. In the Parameter Name, enter CEH experience ID.

        2. In the Value field, click the button to the right and select the CEH experience ID variable.

      4. Click the Add row button.

        1. In the Parameter Name, enter CEH variation main ID.

        2. In the Value field, click the button to the right and select the CEH variation main ID variable.

    7. In the Triggering panel, click anywhere to open the Choose a trigger pane.

    8. Select the trigger you created earlier.

      The tag properties should look like this:

      Properties of GA4 Event tag
    9. Click the Save button.