How to use Cookie Targeting to A/B Test Your Playbooks

If you are hoping to A/B test your Playbooks, we've created a script for you so that you can assign a cookie at random on every page load. 

All you need to do is use this script and put it right after the Drift Embed code and use Display targeting to target your Playbook by cookie. 

Let's go through this step by step: 

<script>

function getRandomInt(min, max) {

min = Math.ceil(min);

max = Math.floor(max);

return Math.floor(Math.random() * (max - min)) + min;

}

var random = getRandomInt(1,100);

if( random <= 50 ) {

document.cookie = "DriftPlaybook=A"

} else {

document.cookie = "DriftPlaybook=B"

}

</script>

This script will assign the A/B cookies at random for every page load. 

      You will need to create your playbook in Drift:
      Once you select the playbook, go into the Targeting section under "Display Conditions".
      From there, you'll want to select the "Website Behavior" condition. From the dropdown menu, choose "Cookie". And then Add "DriftPlaybook=A" as your cookie.

    And there you have it! You can now do A/B testing with Cookies using this set up. Let us know how it goes! 


    Did this help answer your question?

    👍
    👍

    Thanks for the feedback! 🙏🏽


    Help by drift