预览模式

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

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