June 16, 2026
How to Track A/B Tests in GA4: The Complete Setup Guide for 2026
GA4 doesn't have built-in A/B testing — here's how to track experiment variants using custom dimensions, GTM, and free tools like PageDuel so you can analyze results in Google Analytics 4.
Google Optimize shut down in September 2023, and Google confirmed that GA4 will never get a native A/B testing feature. That leaves millions of marketers with a powerful analytics platform that can't run experiments on its own.
The good news: GA4 is excellent at analyzing A/B test results — you just need to send it the right data. In this guide, you'll learn exactly how to track experiment variants in GA4 using custom dimensions, Google Tag Manager, and a third-party testing tool. The whole setup takes about 15 minutes.
Why GA4 Can't Run A/B Tests (But Can Track Them)
GA4 is an analytics platform, not an experimentation engine. It can't randomly split traffic, assign visitors to variants, or compute statistical significance. What it can do is slice every event, conversion, and metric by any custom dimension you define — including experiment variant.
That's the key insight: if your A/B testing tool pushes variant assignments into GA4 as custom dimensions, you can use Explorations, funnel reports, and audience comparisons to analyze how each variant performs across your entire analytics dataset. It's the best of both worlds — a dedicated testing tool handles assignment and significance, while GA4 gives you the full behavioral picture.
If you're still looking for the right testing tool after the Google Optimize shutdown, there are strong free options available today.
What You Need Before You Start
Before setting up tracking, make sure you have three things in place:
- A GA4 property with your measurement ID (starts with G-)
- Google Tag Manager installed on your site (or gtag.js if you prefer hardcoding)
- An A/B testing tool that assigns visitors to variants — PageDuel works perfectly here and is completely free
Your testing tool handles the hard part: splitting traffic, persisting assignments across sessions, and calculating statistical significance. GA4's job is to receive variant data and let you explore it alongside your existing analytics.
Step 1: Create Custom Dimensions in GA4
Custom dimensions are the bridge between your testing tool and GA4 reports. You need two:
- Go to Admin → Data display → Custom definitions
- Click Create custom dimension
- Create your first dimension:
- Dimension name: experiment_name
- Scope: Event
- Event parameter: experiment_name
- Create a second dimension:
- Dimension name: experiment_variant
- Scope: Event
- Event parameter: experiment_variant
GA4 allows up to 50 event-scoped custom dimensions on the free tier, so two more won't hurt your quota. These dimensions take 24-48 hours to start appearing in standard reports, but show up immediately in Realtime and Explorations.
Step 2: Push Variant Data via Google Tag Manager
Your A/B testing tool needs to push the variant assignment into the GTM data layer so GA4 can pick it up. Most tools — including PageDuel, VWO, Convert, and Optimizely — do this automatically or with a one-click integration.
If you're using a tool that writes to the data layer, the event looks like this:
window.dataLayer.push({
event: "experiment_impression",
experiment_name: "hero-headline-test",
experiment_variant: "variant-b"
});
In GTM, create a Custom Event trigger for experiment_impression, then create a GA4 Event tag that fires on this trigger. Map the two data layer variables (experiment_name and experiment_variant) as event parameters. For a deeper dive on GTM-based testing, see our complete GTM A/B testing guide.
Step 3: Analyze Results in GA4 Explorations
Once data flows in (give it 24-48 hours for custom dimensions to populate), you can build a dedicated experiment report:
- Go to Explore → Blank exploration
- Add experiment_name and experiment_variant as dimensions
- Add your metrics: Sessions, Conversions, Conversion rate, Revenue
- Drag experiment_name into Rows, experiment_variant into Columns, and your metrics into Values
- Apply a filter for the specific experiment you want to analyze
This gives you a side-by-side comparison of how each variant performed across every metric GA4 tracks — not just the primary goal your testing tool measures. You might discover that Variant B lifts sign-ups but tanks pageviews per session, which is exactly the kind of insight GA4 excels at surfacing.
Step 4: Build Audiences for Deeper Segmentation
GA4 audiences let you create persistent segments based on experiment participation. Go to Admin → Data display → Audiences and create an audience where experiment_variant equals your variant name.
This unlocks powerful analysis: compare how variant groups behave over time, track downstream conversions days or weeks after exposure, and even export these audiences to Google Ads for remarketing. It's the most underused feature in the GA4-experimentation workflow.
Common Mistakes to Avoid
Tracking A/B tests in GA4 is straightforward, but a few pitfalls trip up even experienced marketers:
- Using session-scoped dimensions instead of event-scoped. Event scope gives you more flexibility and works better with GA4's event-driven model.
- Forgetting to filter by date range. GA4 custom dimensions apply retroactively to all data, so always filter to the experiment's actual run dates.
- Relying on GA4 for statistical significance. GA4 shows raw numbers but doesn't calculate confidence intervals or p-values. Use your testing tool for significance — or check out a free A/B testing tool that handles the math automatically.
- Not accounting for sampling. GA4 samples data in Explorations above ~500K rows. For high-traffic tests, use the GA4 BigQuery export for unsampled analysis.
For more pitfalls to watch out for, read our guide on A/B testing mistakes to avoid.
The Simpler Alternative: Skip the GA4 Setup Entirely
If this setup feels like overkill for your needs, consider using an A/B testing tool with built-in analytics. PageDuel tracks conversions, calculates statistical significance, and shows you which variant wins — all without touching GA4 custom dimensions or GTM configurations. It's free, installs with a single script tag, and gives you results in a clean dashboard.
You still can send PageDuel data to GA4 using the method above if you want the full behavioral picture. But for most teams — especially those running their first few experiments — the built-in analytics are more than enough to make confident decisions.
Related Reading
Ready to test this on your own site?
PageDuel pairs free, privacy-friendly analytics with no-code A/B testing and revenue attribution — so you can find a leak, fix it, and prove the fix made money.
Free plan, free forever · No credit card · Set up in 5 minutes