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
- In GTM, navigate to Variables > User-Defined Variables > New.
- Click on Variable Configuration.
- Select Data Layer Variable.
- Set Variable Name to
dlv_test_name
. - Set Data Layer Variable Name to
test_name
. - 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
.
- In GTM, go to Triggers > New.
- Click on Trigger Configuration.
- Select Custom Event.
- Set Trigger Name to
ab_split_test_trigger
. - In Event Name, enter
ab_split_test
. - Under This trigger fires on, select All Custom Events.
- 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.
- In GTM, navigate to Tags > New.
- Click on Tag Configuration.
- Select Google Analytics: GA4 Event.
- Choose your existing GA4 Configuration Tag from the dropdown.
- Set Event Name to
ab_split_test
(or a name of your choice). - 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}}
- Parameter Name:
- Click on Triggering and select
ab_split_test_trigger
. - Name your tag
GA4 - ab_split_test
. - Click Save.
Step 4: Preview and Debug in GTM
Before publishing, it’s important to test your setup.
- In GTM, click Preview to enter Debug Mode.
- Navigate to your website where the AB Split Test plugin is active.
- Perform actions that would trigger the
ab_split_test
event (e.g., visit a split test page or complete a conversion). - In the GTM Debug Console, verify that:
- The
ab_split_test
event appears under Events. - The variables
dlv_test_name
,dlv_test_variation
, anddlv_test_event
are capturing the correct values. - The GA4 – ab_split_test tag fires when the event occurs.
- The
Step 5: Publish Your GTM Container
Once you’ve confirmed everything is working:
- In GTM, click Submit.
- Add a descriptive Version Name and Version Description (e.g., “Added AB Split Test tracking”).
- 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
- In GA4, navigate to Configure > Custom definitions.
- Click on Create custom dimensions.
6.2 Create Custom Dimensions
For each parameter (test_name
, test_variation
, test_event
):
- Set Dimension name to match the parameter (e.g.,
test_name
). - Optionally add a Description.
- Set Scope to Event.
- In Event parameter, enter the parameter name exactly (e.g.,
test_name
). - 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
- In GA4, go to Configure > DebugView.
- Perform the split test actions on your website again.
- In DebugView, verify that the
ab_split_test
event appears with the associated parameters.
7.2 Check Realtime Reports
- Navigate to Reports > Realtime.
- 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.