/Docs

Google Analytics Integration

The Google Analytics integration sends experiment assignment events to Google Analytics 4 (GA4) using gtag(). Once connected, every time a visitor is enrolled in an experiment, A vs B fires a GA4 custom event with the experiment and variation details. You can then use GA4's Explore tool to build custom reports segmented by experiment variation.

Setup

1

Go to Project Settings > Integrations

Open your project in A vs B, click Settings in the left sidebar, and then click the Integrations tab.
2

Enable Google Analytics 4

Find the Google Analytics 4 card and toggle it on.
3

Enter your Measurement ID (optional)

Enter your GA4 Measurement ID in the format G-XXXXXXXXXX. This is optional — if you leave it blank, the snippet will auto-detect an existing window.gtag instance on the page and use it. If you have already installed GA4 on your site (which you almost certainly have if you are enabling this integration), auto-detection is the easiest path.
4

Save

Click Save. The integration is now active.

What is sent to GA4

When a visitor is enrolled in a variation, A vs B calls:

javascript
1gtag('event', 'avsb_experiment', {
2 experiment_id: 'exp_abc123',
3 experiment_name: 'Homepage Hero Test',
4 variation_id: 'var_xyz789',
5 variation_name: 'Variation B',
6 event_name: 'experiment_viewed'
7});

The event name is avsb_experiment by default. This can be customized in the integration settings if you prefer a different name.

Viewing in GA4 reports

After the integration has been running and collecting data for at least 24 hours (GA4 processing delay), you can find experiment data in GA4:

  1. In GA4, go to Explore and create a new Free Form exploration.
  2. Add Event count as a metric.
  3. In the Dimensions panel, search for Event parameterand add experiment_name and variation_name as dimensions.
  4. Filter by Event Name = avsb_experiment to see only A vs B events.

You can also use these dimensions in existing reports to segment your conversion goals, funnels, and user behavior by experiment variation.

GA4 event parameter registration
Custom event parameters in GA4 must be registered as custom dimensions before they appear in standard reports (though they are still available in Explore immediately). Go to Admin > Custom Definitions and register experiment_id, experiment_name, variation_id, and variation_name as event-scoped custom dimensions.
Tip
If you are using Google Tag Manager to load GA4, auto-detection will work as long as gtag is initialized before A vs B runs. The standard GTM GA4 configuration tag initializes gtag on page load, which is almost always before the body of the page renders.