アセット
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
P-MAX キャンペーンを作成する前に、キャンペーンで使用する予定のアセットをすべてインポートすることが重要です。アセットは後でいつでも追加できますが、始めるにはアセットのセットが必要です。
キャンペーンの計画時に、P-MAX キャンペーンのアセットとアセットの要件についてご確認ください。
テキスト アセットと画像アセットは、主な必須アセットタイプであるため、このガイドでは、それぞれをアップロードする方法について説明します。これらの原則は、他のアセットタイプにも適用できます。作成するアセットの種類に関係なく、AssetOperation
を使用して作成します。
アセットは mutate を使用せずに AdsApp
を使用して作成できますが、一貫性を保つため、このガイドでは他のすべてのオペレーションと同じ方法で作成します。既存のアセットが利用可能な場合は、再利用できます。そのため、P-MAX キャンペーンを作成するにはアセットが必要ですが、キャンペーンの作成プロセスの一環としてアセットを作成する必要があるとは限りません。
テキスト アセット
テキスト アセットは、他のオペレーションと同じように機能します。キャンペーン作成プロセスの一環としてアセットをアップロードする場合は、一時 ID を使用します。それ以外の場合は、返されたリソース名をメモしておきます。これは、アセットをアセット グループに追加するために参照する必要がある場合に、将来のオペレーションで使用します。
const textAsset = {
"assetOperation": {
"create": {
"resourceName": `customers/${customerId}/assets/${getNextTempId()}`,
"textAsset": {
"text": "Travel the World"
}
}
}
}
operations.push(textAsset);
画像アセット
画像アセットは base-64 エンコード形式でアップロードされます。Google 広告スクリプトに画像を直接アップロードすることはできないため、画像データを取得してアップロード用にエンコードする方法は 2 つあります。
Google ドライブから画像を取得するには、まず画像の ID が必要です。これは、画像を一意に識別する最良の方法です。ID を取得する方法の 1 つは、Google ドライブの UI から共有可能なリンクをコピーして ID を抽出することです。一連のファイルをプログラムで取得し、アップロードするファイルを選択することもできます。このコードは、既知の ID を持つ単一の画像をアップロードする方法を示しています。
const file = DriveApp.getFileById(fileId);
const imageAsset = {
"assetOperation": {
"create": {
"resourceName": `customers/${customerId}/assets/${getNextTempId()}`,
"name": "Marketing Logo",
"type": "IMAGE",
"imageAsset": {
"data": Utilities.base64Encode(file.getBlob().getBytes())
}
}
}
}
または、UrlFetchApp
を使用して、ウェブサーバーでホストされている画像を URL で取得することもできます。
const file = UrlFetchApp.fetch(imageUrl);
このファイルに対して、Google ドライブ ファイルと同じように getBlob
を呼び出すことができます。そのため、オペレーションの構築は Google ドライブ ファイルの手順と同じになります。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-27 UTC。
[null,null,["最終更新日 2025-08-27 UTC。"],[[["\u003cp\u003eBefore creating a Performance Max campaign, ensure you have all necessary assets ready, such as text and images, or import them beforehand.\u003c/p\u003e\n"],["\u003cp\u003eFamiliarize yourself with Performance Max asset requirements and specifications detailed in the provided links.\u003c/p\u003e\n"],["\u003cp\u003eLeverage \u003ccode\u003eAssetOperation\u003c/code\u003e to create new assets or reuse existing ones within your campaign.\u003c/p\u003e\n"],["\u003cp\u003eUtilize Google Drive or web URLs to source images, converting them to base-64 encoding for upload as image assets.\u003c/p\u003e\n"],["\u003cp\u003eText assets can be easily integrated by defining their content during campaign setup or by referencing existing ones.\u003c/p\u003e\n"]]],[],null,["# Assets\n\nBefore creating a Performance Max campaign, it's important to import all of the\nassets you plan to use in the campaign. You can always come back and add assets\nlater, but you need a set of assets to even begin.\n\nRead up on [assets](/google-ads/api/performance-max/assets) and\n[asset requirements](/google-ads/api/performance-max/asset-requirements) for\nPerformance Max campaigns while planning your campaign.\n\nSince text assets and image assets are the primary required asset types, this\nguide will demonstrate how to upload each of these. These principles can be\nextended to other asset types as well. No matter what type of asset you're\nmaking, use [`AssetOperation`](/google-ads/api/reference/rpc/v21/AssetOperation) to create\nit.\n\nAssets can be created using the `AdsApp` without using mutate, but for the sake\nof consistency, this guide does it the same way as all the rest\nof the operations. Note that you can and should reuse existing assets if you\nalready have some available. So while it's required that you have assets to\ncreate a Performance Max campaign, it might not be strictly required that you\n*create* them as part of the campaign creation process.\n\nText assets\n-----------\n\nText assets work just like any other operation. If you're uploading assets as\npart of the campaign creation process, use a temp ID. Otherwise, make a note of\nthe returned resource name to use in a future operation when you need to\nreference the asset to add it to an asset group. \n\n const textAsset = {\n \"assetOperation\": {\n \"create\": {\n \"resourceName\": `customers/${customerId}/assets/${getNextTempId()}`,\n \"textAsset\": {\n \"text\": \"Travel the World\"\n }\n }\n }\n }\n operations.push(textAsset);\n\nImage assets\n------------\n\nImage assets are uploaded in a [base-64 encoded](//en.wikipedia.org/wiki/Base64)\nformat. Since you can't upload images directly into Google Ads scripts, you have a\nchoice of two different approaches for getting the image data and encoding it\nfor the upload.\n\nTo fetch an image from Google Drive, first you'll need its\n[ID](/apps-script/reference/drive/file#getId()), which is the best way to\nuniquely identify the image. One way to get the ID is to copy the shareable\nlink from the Google Drive UI and extract the ID. You can also fetch a series\nof files programmatically and select the ones you want to upload. This code\ndemonstrates how to upload a single image with a known ID: \n\n const file = DriveApp.getFileById(fileId);\n const imageAsset = {\n \"assetOperation\": {\n \"create\": {\n \"resourceName\": `customers/${customerId}/assets/${getNextTempId()}`,\n \"name\": \"Marketing Logo\",\n \"type\": \"IMAGE\",\n \"imageAsset\": {\n \"data\": Utilities.base64Encode(file.getBlob().getBytes())\n }\n }\n }\n }\n\nAlternatively, you can fetch an image hosted on a web server by its\nURL by using `UrlFetchApp`: \n\n const file = UrlFetchApp.fetch(imageUrl);\n\nYou can then call `getBlob` on this file just as you would with a Drive file,\nso the operation construction is identical to the steps for a Google Drive file."]]