更改策略
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南將提供與現有最高成效廣告活動指南完全相同的建構方式,這類指南假設您會在單一原子要求中建立整個廣告活動,而不是在個別要求中逐一建立每個實體。也就是說,您必須使用臨時 ID 將資源彼此連結,因為您必須先取得 API 回應,才能知道完整的資源名稱。
為此,您必須編寫一些程式碼,確保不會建立任何重複的臨時 ID:
let nextId = -1;
function getNextTempId() {
const ret = nextId;
nextId -= 1;
return ret;
}
每次對 getNextTempId
的後續呼叫都會傳回比前一個呼叫少一個的數字。由於所有暫時 ID 都必須為負數,請從 -1 開始。
完成上述設定後,您現在可以建立陣列來儲存所有作業:
const operations = [];
您經常需要建立廣告活動的客戶客戶 ID,因為每個資源名稱都需要此 ID。
const customerId = AdsApp.currentAccount().getCustomerId();
每次建立新作業時,您都會在資源名稱中使用下一個暫時 ID,以便日後參照此物件,並將建立的物件插入陣列:
const newOperation = {
[OPERATION_TYPE_VARIES]: {
create: {
resourceName: `customers/${customerId}/[EXACT_PATH_VARIES]/${getNextTempId()}`
// Other fields, relevant to the resource being created.
}
}
}
operations.push(newOperation);
如要進一步瞭解相關資訊,並查看操作範例,請參閱 Google Ads API REST 變異作業說明文件。
建構所有作業後,請在單一批次中執行這些作業:
AdsApp.mutateAll(operations);
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-04 (世界標準時間)。"],[[["This guide provides instructions on creating Google Ads Performance Max campaigns using the Google Ads API with a single atomic request, as opposed to creating each entity individually."],["To link resources within the single request, temporary IDs are utilized and assigned with a function ensuring unique negative values for each."],["The guide involves constructing an array of operations, where each operation represents the creation of a specific campaign component."],["After defining all campaign elements and their relationships through the operations array, the entire campaign structure is created by executing a single batch mutation request via `AdsApp.mutateAll(operations)`."]]],[]]