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

by Sara Pion

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: 

  • First, you'll want to add this script to your website in the header, right next to the Drift embed code: 
<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. 

  • Then, select your Playbook in Drift


  • In your Targeting Section, add a new Display Condition or edit your existing condition: 
  • 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! 


Was this article helpful?