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
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 event9});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:
- Go to Triggers > New in GTM.
- Choose Custom Event as the trigger type.
- Set Event Name to
avsb_experiment(or your custom event name). - Configure the trigger to fire on All Custom Eventsor add conditions to filter for specific experiments.
- Create a tag that uses this trigger. The tag can access the experiment data via GTM variables:
{{DLV - experiment_name}},{{DLV - variation_name}}, etc.
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 platform6myAnalytics.track('A/B Test Viewed', {7 experiment: experimentName,8 variation: variationName9});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.
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:
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 events8}Callback examples
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_name7 });8 }9};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 experience9 });10};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_name7 });8 }9};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.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.