top of page
Writer's pictureKelvin Luhr

Setting Up Custom Dimensions for A/B Testing with Experiment ID in GA4: A Step-by-Step Guide

Ever run an A/B test and wished you could easily track its impact in Google Analytics 4 (GA4)? While GA4 doesn't have built-in A/B testing yet, don't worry! You can leverage custom dimensions to achieve similar results, including capturing Experiment ID. This guide will walk you through setting up custom dimensions to collect the necessary data for A/B testing. If you're interested in further analyzing your A/B tests, be sure to check out our guide on setting up a Bayesian AB Testing dashboard here.


 

Step 1: Select an A/B Testing Tool and Setup Type


Choose an A/B testing platform that aligns with your testing requirements:


  • Recommended Tools: Consider platforms like Optimizely, VWO, or AB Tasty, which support both client-side and server-side testing.


  • Integration: Ensure seamless integration with Piwik PRO for comprehensive data tracking.


  • Consideration of Testing Type: Server-side testing offers more control and often better performance, but if you opt for client-side testing, ensure that your tool's configuration is compatible with Piwik PRO's data tracking mechanisms.


 

Step 2: Define Your Experiment Details


Begin by outlining the framework of your A/B test:


  • Experiment Name: Choose a descriptive name that captures the essence of your test, such as "Homepage Button Color Test."


  • Experiment Variations: Define the different versions that participants will experience, such as "Original" vs. "Variant-1"


  • Experiment ID (Optional): Create a unique identifier for tracking multiple tests simultaneously, like "Experiment 1" or "Experiment 2." Important Note: If you choose to implement an Experiment ID, keep in mind that you’ll only be able to run one test at a time. Running a new test while another is active will cause the tracking to overwrite the previous test’s ID with the latest one, resulting in only the most recent test ID being stored.


Tip: Maintaining a consistent naming convention is key for streamlined tracking and analysis later on.


 

Step 3: Set Up Event Parameters in Google Tag Manager (GTM)


Prepare to capture data by configuring GTM:


  • Decide on an Event Name: Choose a standardized event name for all experiment interactions. For example, you might name the event 'experimentEvent'.


  • Create Event Parameters as Variables in GTM:


    • Navigate to Variables within GTM and click "New."


    • Variable Setup:


      • Variable Type: Select "Data Layer Variable."


      • Name the Variable: Such as experimentName.


      • Data Layer Variable Name: Enter the key that matches your dataLayer push, like experimentName.


      • Repeat this process to create variables for experimentVariation and experimentId.


  • Implement Data Layer Push: Coordinate with your developer to embed these parameters into your site’s or app’s code using the dataLayer:

dataLayer.push({ 
'event': 'experimentEvent', // Standardized event name
'experimentName': 'Homepage Button Color Test', 
'experimentVariation': 'Variant-1', 
'experimentId': 'Experiment 1'  // Optional 
});

Tip: Ensure the dataLayer push is triggered when a user encounters a specific variation.


 

Step 4: Configure Tags and Triggers in Google Tag Manager


Set up the tags and triggers using the parameters you've just created:


  • Create a Custom Event Trigger:


    • Navigate to Triggers in GTM and click "New."


    • Trigger Setup:


      • Trigger Type: Select "Custom Event."


      • Event Name: Enter 'experimentEvent' as the event that triggers this.


      • Save the trigger.


  • Create GA4 Event Tags:


    • Navigate to Tags and click "New" to create a new tag.


    • Tag Configuration:


      • Tag Type: Select "Google Analytics: GA4 Event."


      • Configure the Tag:


        • Event Name: Such as 'experiment'


        • Event Parameters: Attach the variables you created (e.g., experiment_name, experiment_variation and optinally eperiment_id).


        • Triggering: Link the tag to the custom event trigger you just created.


    • Save the tag.


  • Test and Publish:


    • Use GTM’s preview mode to test your tags, ensuring they fire correctly and capture the detailed data.


Tip: Testing your configuration is crucial to ensure accurate data capture.


 

Step 5: Create Custom Dimensions in GA4


Now that the parameters and tags are correctly set up in Google Tag Manager, it's time to configure the corresponding custom dimensions in Google Analytics 4:


  1. Log In to Your GA4 Property: Access your GA4 dashboard to begin setting up the dimensions.


  2. Access Admin Settings: Navigate by clicking the gear icon located in the bottom left corner of your GA4 interface.


  3. Navigate to Custom Definitions:


    • Find Custom Definitions: Under the 'Property settings' in the left menubar, click on "Data display," then select "Custom Definitions".


  4. Create Custom Dimensions:


    • Initiate New Dimensions: Click 'Create Custom Dimensions'.


    • Configure Each Dimension:


      • Name: Assign a name that accurately describes its purpose, such as 'Experiment Name'.


      • Scope: Select "User" to ensure the dimension captures data across the user’s sessions.


      • Description: Add a brief description for clarity, e.g., "Captures the overall experiment name."


      • Event Parameter: Link each dimension to the corresponding parameter set up in GTM, like experimentName. Include experimentId only if you choose to utilize this optional parameter.


Tip: It’s crucial to match the GTM parameters precisely with the GA4 custom dimensions to ensure that the data flows correctly and is accurately captured for analysis.


 

Step 6: Analyze Your A/B Test Results in GA4


Once users interact with your A/B test variations, the data will flow into GA4 with the custom dimension values. Here's how to analyze the test's impact:


  1. Go to "Explore" in the left menu of GA4.


  2. Create a new exploration by clicking the blank option.


  3. Add "Experiment Name," "Experiment Variation," and "Experiment ID" (if applicable) as dimensions to your report.


  4. Analyze key metrics like conversions, user engagement, and more between different variations.


  5. Tip: You can further segment your data to drill down into specific user behaviors and test outcomes.


 

By following these steps, you'll be able to track and analyze your A/B tests effectively within GA4, even without native A/B testing functionality. If you're looking to take your analysis further and set up a Bayesian AB Testing dashboard with this data, be sure to check out our other guide here for a detailed walkthrough. Happy testing and data-driven decision-making!

bottom of page