استراتژی جهش
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این راهنما برای ساختن یک آنالوگ دقیق با راهنماهای Performance Max موجود ارائه میشود، که فرض میکند شما کل کمپین را در یک درخواست اتمی ایجاد میکنید، نه اینکه هر موجودیت را در یک زمان در درخواستهای جداگانه ایجاد کنید. این بدان معناست که شما باید از شناسههای موقت برای پیوند دادن منابع به یکدیگر استفاده کنید، زیرا تا زمانی که پاسخ API را دریافت نکنید، نام کامل منابع را نمیدانید.
برای انجام این کار، باید کدی بنویسید تا مطمئن شوید که هیچ شناسه موقت تکراری ایجاد نمی کنید:
let nextId = -1;
function getNextTempId() {
const ret = nextId;
nextId -= 1;
return ret;
}
هر تماس متوالی به getNextTempId
یک عدد کمتر از قبلی را برمی گرداند. از آنجایی که همه شناسه های دمایی باید منفی باشند، از 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 ببینید.
هنگامی که تمام عملیات ما را ساختید، آنها را در یک دسته اجرا کنید:
AdsApp.mutateAll(operations);
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-26 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-26 بهوقت ساعت هماهنگ جهانی."],[[["\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);"]]