Google Tag Manager + GA4 set up guide

Introduction

This guide will walk you through integrating AB Split Test with Google Analytics 4 (GA4) using Google Tag Manager (GTM). By following these steps, you’ll be able to track split test visits and conversions in GA4, leveraging the dataLayer events pushed by the plugin.

The AB Split Test plugin pushes the following dataLayer object on split test visits and conversions:

window.dataLayer.push({
  'event': 'ab_split_test',
  'test_name': Your test name,
  'test_variation': Page ID or variation name,
  'test_event': 'visit' or 'conversion'
});

Prerequisites

  • Access to your website’s Google Tag Manager (GTM) account.
  • A Google Analytics 4 (GA4) property set up.
  • The AB Split Test plugin installed and configured on your website.

Step 1: Set Up Data Layer Variables in GTM

First, we’ll create variables in GTM to capture the custom parameters (test_name, test_variation, test_event) from the dataLayer.

1.1 Create Data Layer Variable for test_name

  1. In GTM, navigate to Variables > User-Defined Variables > New.
  2. Click on Variable Configuration.
  3. Select Data Layer Variable.
  4. Set Variable Name to dlv_test_name.
  5. Set Data Layer Variable Name to test_name.
  6. Click Save.

1.2 Create Data Layer Variable for test_variation

Repeat the steps above with the following details:

  • Variable Name: dlv_test_variation
  • Data Layer Variable Name: test_variation

1.3 Create Data Layer Variable for test_event

Repeat the steps again with:

  • Variable Name: dlv_test_event
  • Data Layer Variable Name: test_event

Step 2: Create a Custom Event Trigger in GTM

Next, we’ll set up a trigger that fires when the ab_split_test event is pushed to the dataLayer.

  1. In GTM, go to Triggers > New.
  2. Click on Trigger Configuration.
  3. Select Custom Event.
  4. Set Trigger Name to ab_split_test_trigger.
  5. In Event Name, enter ab_split_test.
  6. Under This trigger fires on, select All Custom Events.
  7. Click Save.

Step 3: Create a GA4 Event Tag in GTM

We’ll now create a tag that sends the event data to GA4 whenever the trigger fires.

  1. In GTM, navigate to Tags > New.
  2. Click on Tag Configuration.
  3. Select Google Analytics: GA4 Event.
  4. Choose your existing GA4 Configuration Tag from the dropdown.
  5. Set Event Name to ab_split_test (or a name of your choice).
  6. Under Event Parameters, click Add Row three times to add parameters:
    • Parameter Name: test_name; Value: {{dlv_test_name}}
    • Parameter Name: test_variation; Value: {{dlv_test_variation}}
    • Parameter Name: test_event; Value: {{dlv_test_event}}
  7. Click on Triggering and select ab_split_test_trigger.
  8. Name your tag GA4 - ab_split_test.
  9. Click Save.

Step 4: Preview and Debug in GTM

Before publishing, it’s important to test your setup.

  1. In GTM, click Preview to enter Debug Mode.
  2. Navigate to your website where the AB Split Test plugin is active.
  3. Perform actions that would trigger the ab_split_test event (e.g., visit a split test page or complete a conversion).
  4. In the GTM Debug Console, verify that:
    • The ab_split_test event appears under Events.
    • The variables dlv_test_name, dlv_test_variation, and dlv_test_event are capturing the correct values.
    • The GA4 – ab_split_test tag fires when the event occurs.

Step 5: Publish Your GTM Container

Once you’ve confirmed everything is working:

  1. In GTM, click Submit.
  2. Add a descriptive Version Name and Version Description (e.g., “Added AB Split Test tracking”).
  3. Click Publish.

Step 6: Configure GA4 to Receive Custom Parameters

To view the custom parameters in GA4 reports, you’ll need to register them as custom dimensions.

6.1 Access Custom Definitions

  1. In GA4, navigate to Configure > Custom definitions.
  2. Click on Create custom dimensions.

6.2 Create Custom Dimensions

For each parameter (test_name, test_variation, test_event):

  1. Set Dimension name to match the parameter (e.g., test_name).
  2. Optionally add a Description.
  3. Set Scope to Event.
  4. In Event parameter, enter the parameter name exactly (e.g., test_name).
  5. Click Save.

Note: It may take up to 24 hours for GA4 to start populating these custom dimensions in your reports.

Step 7: Verify Events in GA4

7.1 Use DebugView

  1. In GA4, go to Configure > DebugView.
  2. Perform the split test actions on your website again.
  3. In DebugView, verify that the ab_split_test event appears with the associated parameters.

7.2 Check Realtime Reports

  1. Navigate to Reports > Realtime.
  2. Look for the ab_split_test event and verify the parameters.

Conclusion

You’ve successfully integrated your AB Split Test plugin with Google Analytics 4 using Google Tag Manager. Now, you can monitor how different variations of your split tests are performing directly within GA4.

By capturing and analyzing these events, you’ll gain valuable insights into user behavior and the effectiveness of your split tests, enabling you to make data-driven decisions for your website.

Additional Tips

  • Custom Reports: Use GA4’s Exploration reports to analyze the custom dimensions in depth.
  • Event Parameters Limit: GA4 allows up to 25 custom parameters per event; ensure you stay within this limit.
  • Data Retention: Configure data retention settings in GA4 to keep your event data as long as needed.

Leave a Comment

You must be logged in to post a comment.