预览模式

当脚本在预览模式下执行时,它们不会更改实际的广告系列数据。相反,脚本执行会显示该脚本执行后应该发生的更改。如果您对输出结果感到满意,就可以开始实时执行脚本或安排脚本执行时间。

预览模式是一项非常强大的功能,它使您可以开发和调试脚本,而不必担心对 Google Ads 数据进行错误更改。

预览模式只会影响使用 AdsApp 作为入口点的调用。对其他服务的调用将照常进行。例如,如果某个脚本使用 MailApp 发送电子邮件,则无论该脚本是否已预览或执行,系统都会发送该脚本。在这两种情况下,电子表格也会更新。脚本可通过其执行信息了解其是否正在预览模式下运行。

以下代码段在预览模式下不会按预期运行:

// Suppose the ad group has no keywords.
let adGroup = findAnEmptyAdGroup();

// Create a keyword.
adGroup.createKeyword("test");

// Fetch all keywords in the ad group.
let keywords = adGroup.keywords().get();

// In preview mode, will log "false": keyword was not actually created.
// In real execution, will log "true".
console.log("Are there keywords in the ad group? " + keywords.hasNext());