Asset creation and usage

  • Most asset types must be created using the AssetService before use in an ad, with TextAsset being the exception as it can be created inline during ad creation.

  • Once an asset is uploaded using AssetService, it cannot be changed or removed programmatically, and associations with ads must be managed through ad-level operations.

  • The API returns a MutateAssetResult containing the resource name of a newly created asset, which is used to reference the asset when creating asset-based ads.

  • Different ad and campaign types support specific asset types, and for most, existing assets are added by referencing their resource names.

  • Recommendations can suggest assets to add to campaigns or identify areas to update existing assets to improve ad strength.

Most asset types must be created using the AssetService before they can be used in an ad. The TextAsset type is the exception as it is created inline during ad creation. All other types must first be uploaded to an advertiser's account before they can be used.

Asset Association Levels

Assets are made available for serving by linking them to different entities in your Google Ads account hierarchy. The level of association depends on the asset type and the campaign type. Common resources for managing these links include:

The specific service and resource to use will depend on what you are trying to achieve.

Performance Max brand assets

While many assets in Performance Max campaigns are linked to asset groups using AssetGroupAsset, Business Name and Business Logo assets are an exception if brand guidelines are enabled for the campaign. In this case, they are linked directly at the campaign level using CampaignAsset with the field types BUSINESS_NAME and LOGO, respectively. If brand guidelines are disabled for the campaign, then these assets must be attached using AssetGroupAsset. See Assets in Performance Max for more details.

Create an asset

Unique names are required when creating image and media bundle assets. If you supply an existing name, a new name will be created by appending a unique string to the existing name. We strongly recommend that you use unique names that are descriptive to make it easier to manage and identify individual assets as your collection grows.

The following example shows how to create a new image asset from a URL of raw image data.

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;
    }
}