Easily set up a split test between Refinery89’s Single Tag and a third-party tag. This guide provides a script for running A/B tests on your website. This script ensures that once a visitor is assigned to either Refinery89 or another party’s solution, they will consistently see that same provider for the duration of the test (for default 30 days).
1. Script Implementation
Copy and paste the following code block into the section of your website, as high as possible to ensure the ad stack initializes before other page elements.
<script>
/* A/B testing script - loads either Refinery89 or competitor script
Edit the 4 variables below and paste this in your site's head*/
(function () {
// ===== CONFIGURATION =====
var R89_SCRIPT_URL = "https://tags.refinery89.com/yoursite.js";
var OTHER_SCRIPT_URL = "https://example.com/other-script.js"; // Replace with competitor URL
var COOKIE_DAYS = 30; // Days to keep user in same variant
var SPLIT = 0.5; // Percentage for R89 (0.5 = 50% each)
// ===== DO NOT EDIT BELOW =====
function _ab_getCookie(n) {
var m = document.cookie.match(new RegExp("(?:^|; )" + n + "=([^;]*)"));
return m ? decodeURIComponent(m[1]) : null;
}
function _ab_setCookie(n, v, d) {
var e = new Date(Date.now() + d * 864e5);
var f = "; SameSite=Lax" + (location.protocol === "https:" ? "; Secure" : "");
document.cookie = n + "=" + v + "; expires=" + e.toUTCString() + "; path=/" + f;
}
var _ab_v = _ab_getCookie("ab_variant"), _ab_e = _ab_getCookie("ab_exp");
var _ab_url = new URLSearchParams(location.search).get("ab_variant");
if (_ab_url === "r89" || _ab_url === "other") _ab_v = _ab_url;
if (!_ab_v || !_ab_e || Date.now() > parseInt(_ab_e)) {
_ab_v = Math.random() < SPLIT ? "r89" : "other";
_ab_setCookie("ab_variant", _ab_v, COOKIE_DAYS);
_ab_setCookie("ab_exp", String(Date.now() + COOKIE_DAYS * 864e5), COOKIE_DAYS);
}
if (document.querySelector('[data-ab-test]')) return;
var _ab_s = document.createElement("script");
_ab_s.async = true;
_ab_s.src = _ab_v === "r89" ? R89_SCRIPT_URL : OTHER_SCRIPT_URL;
_ab_s.setAttribute("data-ab-test", "true");
(document.head || document.getElementsByTagName("head")[0]).appendChild(_ab_s);
window.__AB_VARIANT__ = _ab_v;
})();
</script>
This script ensures user-level persistence via cookies, preventing provider switching during a session. This results in cleaner performance data and maximized revenue by maintaining a stable monetization environment for every visitor.
The methodology is applied as follows:
User A is monetized randomly by provider A or B
Example 1 – 50/50 Split
var SPLIT = 0.5; // 50% R89 / 50% alternative
- Traffic is evenly distributed between Refinery89 and the alternative setup.
- Recommended for balanced A/B testing and clear performance comparison.
Example 2 – 70/30 Split
var SPLIT = 0.7; // 70% R89 / 30% alternative
-
-
- Majority of traffic is routed to Refinery89.
- Useful for controlled rollouts or lower-risk testing.
-
During the whole session the User will be monetized through the same solution
2. Configuration Reference
| Variable | Description | Default / Example |
R89_SCRIPT_URL |
The unique Refinery89 tag for your specific site. | https://tags.refinery89.com/yourdomain.js |
OTHER_SCRIPT_URL |
The tag URL for the third-party solution/provider that is being tested | https://competitor.com/tag.js |
COOKIE_DAYS |
How long the user remains in an assigned group (A or B) | 30 (Recommended) |
SPLIT |
Decimal representing the probability of loading Refinery89 | 0.5 (50% Split) |