这是我已经工作了一段时间的脚本,我认为它确实很有用。我希望你也这样做。
每个有价值的SEM经理都在不断进行创造性的测试。而且,由于您正在阅读此博客,因此许多人可能以某种方式使用脚本来简化此过程。但是,您如何确定测试何时开始?对于每个广告组,它们可能会有所不同。
我见过有些人使用标签,有些人使用时间表,但是我从不真正喜欢跟踪那些东西。因此,我创建了此脚本,该脚本将自动跟踪创意测试的开始日期。
我采用的方法是将您的广告ID副本存储在Google电子表格中。然后,它会对照电子表格中的广告检查广告组中的当前广告,并通过查看广告ID找出是否有所更改。如果已经存在,则脚本假定已开始新的测试,并相应地在电子表格中记录了日期。使用此方法,营销人员可以确保脚本正在比较适当时间范围内的统计信息以确定测试获胜者。
但是后来一位读者提到,他们希望能够选择度量标准来衡量广告,并希望使用阈值仅在广告组中获得一定点击次数后才开始进行衡量。因此,我也将该功能添加到了脚本中。您只需要在脚本顶部调整一些参数,即可使用功能齐全的广告素材测试脚本。
每当它通过暂停对广告采取行动时,结果都会通过电子邮件发送给您,以便您可以为该广告组创建新的挑战者广告。
我用这个脚本做了一些不同的事情。我一直很讨厌让我的读者进入Google文档,并为我的脚本创建一个空白电子表格以用作存储。因此,为了解决这个问题,此脚本将检查存储电子表格ID的帐户中是否存在特殊标签。如果找到一个,它将使用它。并且如果缺少它(如第一次运行),它将创建电子表格和标签。这样,脚本中不会出现混乱的电子表格网址。这是一个变通办法,但是直到Google允许我们为脚本存储其他配置数据之前,我认为这是处理此问题的一种好方法。
与往常一样,我们欢迎您反馈此脚本是否对您有用。您还通过哪些其他指标来判断广告效果?该脚本还缺少什么?
谢谢,
拉斯
/************************************
* 广告创意测试自动化脚本
* Version: 1.3
* Changelog v1.3 - Data is written to the 电子表格 a little faster
* Changelog v1.2 - Added 广告 ditional threshold options
* Changelog v1.1 - Fixed issue with 日期 in 电子邮件
* Created By: 拉斯 Savage
* FreeAdWordsScripts.com
************************************/
// You can use any of the same values here as you can for METRIC below
var THRESHOLD = { metric : 'Clicks', value : 100 };
var TO = ['[email protected]'];
//Try any of these values for METRIC:
//AverageCpc, AverageCpm, AveragePageviews, AveragePosition,
//AverageTimeOnSite, BounceRate, Clicks, ConversionRate,
//Conversions, Cost, Ctr, Impressions
var METRIC = 'Ctr';
var ASC_OR_DESC = 'ASC'; //ASC - 暂停广告 with lowest value, DESC - 暂停广告 with highest value
function main() {
//Start by finding what has changed in the account
var 广告 _map = buildCurrentAdMap();
var prev_ad_map = readMapFromSpreadsheet();
prev_ad_map = 更新PreviousAdMap(prev_ad_map,ad_map);
writeMapToSpreadsheet(prev_ad_map);
//Now run through the 广告群组 to find creative tests
var ag_iter = AdWordsApp.adGroups().get();
var 暂停d_ads = [];
while(ag_iter.hasNext()) {
var ag = ag_iter.next();
if(!prev_ad_map[ag.getId()]) { continue; }
//Here is the date range for the test metrics
var last_touched_str = _getDateString(prev_ad_map[ag.getId()].last_touched,'yyyyMMdd');
var get_today_str = _getDateString(new Date(),'yyyyMMdd');
var ag_stats = ag.getStatsFor(last_touched_str, get_today_str);
if(ag_stats['get'+THRESHOLD.metric]() >= THRESHOLD.value) {
var 广告 _iter = ag.ads().withCondition('Status = ENABLED')
.forDateRange(last_touched_str, get_today_str)
.orderBy(METRIC+" "+ASC_OR_DESC).get();
var 广告 = 广告 _iter.next();
var metric = 广告 .getStatsFor(last_touched_str, get_today_str)['get'+METRIC]();
ad.pause();
paused_ads.push({a : 广告 , m : metric});
}
}
sendEmailForPausedAds(paused_ads);
}
// A function to send an 电子邮件 with an 在tached report of 广告 it has 暂停d
function sendEmailForPausedAds(ads) {
if(ads.length == 0) { return; } //No 广告 暂停d, no 电子邮件
var 电子邮件_body = '"' + ['CampaignName','AdGroupName','Headline','Desc1','Desc2','DisplayUrl',METRIC].join('","') + '"\n';
for(var i in 广告) {
var 广告 = 广告[i].a;
var metric = 广告[i].m;
email_body += '"' + [ad.getCampaign().getName(),
ad.getAdGroup().getName(),
ad.getHeadline(),
ad.getDescription1(),
ad.getDescription2(),
ad.getDisplayUrl(),
metric
].join('","') +
'"\n';
}
var date_str = _getDateString(new Date(),'yyyy-MM-dd');
var options = { 附件: [Utilities.newBlob(email_body, 'text/csv', "FinishedTests_"+date_str+'.csv')] };
var subject = 'Finished Tests - ' + date_str;
for(var i in TO) {
MailApp.sendEmail(TO[i], subject, 'See 在tached.', options);
}
}
//Given two lists of 广告, this checks to make sure they are the same.
function sameAds(ads1,ads2) {
for(var i in 广告1) {
if(ads1[i] != 广告2[i]) { return false; }
}
return true;
}
//This reads the stored data from the 电子表格
function readMapFromSpreadsheet() {
var 广告 _map = {};
var sheet = SpreadsheetApp.openById(findSpreadsheetId()).getActiveSheet();
var data = sheet.getRange('A:C').getValues();
for(var i in data) {
if(data[i][0] == '') { break; }
var [ag_id,last_touched,ad_ids] = data[i];
ad_map[ag_id] = { 广告 _ids : (''+ad_ids).split(','), last_touched : new Date(last_touched) };
}
return 广告 _map;
}
//This will search for a 标签 containing the 电子表格 id
//If one isn't found, it will 创造 a new one and the 标签 as well
function findSpreadsheetId() {
var 电子表格_id = "";
var 标签_iter = AdWordsApp.labels().withCondition("Name STARTS_WITH 'history_script:'").get();
if(label_iter.hasNext()) {
var 标签 = 标签_iter.next();
return 标签.getName().split(':')[1];
} else {
var sheet = SpreadsheetApp.create('AdGroups History');
var sheet_id = sheet.getId();
AdWordsApp.createLabel('history_script:'+sheet_id, 'stores sheet id for 广告群组 changes script.');
return sheet_id;
}
}
//This will store the data from the account into a 电子表格
function writeMapToSpreadsheet(ad_map) {
var toWrite = [];
for(var ag_id in 广告 _map) {
var 广告 _ids = 广告 _map[ag_id].ad_ids;
var last_touched = 广告 _map[ag_id].last_touched;
toWrite.push([ag_id,last_touched,ad_ids.join(',')]);
}
writeToSpreadsheet(toWrite);
}
// Write the 关键词 data to the 电子表格
function writeToSpreadsheet(toWrite) {
var sheet = SpreadsheetApp.openById(findSpreadsheetId()).getActiveSheet();
sheet.clear();
var numRows = sheet.getMaxRows();
if(numRows < toWrite.length) {
sheet.insertRows(1,toWrite.length-numRows);
}
var range = sheet.getRange(1,1,toWrite.length,toWrite[0].length);
range.setValues(toWrite);
}
//This builds a map of the 广告 in the account so that it is easy to compare
function buildCurrentAdMap() {
var 广告 _map = {}; // { ag_id : { 广告 _ids : [ 广告 _id, ... ], last_touched : date } }
var 广告 _iter = AdWordsApp.ads().withCondition('Status = ENABLED').get();
while(ad_iter.hasNext()) {
var 广告 = 广告 _iter.next();
var ag_id = 广告 .getAdGroup().getId();
if(ad_map[ag_id]) {
ad_map[ag_id].ad_ids.push(ad.getId());
ad_map[ag_id].ad_ids.sort();
} else {
ad_map[ag_id] = { 广告 _ids : [ad.getId()], last_touched : new Date() };
}
}
return 广告 _map;
}
//This takes the old 广告 map and the current 广告 map and returns an
//updated map with all changes.
function 更新PreviousAdMap(prev_ad_map,ad_map) {
for(var ag_id in 广告 _map) {
var current_ads = 广告 _map[ag_id].ad_ids;
var previous_ads = (prev_ad_map[ag_id]) ? prev_ad_map[ag_id].ad_ids : [];
if(!sameAds(current_ads,previous_ads)) {
prev_ad_map[ag_id] = 广告 _map[ag_id];
}
}
return prev_ad_map;
}
//Helper function to format the date
function _getDateString(date,format) {
return Utilities.formatDate(date,AdWordsApp.currentAccount().getTimeZone(),format);
}