在預覽模式下執行指令碼時,系統不會變更實際的廣告活動資料。而是顯示指令碼本來會進行的變更。確認輸出內容符合需求後,即可開始即時執行指令碼或排定執行時間。
預覽模式是一項強大的功能,可讓您開發及偵錯指令碼,不必擔心 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, this will log "false" since the keyword was not actually created.
// In real execution, this will log "true".
console.log("Are there keywords in the ad group? " + keywords.hasNext());