预览模式

在预览模式下执行脚本时,脚本不会更改实际的广告系列数据。而是会显示如果脚本正在执行,将会进行的更改。对输出结果满意后,您可以开始实时执行脚本或安排脚本执行时间。

预览模式是一项强大的功能,可让您开发和调试脚本,而无需担心对 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());