คุณต้องสร้างชิ้นงานประเภทส่วนใหญ่โดยใช้
AssetServiceก่อนจึงจะใช้ในโฆษณาได้
ประเภท TextAsset เป็นข้อยกเว้นเนื่องจากสร้างขึ้นในบรรทัดระหว่างการสร้างโฆษณา ส่วนครีเอทีฟโฆษณาประเภทอื่นๆ ทั้งหมดต้องอัปโหลดไปยังบัญชีของผู้ลงโฆษณาก่อนจึงจะใช้งานได้
ระดับการเชื่อมโยงชิ้นงาน
ระบบจะทำให้ชิ้นงานพร้อมแสดงโดยการลิงก์ชิ้นงานกับเอนทิตีต่างๆ ใน ลําดับชั้นบัญชี Google Ads ระดับการเชื่อมโยงจะขึ้นอยู่กับประเภทชิ้นงาน และประเภทแคมเปญ แหล่งข้อมูลทั่วไปสำหรับการจัดการลิงก์เหล่านี้ ได้แก่
CustomerAsset: สำหรับชิ้นงานที่ลิงก์ที่ระดับบัญชีCampaignAsset: สำหรับชิ้นงานที่ลิงก์กับแคมเปญที่เฉพาะเจาะจงAdGroupAsset: สำหรับชิ้นงานที่ลิงก์กับกลุ่มโฆษณาที่เฉพาะเจาะจงAssetGroupAsset: สําหรับชิ้นงานที่ลิงก์กับกลุ่มชิ้นงานภายในแคมเปญ Performance Max
บริการและทรัพยากรที่เฉพาะเจาะจงที่จะใช้จะขึ้นอยู่กับสิ่งที่คุณต้องการ ทำให้สำเร็จ
ชิ้นงานแบรนด์ของ Performance Max
แม้ว่าชิ้นงานจํานวนมากในแคมเปญ Performance Max จะลิงก์กับกลุ่มชิ้นงานโดยใช้AssetGroupAsset แต่ชิ้นงานชื่อธุรกิจและโลโก้ธุรกิจเป็นข้อยกเว้นหากเปิดใช้หลักเกณฑ์การใช้แบรนด์สําหรับแคมเปญ ในกรณีนี้
จะมีการลิงก์โดยตรงที่ระดับแคมเปญโดยใช้
CampaignAsset ที่มีฟิลด์
ประเภท BUSINESS_NAME และ LOGO ตามลำดับ หากปิดใช้หลักเกณฑ์การใช้แบรนด์สำหรับแคมเปญ คุณจะต้องแนบชิ้นงานเหล่านี้โดยใช้
AssetGroupAsset ดูรายละเอียดเพิ่มเติมได้ที่ชิ้นงานใน Performance Max
สร้างเนื้อหา
ต้องใช้ชื่อที่ไม่ซ้ำกันเมื่อสร้างชิ้นงานรูปภาพและชิ้นงานกลุ่มสื่อ หากคุณ ระบุชื่อที่มีอยู่ ระบบจะสร้างชื่อใหม่โดยต่อท้ายสตริงที่ไม่ซ้ำกัน กับชื่อที่มีอยู่ เราขอแนะนำอย่างยิ่งให้คุณใช้ชื่อที่ไม่ซ้ำกัน ซึ่งสื่อความหมายเพื่อให้จัดการและระบุชิ้นงานแต่ละรายการได้ง่ายขึ้น เมื่อคอลเล็กชันเติบโตขึ้น
ตัวอย่างต่อไปนี้แสดงวิธีสร้างชิ้นงานรูปภาพใหม่จาก URL ของข้อมูลรูปภาพดิบ
Java
private void runExample(GoogleAdsClient googleAdsClient, long customerId) throws IOException { byte[] imageData = ByteStreams.toByteArray(new URL(IMAGE_URL).openStream()); // Create the image asset. ImageAsset imageAsset = ImageAsset.newBuilder().setData(ByteString.copyFrom(imageData)).build(); // Creates an asset. Asset asset = Asset.newBuilder() // Provide a unique friendly name to identify your asset. // When there is an existing image asset with the same content but a different name, the // new name will be dropped silently. .setName("Marketing Image") .setType(AssetType.IMAGE) .setImageAsset(imageAsset) .build(); // Creates the operation. AssetOperation operation = AssetOperation.newBuilder().setCreate(asset).build(); // Creates the service client. try (AssetServiceClient assetServiceClient = googleAdsClient.getLatestVersion().createAssetServiceClient()) { // Issues a mutate request to add the asset. MutateAssetsResponse response = assetServiceClient.mutateAssets(Long.toString(customerId), ImmutableList.of(operation)); // Prints the result. System.out.printf( "The image asset with resource name '%s' was created.%n", response.getResults(0).getResourceName()); } }
C#
public void Run(GoogleAdsClient client, long customerId) { // Get the AssetServiceClient. AssetServiceClient assetService = client.GetService(Services.V22.AssetService); // Creates an image content. byte[] imageContent = MediaUtilities.GetAssetDataFromUrl(IMAGE_URL, client.Config); // Creates an image asset. ImageAsset imageAsset = new ImageAsset() { Data = ByteString.CopyFrom(imageContent), FileSize = imageContent.Length, MimeType = MimeType.ImageJpeg, FullSize = new ImageDimension() { HeightPixels = 315, WidthPixels = 600, Url = IMAGE_URL } }; // Creates an asset. Asset asset = new Asset() { // Optional: Provide a unique friendly name to identify your asset. // If you specify the name field, then both the asset name and the image being // uploaded should be unique, and should not match another ACTIVE asset in this // customer account. // Name = 'Jupiter Trip #' + ExampleUtilities.GetRandomString(), Type = AssetType.Image, ImageAsset = imageAsset, // Provide a unique friendly name to identify your asset. // When there is an existing image asset with the same content but a different // name, the new name will be dropped silently. Name = "Marketing Image" }; // Creates an asset operation. AssetOperation operation = new AssetOperation() { Create = asset }; try { // Issues a mutate request to add the asset. MutateAssetsResponse response = assetService.MutateAssets(customerId.ToString(), new[] { operation }); // Displays the result. Console.WriteLine($"Image asset with resource name: " + $"'{response.Results.First().ResourceName}' is created."); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId) { // Creates an image content. $imageContent = file_get_contents(self::IMAGE_URL); // Creates an asset. $asset = new Asset([ // Provide a unique friendly name to identify your asset. // When there is an existing image asset with the same content but a different // name, the new name will be dropped silently. 'name' => 'Marketing Image', 'type' => AssetType::IMAGE, 'image_asset' => new ImageAsset(['data' => $imageContent]) ]); // Creates an asset operation. $assetOperation = new AssetOperation(); $assetOperation->setCreate($asset); // Issues a mutate request to add the asset. $assetServiceClient = $googleAdsClient->getAssetServiceClient(); $response = $assetServiceClient->mutateAssets(MutateAssetsRequest::build( $customerId, [$assetOperation] )); if (!empty($response->getResults())) { // Prints the resource name of the added image asset. /** @var MutateAssetResult $addedImageAsset */ $addedImageAsset = $response->getResults()[0]; printf( "The image asset with resource name '%s' was created.%s", $addedImageAsset->getResourceName(), PHP_EOL ); } else { print 'No image asset was created.' . PHP_EOL; } }