預覽模式

在預覽模式下執行指令碼時,系統不會對實際的廣告活動資料進行任何變更。相反地,指令碼執行作業會顯示「如果」指令碼執行時所做的變更。一旦滿意輸出結果,即可開始執行或排程執行指令碼。

預覽模式是一項強大的功能,可讓您開發及偵錯指令碼,不必擔心會對 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());