/************************************************* * Label By Performance - Lower Bids * @version: 1.0.1 (non-functional) * @author: KlientBoost ***************************************************/ var LABEL_NAME = 'REDUCE BIDS'; var CPA_ABOVE = 300; var COST_ABOVE = 500; 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('Cost > ' + COST_ABOVE) .withCondition('CostPerConversion > ' + CPA_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); }