預覽模式

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

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