AB Testing
This guide shows how to set up an A/B test on your website to dynamically load either the Fuse tag or a competitor’s tag. Client can easily control the percentage of traffic and add optional CMP scripts (Consent Management Platform) if needed.
Instructions
1. Copy the A/B Test Script
The following script allows you to load either the Fuse ad tag or the competitor’s ad tag based on random selection. You can customize the percentage of traffic that loads each tag and add optional CMP scripts.
<head>
<script>
// A/B test logic to load either the Fuse ad tag or the competitor's ad tag
function runABTestForAdTags(config) {
var fuseTagURL = config.fuseTagURL;
var cmpScriptURL = config.cmpScriptURL;
var competitorTagURL = config.competitorTagURL;
var competitorCmpScriptURL = config.competitorCmpScriptURL;
// Set the percentage chance for loading your Fuse ad tag
var fuseTagPercentage = config.fuseTagPercentage || 50;
// Randomly choose a number between 0 and 100
var randomChoice = Math.random() * 100;
// Load the Fuse ad tag if the random number is within the percentage
if (randomChoice < fuseTagPercentage) {
// Load the Fuse ad tag
var fuseScript = document.createElement('script');
fuseScript.async = true;
fuseScript.src = fuseTagURL;
document.head.appendChild(fuseScript);
// Load CMP script if provided
if (cmpScriptURL) {
var cmpScript = document.createElement('script');
cmpScript.async = true;
cmpScript.src = cmpScriptURL;
document.head.appendChild(cmpScript);
}
/*
You can implement Fuse logic here: https://docs.publift.com/fuse-web/
For example, set targeting options like this:
const fusetag = window.fusetag || (window.fusetag = { que: [] });
fusetag.que.push(function () {
fusetag.setTargeting('weather', ['hot', 'sunny']);
fusetag.setTargeting('age', '18-39');
});
*/
} else {
// Load the competitor's ad tag
var competitorScript = document.createElement('script');
competitorScript.async = true;
competitorScript.src = competitorTagURL;
document.head.appendChild(competitorScript);
// Load competitor's CMP script if provided
if (competitorCmpScriptURL) {
var competitorCmpScript = document.createElement('script');
competitorCmpScript.async = true;
competitorCmpScript.src = competitorCmpScriptURL;
document.head.appendChild(competitorCmpScript);
}
}
}
// Example usage with A/B test configuration
runABTestForAdTags({
fuseTagURL: 'https://cdn.fuseplatform.net/publift/tags/2/2107/fuse.js',
cmpScriptURL: null, // Optional CMP script for Fuse
competitorTagURL: 'https://competitor.cdn.com/adtag.js',
competitorCmpScriptURL: null, // Optional CMP script for competitor
fuseTagPercentage: 50 // 50% chance to load your Fuse ad tag, 50% for competitor
});
</script>
</head>
2. Customize the Script
You can modify the following configuration options to fit your needs:
Fuse Ad Tag URL
- Description: The URL of your Fuse ad tag.
-
Example:
fuseTagURL: ‘https://cdn.fuseplatform.net/publift/tags/2/2107/fuse.js'
-
Competitor Ad Tag URL
- Description: The URL of the competitor’s ad tag.
-
Example:
competitorTagURL: ‘https://competitor.cdn.com/adtag.js'
-
Percentage Split
-
Description: To ensure as fair a test as possible traffic should be split 50/50. If however an alternative split has been discussed and approved, you can adjust the percentage of traffic that loads the Fuse ad tag versus the competitor’s ad tag. Set the fuseTagPercentage to control this split.
-
Example:
fuseTagPercentage: 50 // 50% chance for Fuse, 50% for competitor
-
CMP Script URLs
These fields are optional. They should only be populated if you want to use a CMP script that is not already imported on their site.
-
Fuse CMP Script: Optionally, you can provide a CMP script URL for the Fuse ad tag.
cmpScriptURL: ‘https://yourcmp.cdn.com/fuse_cmp.js' or cmpScriptURL: null
-
Competitor CMP Script: Optionally, provide a CMP script URL for the competitor ad tag.
competitorCmpScriptURL: ‘https://competitorcmp.cdn.com/competitor_cmp.js' or competitorCmpScriptURL: null