AdWords脚本无法找到价值

时间:2016-01-29 22:05:50

标签: javascript google-adwords

我有一个Google AdWords脚本,它会花费昨天的累计支出(已过滤)并将该值输入Google表格行。我所使用的逻辑已经过测试并且工作正常,但是当我尝试为不同的过滤条件复制逻辑时,为复制逻辑传回的值返回值为0.我相信问题必须要做使用我的.withCondition过滤器逻辑,但它对我来说是正确的。

Adwords脚本:

function main() {

  var sheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1kKPwvazsT9YOfL5swKRkjHYAdUtetetetetetet/edit#gid=0").getActiveSheet();

  var emptyRow = findEmptyRow(sheet);

  var yesterday = new Date(new Date()-1);

  var range = sheet.getRange(emptyRow + 1, 1, 1, 10);

  var row = range.getValues();


  var campaignIteratorPaidSearch = AdWordsApp.campaigns().withCondition("Name NOT_IN ['Remarketing', 'GSP', 'YouTube'] ").forDateRange('YESTERDAY').get();
  var campaignIteratorDisplay = AdWordsApp.campaigns().withCondition("Name IN ['Remarketing', 'GSP', 'YouTube'] ").forDateRange('YESTERDAY').get();


  var totalPaidSearchCost = 0;
  var totalDisplayCost = 0;

  var date = new Date(); 
   date.setDate(date.getDate() - 1);

  //Paid Search Spend
  while (campaignIteratorPaidSearch.hasNext()) {
   var campaignStats = campaignIteratorPaidSearch.next();
   var stats = campaignStats.getStatsFor('YESTERDAY');


   totalPaidSearchCost += stats.getCost(); 

  } 

  //Display Spend
  while (campaignIteratorDisplay.hasNext()) {
   var displayCampaignStats = campaignIteratorDisplay.next();
   var displayStats = displayCampaignStats.getStatsFor('YESTERDAY');

   totalDisplayCost += displayStats.getCost(); 

  }  

  row[0][0] = date; 
  row[0][1] = totalPaidSearchCost;
  row[0][2] = totalDisplayCost;

  range.setValues(row);


}

function findEmptyRow(sheet) {
 var dates = sheet.getRange(1, 1, 365, 1).getValues();
  for (var emptyDate = 0; emptyDate < dates.length; emptyDate++) {
    if (dates[emptyDate][0].length == 0) {
     return emptyDate;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

广告系列名称是一个字符串,因此您不能使用NOT_IN和IN运算符,您应该使用:

=  !=  STARTS_WITH  STARTS_WITH_IGNORE_CASE  CONTAINS  CONTAINS_IGNORE_CASE  DOES_NOT_CONTAIN  DOES_NOT_CONTAIN_IGNORE_CASE

https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_campaignselector#withCondition_1