AdWords 脚本提取广告系列数据报告

AdWords Script Pulling Campaign Data Report

我正在尝试将昨天的广告系列总支出和点击量提取到我的 Google 表格中,但我当前的设置 returns "undefined" 用于我的 "Clicks" 列,0 用于我的 "TotalCost" 专栏。当我在帐户级别提取此数据时,我的设置没有问题,但是当我切换到广告系列级别时,我 运行 遇到了这些问题。关于我在哪里错误地提取数据的想法?

function main() {
  var sheet = SpreadsheetApp.openByUrl(
    "https://docs.google.com/spreadsheets/d/tttttt").getActiveSheet();
  var emptyRow = findEmptyRow(sheet);

  var yesterday = new Date(new Date().getTime() - (24 * 3600 * 1000));

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

  var row = range.getValues();
  row[0][0] = yesterday;

  var stats = AdWordsApp.report('SELECT CampaignName, ExternalCustomerId, TotalCost, Amount, BiddingStrategyId, Impressions ' +
    'FROM CAMPAIGN_PERFORMANCE_REPORT DURING YESTERDAY'

    )
    .rows()
    .next();
  row[0][1] = stats["Clicks"];
  row[0][2] = stats["TotalCost"];


  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;
    }
  }
}

点击次数:您没有将 'Clicks' 字段添加到报告中。 TotalCost:该字段不存在,请检查 Adwords 页面中的可用字段:https://developers.google.com/adwords/api/docs/appendix/reports/campaign-performance-report