错误和警告

Google Ads 脚本在执行时会尽其所能:它们会尝试对 Google Ads 数据进行更改,但如果某些更改没有成功,脚本会将其记录到更改日志中并继续执行:

// Attempt an invalid change.
let amount = 999999999999;
campaign.getBudget().setAmount(amount);
// Error is logged into Changes log, but the script keeps running.

// Suppose we must know whether the change actually happened.
if (campaign.getBudget() != amount) {
  // The current value of budget is not the one we expected.
  // The change must have failed.
}

输出类似错误的操作包括:

  • 设置的关键字出价高于广告系列预算。
  • 将广告系列名称设置为已存在的名称。
  • 在已达到广告组配额上限的广告系列中创建广告组。

不过,有些错误不能忽略。示例如下:

let keywords = AdsApp.keywords()
    .withCondition("metrics.clicks > 10")
    // Forgot forDateRange().
    .get();

使用此代码,由于未指定日期范围,该脚本无法生成有意义的 keywords 迭代器。因此,脚本执行将停止,并且文本日志中会记录一条错误消息。

如果超出quotas,脚本将记录警告。脚本执行仍会继续,但您应始终查看警告。

在执行日志中,错误为红色,警告为橙色。您还可以在这些日志中输出自定义消息,以便进行问题排查和监控。