All /
How to add test variation data to a form submission.
You may want to have your test data available in form submissions.
Check the video walkthrough, and grab the JS snippet below.
You can add JS anywhere you normally do, make sure its running on the page that you have your form. If you haven’t added custom JavaScript before, here’s how you add JavaScript to your site
const testID = 1234; // change to your test ID
const formFieldSelector = '#mysecretinput'; // change to your input # for ID . for class
function updateFields() {
const cookie = abstGetCookie('btab_' + testID);
if (!cookie) return;
try {
const variation = JSON.parse(cookie).variation;
let elements = document.querySelectorAll(formFieldSelector);
// checks if element is an input if if the input is inside the element given
elements.forEach(el => {
if (el.tagName.toLowerCase() === 'input') {
el.value = variation; // value added to input
} else {
const nestedInputs = el.querySelectorAll('input');
nestedInputs.forEach(input => input.value = variation);
}
});
} catch (e) {
console.error('Could not parse variation cookie:', e);
}
}
// Run update whenever *any input* on the page gains focus, change this to be less sensitive however you like
document.addEventListener('focusin', (e) => {
if (e.target.tagName.toLowerCase() === 'input') {
updateFields();
}
});
September 2, 2025 / /