変更戦略
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このガイドは、既存の P-MAX ガイドとまったく同じように作成されます。このガイドでは、各エンティティを個別のリクエストで 1 つずつ作成するのではなく、キャンペーン全体を 1 つのアトミック リクエストで作成することを前提としています。つまり、API レスポンスを取得するまで完全なリソース名がわからないため、リソースを相互にリンクするには一時 ID を使用する必要があります。
これを行うには、重複する一時 ID が作成されないように、コードを記述する必要があります。
let nextId = -1;
function getNextTempId() {
const ret = nextId;
nextId -= 1;
return ret;
}
getNextTempId
を呼び出すたびに、前回よりも 1 少ない数が返されます。すべての一時 ID は負の値にする必要があるため、-1 から開始します。
これで、すべてのオペレーションを保持する配列を作成できるようになりました。
const operations = [];
キャンペーンを作成するお客様のお客様 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 mutate のドキュメントで例をご覧ください。
すべてのオペレーションを構築したら、1 つのバッチで実行します。
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);"]]