素材資源
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
建立最高成效廣告活動前,請務必先匯入您打算在廣告活動中使用的所有素材資源。您隨時可以返回並稍後新增素材資源,但您需要一組素材資源才能開始。
規劃廣告活動時,請詳閱最高成效廣告活動的素材資源和素材資源規定。
由於文字素材資源和圖片素材資源是主要必備的素材資源類型,本指南將示範如何上傳這兩種素材資源。這些原則也適用於其他素材資源類型。無論要製作哪種素材資源,請使用 AssetOperation
建立。
您可以使用 AdsApp
建立資產,而不必使用 mutate,但為了保持一致性,本指南會採用與其他作業相同的方式。請注意,如果已有可用的素材資源,可以且應該重複使用。因此,雖然建立最高成效廣告活動時必須提供素材資源,但您可能不一定需要建立素材資源,才能完成廣告活動建立程序。
文字素材資源
文字素材資源的運作方式與任何其他作業相同。如果您在建立廣告活動時上傳素材資源,請使用臨時 ID。否則,請記下傳回的資源名稱,以便在日後需要參照素材資源並將其加入素材資源群組時使用。
const textAsset = {
"assetOperation": {
"create": {
"resourceName": `customers/${customerId}/assets/${getNextTempId()}`,
"textAsset": {
"text": "Travel the World"
}
}
}
}
operations.push(textAsset);
圖片素材資源
圖片素材資源會以 Base64 編碼格式上傳。由於您無法直接將圖片上傳至 Google Ads 指令碼,因此有兩種不同的方法可取得圖片資料並編碼,以供上傳。
如要從 Google 雲端硬碟擷取圖片,請先取得圖片的 ID,這是唯一識別圖片的最佳方式。如要取得 ID,可以從 Google 雲端硬碟使用者介面複製共用連結,然後擷取 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
,透過網址擷取網路伺服器代管的圖片:
const file = UrlFetchApp.fetch(imageUrl);
接著,您就可以像處理雲端硬碟檔案一樣,對這個檔案呼叫 getBlob
,因此作業建構步驟與 Google 雲端硬碟檔案相同。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[[["\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."]]