대부분의 애셋 유형은 광고에 사용하기 전에 AssetService를 사용하여 만들어야 합니다.
TextAsset 유형은 광고를 만드는 동안 인라인으로 생성되므로 예외입니다. 다른 모든 유형은 먼저 광고주의 계정에 업로드해야 사용할 수 있습니다.
애셋 연결 수준
Google Ads 계정 계층 구조의 여러 항목에 확장 소재를 연결하면 확장 소재가 게재에 사용될 수 있습니다. 연결 수준은 애셋 유형과 캠페인 유형에 따라 다릅니다. 이러한 링크를 관리하는 데 사용되는 일반적인 리소스는 다음과 같습니다.
CustomerAsset: 계정 수준에서 연결된 확장 소재의 경우CampaignAsset: 특정 캠페인에 연결된 애셋의 경우AdGroupAsset: 특정 광고 그룹에 연결된 애셋의 경우AssetGroupAsset: 실적 최대화 캠페인 내 애셋 그룹에 연결된 애셋의 경우
사용할 구체적인 서비스와 리소스는 달성하려는 목표에 따라 달라집니다.
실적 최대화 캠페인 브랜드 애셋
실적 최대화 캠페인의 많은 애셋이 AssetGroupAsset를 사용하여 애셋 그룹에 연결되지만, 캠페인에 브랜드 가이드라인이 사용 설정된 경우 비즈니스 이름 및 비즈니스 로고 애셋은 예외입니다. 이 경우 필드 유형이 각각 BUSINESS_NAME 및 LOGO인 CampaignAsset를 사용하여 캠페인 수준에서 직접 연결됩니다. 캠페인에서 브랜드 가이드라인이 사용 중지된 경우 이러한 애셋은 AssetGroupAsset를 사용하여 연결해야 합니다. 자세한 내용은 실적 최대화 캠페인의 애셋을 참고하세요.
애셋 만들기
이미지 및 미디어 번들 확장 소재를 만들 때는 고유한 이름이 필요합니다. 기존 이름을 제공하면 기존 이름에 고유한 문자열을 추가하여 새 이름이 생성됩니다. 컬렉션이 늘어남에 따라 개별 애셋을 더 쉽게 관리하고 식별할 수 있도록 설명이 포함된 고유한 이름을 사용하는 것이 좋습니다.
다음 예에서는 원시 이미지 데이터의 URL에서 새 이미지 애셋을 만드는 방법을 보여줍니다.
자바
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; } }