Hi. I am trying to figure out what is best way to point users to the branch of choice when split testing is running. For example for users that are coming from google ads?
Right now, I added a url param like “branch=branch-b” and added a script to the header of my index.html to check for branch
param. If exists, script sets nf_ab
cookie to param value. Next, I need to reload in order to fetch from the branch I want. However this is far from being perfect because page flash with master branch content and only after a moment re-loads with branch-b.
const urlParams = new URLSearchParams(window.location.search);
const branch = urlParams.get('branch');
if(branch) {
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
if(getCookie('nf_ab') !== branch) {
document.cookie=`nf_ab=${branch}`;
}
location.replace(document.location.origin);
}
Is there a way to force Netlify to load from branch-b at a first request? Some magic url param perhaps? Or is there something I am missing with my thinking?