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

时间:2016-01-27 18:28:20

标签: javascript google-apps-script google-adwords

我试图将昨天的广告系列支出和点击次数提取到我的Google表格中,但我当前的设置会返回" 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;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

点击次数:您没有在报告中添加“点击次数”字段。 TotalCost:该字段不存在,请检查Adwords页面中的可用字段:Panels Overview