A/B Testing Script

This is a script to enable a scientific approach to your PPC strategy – whatever variable you want to measure, and with automated reports thrown in.

What’s included?

How does the script work?

You simply have two versions of your campaigns – the ‘Control’ and ‘Experiment’ – and the script alternately pauses and enables them every hour, so they get an even share of the traffic. The script then checks the performance to see if there’s a statistically significant difference, and emails you the result. It works on Search, Display and Shopping campaigns!

How do I use it?

Copy your existing campaigns twice. Label one set as ‘Control’ and leave it alone (even though these campaigns will be the same as the original we recommend making copies, so both sets of campaign start with no advantage from a built-up quality score). Label the other set ‘Experiment’ and do whatever you want to it.

Then copy and paste the script below into your account. Change the variables at the top:

  1. campaignLabelA and campaignLabelB are the names of the Control and Experiment labels you’ve just applied to your Search and Display campaigns. If you’re only experimenting with Shopping then have these both as “” so they are skipped.
  2. shoppingLabelA and shoppingLabelB are the same, but for Shopping campaigns. If you’re only experimenting with Search or Display then set these to “”.
  3. confidenceThreshold is used by the stats test – it’s how sure the test is that the sets of campaigns are performing differently. We recommend leaving it as 0.95.
  4. Either set the reportDate to a preset range, like “LAST_30_DAYS”, or change it to “” and set startDate to the day when you began the experiment. This determines how far the script looks back to get the performance of the test campaigns.
  5. emailRecipients is for the address to email when there are results. You can leave it blank if you want, but then you’ll have to manually check how your test is doing – you can do that with our free statistical relevance calculator

Then preview the script, to make sure it’s all working, and then create a schedule so that it runs hourly.

The A/B Testing script code