Here’s An AdWords Script That Will Let You A/B Test Anything

AB-test-ss-1920

Any paid search manager will know that A/B testing is a critical part of AdWords success. Few other marketing channels offer such rich data on performance and allow for tweaks as wide-ranging as changing keywords to changing bids every hour of the day.

Yet for some reason, Google’s native testing platform, AdWords Campaign Experiments, is totally deficient. Aside from being clunky and difficult to use, there is the inherent problem that you must set up an experiment as a campaign setting, and therefore cannot test any campaign settings themselves.

At Brainlabs (my employer), we pride ourselves on scientific testing and needed a way around this. As every statistician knows, before/after analysis is weak. That is particularly true for AdWords, which is an auction where everything changes in a minute, let alone two weeks or a month. So we built an AdWords script which we’re sharing below to tackle this problem.

The logic behind the script is actually quite simple. You take a campaign and duplicate it twice. You label each one (I’d suggest “control” and “experiment”), add those labels to the script, and then run it on an hourly schedule.

The script works by alternating the campaigns on hourly schedules, so one goes on and the other goes off. They alternate all day for a few weeks until you’ve built up roughly even impressions on each. From there, you can visit the Dimensions tab, view Campaign Labels, and there you’ll have rich A/B data on your campaign performance.

Capture

[CLICK TO ENLARGE]

The caveat here is that the logic is not perfect on this script because it can only run every hour. If you’re feeling adventurous, then it’s possible to do this via the AdWords API and run more regular switching.

You’ll also notice that Google rarely serves each campaign evenly, which is partly down to Quality Score and partly down to chance.

/**
*
* Brainlabs A/B Testing Tool
*
* This script will pause and activate campaigns every hour.

*
* Version: 1.0
* AdWords script maintained on brainlabsdigital.com
*
**/

function main() {

var labelA = "Control";
var labelB = "Experiment";

var days = [31,28,31,30,31,30,31,31,30,31,30,31];

var date = new Date();
var timeZone = AdWordsApp.currentAccount().getTimeZone();
var month = parseInt(Utilities.formatDate(date, timeZone, "MM"), 10) - 1;
var dayOfMonth = parseInt(Utilities.formatDate(date, timeZone, "dd"), 10);
var hour = parseInt(Utilities.formatDate(date, timeZone, "HH"), 10);

var totalDays = 0;

for(var i = 0; i < month; i++){
totalDays += days[i];
}

totalDays += dayOfMonth;

Logger.log("Day of year: " + totalDays);

Logger.log("hour: " + hour);

if(totalDays % 2 === 0){
if(hour % 2 === 0){
EnableCampaigns(labelA)
PauseCampaigns(labelB)
}
else{
EnableCampaigns(labelB)
PauseCampaigns(labelA)
}
}
else{
if(hour % 2 === 0){
EnableCampaigns(labelB)
PauseCampaigns(labelA)
}
else{
EnableCampaigns(labelA)
PauseCampaigns(labelB)
}
}
}

function PauseCampaigns(label){
var campaignIterator = AdWordsApp.campaigns()
.withCondition("LabelNames CONTAINS_ANY ['" + label + "']")
.get();
while(campaignIterator.hasNext()){
var campaign = campaignIterator.next();
campaign.pause();
}
}

function EnableCampaigns(label){
var campaignIterator = AdWordsApp.campaigns()
.withCondition("LabelNames CONTAINS_ANY ['" + label + "']")
.get();
while(campaignIterator.hasNext()){
var campaign = campaignIterator.next();
campaign.enable();
}
}

The post Here’s An AdWords Script That Will Let You A/B Test Anything appeared first on Search Engine Land.