/************************************************* * Label By Performance - Raise Bids * @version: 1.0 * @author: Naman Jindal (nj.itprof@gmail.com ***************************************************/ var LABEL_NAME = 'RAISE BIDS'; var AVG_POSITION_WORSE_THAN = 2.5; var CPA_ABOVE = 2; var CONVERIONS_ABOVE = 5; var LAST_N_DAYS = 30; function main() { var DATE_FROM = getAdWordsFormattedDate(LAST_N_DAYS, 'yyyyMMdd'); var DATE_TO = getAdWordsFormattedDate(1, 'yyyyMMdd'); resetLabel(LABEL_NAME); var iter = AdWordsApp.keywords() .withCondition('Impressions > 0') .withCondition('AveragePosition > ' + AVG_POSITION_WORSE_THAN) .withCondition('Conversions > ' + CONVERIONS_ABOVE) .forDateRange(DATE_FROM, DATE_TO) .get(); while(iter.hasNext()) { var kw = iter.next(); var stats = kw.getStatsFor(DATE_FROM, DATE_TO); var cost = stats.getCost(); var conv = stats.getConversions(); var cpa = cost / conv; if(cpa <= CPA_ABOVE) { continue; } kw.applyLabel(LABEL_NAME); } } function resetLabel(name) { if(AdWordsApp.labels().withCondition('Name = "'+name+'"').get().hasNext()) { AdWordsApp.labels().withCondition('Name = "'+name+'"').get().next().remove(); } AdWordsApp.createLabel(name); } function getAdWordsFormattedDate(d, format){ var date = new Date(); date.setDate(date.getDate() - d); return Utilities.formatDate(date,AdWordsApp.currentAccount().getTimeZone(),format); }