เปลี่ยนแปลงกลยุทธ์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คู่มือนี้จะแสดงให้เห็นถึงการสร้างแคมเปญ Performance Max ที่มีอยู่
ซึ่งมีลักษณะคล้ายกันทุกประการ โดยจะถือว่าคุณสร้างทั้ง
แคมเปญในคำขอเดียว แทนที่จะสร้างแต่ละเอนทิตีทีละรายการในคำขอแยกกัน ซึ่งหมายความว่าคุณจะต้องใช้รหัสชั่วคราวเพื่อลิงก์
ทรัพยากรเข้าด้วยกัน เนื่องจากคุณจะไม่ทราบชื่อทรัพยากรแบบเต็มจนกว่าจะได้รับ
การตอบกลับจาก API
โดยคุณจะต้องเขียนโค้ดเพื่อให้แน่ใจว่าคุณจะไม่สร้างรหัสชั่วคราวที่ซ้ำกัน
let nextId = -1;
function getNextTempId() {
const ret = nextId;
nextId -= 1;
return ret;
}
การเรียกใช้ getNextTempId
แต่ละครั้งจะแสดงผลตัวเลขที่น้อยกว่าตัวเลขก่อนหน้าอยู่ 1 เนื่องจากรหัสชั่วคราวทั้งหมดต้องเป็นค่าลบ ให้เริ่มต้นที่ -1
เมื่อตั้งค่านี้แล้ว คุณจะสร้างอาร์เรย์เพื่อเก็บการดำเนินการทั้งหมดได้ดังนี้
const operations = [];
คุณจะต้องใช้รหัสลูกค้าสำหรับลูกค้าที่คุณสร้างแคมเปญบ่อยครั้ง เนื่องจากต้องระบุในชื่อทรัพยากรทุกชื่อ
const customerId = AdsApp.currentAccount().getCustomerId();
ทุกครั้งที่ต้องการสร้างการดำเนินการใหม่ คุณจะต้องใช้รหัสชั่วคราวถัดไปในชื่อทรัพยากร เพื่อให้คุณอ้างอิงออบเจ็กต์นี้ได้ในภายหลัง และแทรกออบเจ็กต์ที่สร้างลงในอาร์เรย์
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 mutate
เมื่อสร้างการดำเนินการทั้งหมดแล้ว ให้ดำเนินการในกลุ่มเดียว
AdsApp.mutateAll(operations);
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 2025-08-27 UTC"],[[["\u003cp\u003eThis 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.\u003c/p\u003e\n"],["\u003cp\u003eTo link resources within the single request, temporary IDs are utilized and assigned with a function ensuring unique negative values for each.\u003c/p\u003e\n"],["\u003cp\u003eThe guide involves constructing an array of operations, where each operation represents the creation of a specific campaign component.\u003c/p\u003e\n"],["\u003cp\u003eAfter 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 \u003ccode\u003eAdsApp.mutateAll(operations)\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Mutate Strategy\n\nThis guide will be presented to construct an exact analog to the existing\nPerformance Max guides, which assume that you will be creating the entire\ncampaign in a single atomic request, rather than creating each entity one at a\ntime in separate requests. This means that you'll need to use\n[temporary IDs](/google-ads/api/docs/batch-processing/temporary-ids) to link\nresources to each other, since you won't know the full resource names until you\nget the API response.\n\nTo do this, you'll have to write some code to ensure that you don't create any\nduplicate temp IDs: \n\n let nextId = -1;\n\n function getNextTempId() {\n const ret = nextId;\n nextId -= 1;\n return ret;\n }\n\nEach successive call to `getNextTempId` will return a number one less than the\nprevious. Since all temp IDs must be negative, start at -1.\n\nWith this in place, you can now create an array to hold all the operations: \n\n const operations = [];\n\nYou will frequently need the customer ID for the customer you're making the\ncampaign in, since it's required in every resource name. \n\n const customerId = AdsApp.currentAccount().getCustomerId();\n\nEach time you want to create a new operation, you will use the next temp ID in\nthe resource name, so that you can reference this object later, and insert the\nobject created into the array: \n\n const newOperation = {\n [OPERATION_TYPE_VARIES]: {\n create: {\n resourceName: `customers/${customerId}/[EXACT_PATH_VARIES]/${getNextTempId()}`\n // Other fields, relevant to the resource being created.\n }\n }\n }\n operations.push(newOperation);\n\nYou can read more and see an example operation on the\n[Google Ads API REST mutate documentation](/google-ads/api/rest/common/mutate).\n\nOnce you have constructed all of our operations, execute them in a single\nbatch: \n\n AdsApp.mutateAll(operations);"]]