/Docs

Custom Integration

If your analytics platform is not listed in the built-in integrations, you have two ways to receive A vs B experiment events and forward them anywhere you need: the Google Tag Manager dataLayer push and the JavaScript onEvent callback. Both give you full access to the experiment data and let you route it to any tool.

Google Tag Manager: dataLayer

When the GTM integration is enabled, A vs B pushes experiment events to window.dataLayer — the standard data exchange layer used by Google Tag Manager. You can then configure GTM triggers and tags to listen for these events and forward the data to any platform GTM supports.

What is pushed to dataLayer

javascript
1window.dataLayer.push({
2 event: 'avsb_experiment',
3 experiment_id: 'exp_abc123',
4 experiment_name: 'Homepage Hero Test',
5 variation_id: 'var_xyz789',
6 variation_name: 'Variation B',
7 event_name: 'experiment_viewed',
8 revenue: null // or a number if this is a revenue conversion event
9});

The event key is set to avsb_experiment by default. You can customize the event name in the integration settings.

Setting up the GTM trigger

In Google Tag Manager, create a new trigger to listen for this event:

  1. Go to Triggers > New in GTM.
  2. Choose Custom Event as the trigger type.
  3. Set Event Name to avsb_experiment (or your custom event name).
  4. Configure the trigger to fire on All Custom Eventsor add conditions to filter for specific experiments.
  5. Create a tag that uses this trigger. The tag can access the experiment data via GTM variables: {{DLV - experiment_name}}, {{DLV - variation_name}}, etc.
Reading dataLayer variables in GTM tags
javascript
1// In a Custom HTML tag in GTM, you can read:
2var experimentName = {{DLV - experiment_name}};
3var variationName = {{DLV - variation_name}};
4
5// Send to your platform
6myAnalytics.track('A/B Test Viewed', {
7 experiment: experimentName,
8 variation: variationName
9});
Custom event name
You can change the default event name from avsb_experiment to any name that fits your existing GTM naming convention. Update it in Project Settings > Integrations > Google Tag Manager.

JavaScript onEvent callback

The window.avsb.onEvent callback is the most flexible integration mechanism. You define a JavaScript function that A vs B calls every time an experiment event fires. This function receives the full event object and can do anything you want with it — send it to any analytics tool, log it to your console, post it to your own API.

Setting up the callback

Define window.avsb.onEvent anywhere in your JavaScript, ideally before the A vs B snippet initializes. If you define it after initialization, it will still receive future events.

Basic onEvent callback
javascript
1window.avsb = window.avsb || {};
2window.avsb.onEvent = function(event) {
3 console.log('A vs B event:', event);
4};

The event object

The event object passed to your callback contains:

javascript
1{
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', // or 'conversion'
7 revenue: null // or a number for revenue conversion events
8}

Callback examples

Send to a custom analytics tool
javascript
1window.avsb = window.avsb || {};
2window.avsb.onEvent = function(event) {
3 if (event.event_name === 'experiment_viewed') {
4 myAnalytics.track('Experiment Viewed', {
5 experiment: event.experiment_name,
6 variation: event.variation_name
7 });
8 }
9};
Send to a custom API endpoint
javascript
1window.avsb = window.avsb || {};
2window.avsb.onEvent = function(event) {
3 fetch('/api/experiment-events', {
4 method: 'POST',
5 headers: { 'Content-Type': 'application/json' },
6 body: JSON.stringify(event)
7 }).catch(function() {
8 // fail silently — don't interrupt the user experience
9 });
10};
Pendo integration via callback
javascript
1window.avsb = window.avsb || {};
2window.avsb.onEvent = function(event) {
3 if (typeof pendo !== 'undefined' && event.event_name === 'experiment_viewed') {
4 pendo.track('avsb_experiment', {
5 experiment_name: event.experiment_name,
6 variation_name: event.variation_name
7 });
8 }
9};
The callback fires synchronously
The onEvent callback is called synchronously in the same execution context as the A vs B event. Keep the callback function fast — avoid blocking operations. For network requests, use fetch() or XMLHttpRequest asynchronously so the callback returns quickly.
Tip
The onEvent callback is the right choice when you need to connect A vs B to a platform that is not in the standard integration list and is not available in Google Tag Manager. Common examples include Pendo, Intercom, HubSpot, custom data warehouses, and internal analytics systems.