You can easily set up A/B testing and measure conversion rates by using our mazingSetAB() method.
Simply add the following code block at the beginning of your integration file:
await waitForMazingFunction; // Wait till mazing cdn method is available
// Write a method which waits for certain elements and replace
// the selector with you own add to cart button selector
await waitForElement('.buy-buttons button[type="submit"]');
mazingSetAB({
enabled: true, // Set this boolean to "false" if you want to deactivate the A/B Test
addToCartListeners: (callback) => {
// Replace selector with your actual add to cart button selector
document.querySelector('.buy-buttons button[type="submit"]').addEventListener('click', () => {
console.log('MAZING: addToCartClicked A/B');
callback();
});
return true;
}
});
What's happening?
await waitForMazingFunction
This method waits until the Mazing function from the CDN is fully loaded and available.
Hereโs an example of how you can use it:
This method waits until a specific element (e.g., the "Add to Cart" button) is fully loaded and available in the DOM.
You pass a CSS selector as an argument. Hereโs an example:
Each time a customer visits your shop, they will be randomly assigned to either Group A (with the Mazing script integration) or Group B (without the integration).
We track how many users click the โAdd to Cartโ button in each group and compare the results to calculate the conversion rate.
If you're interested in accessing the results, feel free to contact the Mazing team!
Don't forget to replace the add to cart selector with your actual selector!