Share your feedback about the Google Ads (AdWords) API. Take the 2021 AdWords API and Google Ads API Annual Survey.

Dynamic remarketing with assets

Historically, campaigns have used Feeds for dynamic remarketing. We are in the process of removing support for feeds.

Dynamic remarketing enables your campaign to serve ads tailored to a user's past behaviour. When a user is added to a dynamic remarketing list, the ID of an asset is also provided in the tracking pixel. When a user from the list sees an ad, the content for the ad is dynamically rendered from the underlying AssetSet.

This document describes the process for managing dynamic remarketing campaigns with assets for dynamic content.

Create assets to serve in your dynamic remarketing campaign

You can use the API to manage assets that contain the custom content for your ad. The Asset contains an ID which can be used in the tracking pixel, together with the customized content to serve in the ad.

Java

// Creates a DynamicEducationAsset.
// See https://support.google.com/google-ads/answer/6053288?#zippy=%2Ceducation for a
// detailed explanation of the field format.
DynamicEducationAsset educationAsset =
    DynamicEducationAsset.newBuilder()
        // Defines meta-information about the school and program.
        .setSchoolName("The University of Unknown")
        .setAddress("Building 1, New York, 12345, USA")
        .setProgramName("BSc. Computer Science")
        .setSubject("Computer Science")
        .setProgramDescription("Slinging code for fun and profit!")
        // Sets up the program ID which is the ID that should be specified in the tracking
        // pixel.
        .setProgramId("bsc-cs-uofu")
        // Sets up the location ID which may additionally be specified in the tracking pixel.
        .setLocationId("nyc")
        .setImageUrl("https://gaagl.page.link/Eit5")
        .setAndroidAppLink("android-app://com.example.android/http/example.com/gizmos?1234")
        .setIosAppLink("exampleApp://content/page")
        .setIosAppStoreId(123L)
        .build();
Asset asset = Asset.newBuilder().setDynamicEducationAsset(educationAsset).build();
// Creates an operation to add the asset.
AssetOperation operation = AssetOperation.newBuilder().setCreate(asset).build();
// Connects to the API.
try (AssetServiceClient client =
    googleAdsClient.getLatestVersion().createAssetServiceClient()) {
  // Sends the mutate request.
  MutateAssetsResponse response =
      client.mutateAssets(String.valueOf(params.customerId), ImmutableList.of(operation));
  // Prints some information about the response.
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created a dynamic education asset with resource name %s.%n", resourceName);
  return resourceName;
}
      

C#

This example is not yet available in C#; you can take a look at the other languages.
    

PHP

This example is not yet available in PHP; you can take a look at the other languages.
    

Python

This example is not yet available in Python; you can take a look at the other languages.
    

Ruby

This example is not yet available in Ruby; you can take a look at the other languages.
    

Perl

This example is not yet available in Perl; you can take a look at the other languages.
    

Package assets together into an AssetSet

An AssetSet represents the collection of Asset objects which can be used for dynamic remarketing in a particular campaign. An AssetSet can be associated with many campaigns that can reuse the same group of Assets as required. This is similar to how the Google Ads UI lets you specify the "data feed" for a dynamic remarketing campaign.

Asset Set in UI

The first step is to create a new AssetSet to house your assets.

Java

// Creates an AssetSet which will be used to link the dynamic remarketing assets to a campaign.
AssetSet assetSet =
    AssetSet.newBuilder()
        .setName("My dynamic remarketing assets " + CodeSampleHelper.getPrintableDateTime())
        .setType(AssetSetType.DYNAMIC_EDUCATION)
        .build();
// Creates an operation to add the link.
AssetSetOperation operation = AssetSetOperation.newBuilder().setCreate(assetSet).build();
try (AssetSetServiceClient serviceClient =
    googleAdsClient.getLatestVersion().createAssetSetServiceClient()) {
  // Sends the mutate request.
  MutateAssetSetsResponse response =
      serviceClient.mutateAssetSets(
          String.valueOf(params.customerId), ImmutableList.of(operation));
  // Prints some information about the response.
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created asset set with resource name %s.%n", resourceName);
  return resourceName;
}
      

C#

This example is not yet available in C#; you can take a look at the other languages.
    

PHP

This example is not yet available in PHP; you can take a look at the other languages.
    

Python

This example is not yet available in Python; you can take a look at the other languages.
    

Ruby

This example is not yet available in Ruby; you can take a look at the other languages.
    

Perl

This example is not yet available in Perl; you can take a look at the other languages.
    

Next, associate assets to the AssetSet with an AssetSetAsset.

Java

AssetSetAsset assetSetAsset =
    AssetSetAsset.newBuilder()
        .setAsset(assetResourceName)
        .setAssetSet(assetSetResourceName)
        .build();
// Creates an operation to add the link.
AssetSetAssetOperation operation =
    AssetSetAssetOperation.newBuilder().setCreate(assetSetAsset).build();
try (AssetSetAssetServiceClient client =
    googleAdsClient.getLatestVersion().createAssetSetAssetServiceClient()) {
  // Sends the mutate request.
  // Note this is the point that the API will enforce uniqueness of the
  // DynamicEducationAsset.product_id field. You can have any number of assets with the same
  // product_id, however, only one Asset is allowed per AssetSet with the same product ID.
  MutateAssetSetAssetsResponse response =
      client.mutateAssetSetAssets(
          String.valueOf(params.customerId), ImmutableList.of(operation));
  // Prints some information about the response.
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created AssetSetAsset link with resource name %s.%n", resourceName);
}
      

C#

This example is not yet available in C#; you can take a look at the other languages.
    

PHP

This example is not yet available in PHP; you can take a look at the other languages.
    

Python

This example is not yet available in Python; you can take a look at the other languages.
    

Ruby

This example is not yet available in Ruby; you can take a look at the other languages.
    

Perl

This example is not yet available in Perl; you can take a look at the other languages.
    

Now that you have an AssetSet containing your dynamic content, you're ready to link it to a campaign so that the assets can start serving. This is achieved by creating a CampaignAssetSet.

Java

// Creates a CampaignAssetSet representing the link between an AssetSet and a Campaign.
CampaignAssetSet campaignAssetSet =
    CampaignAssetSet.newBuilder()
        .setCampaign(ResourceNames.campaign(params.customerId, params.campaignId))
        .setAssetSet(assetSetResourceName)
        .build();
// Creates an operation to add the CampaignAssetSet.
CampaignAssetSetOperation operation =
    CampaignAssetSetOperation.newBuilder().setCreate(campaignAssetSet).build();
// Creates an API connection.
try (CampaignAssetSetServiceClient client =
    googleAdsClient.getLatestVersion().createCampaignAssetSetServiceClient()) {
  // Issues the mutate request.
  MutateCampaignAssetSetsResponse response = client
      .mutateCampaignAssetSets(
          String.valueOf(params.customerId), ImmutableList.of(operation));
  String resourceName = response.getResults(0).getResourceName();
  System.out.printf("Created a CampaignAssetSet with resource name %s.%n", resourceName);
}
      

C#

This example is not yet available in C#; you can take a look at the other languages.
    

PHP

This example is not yet available in PHP; you can take a look at the other languages.
    

Python

This example is not yet available in Python; you can take a look at the other languages.
    

Ruby

This example is not yet available in Ruby; you can take a look at the other languages.
    

Perl

This example is not yet available in Perl; you can take a look at the other languages.
    

Target a UserList

Once you've set up your campaign with a dynamic remarketing feed, you can target it with a UserList. This user list should have been created with the dynamic IDs populated in the tracking pixel.

Java

private void attachUserList(
    GoogleAdsClient googleAdsClient,
    long customerId,
    String adGroupResourceName,
    long userListId) {
  String userListResourceName = ResourceNames.userList(customerId, userListId);
  // Creates the ad group criterion that targets the user list.
  AdGroupCriterion adGroupCriterion =
      AdGroupCriterion.newBuilder()
          .setAdGroup(adGroupResourceName)
          .setUserList(UserListInfo.newBuilder().setUserList(userListResourceName).build())
          .build();

  // Creates the ad group criterion operation.
  AdGroupCriterionOperation operation =
      AdGroupCriterionOperation.newBuilder().setCreate(adGroupCriterion).build();

  // Creates the ad group criterion service client.
  try (AdGroupCriterionServiceClient adGroupCriterionServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) {
    // Adds the ad group criterion.
    MutateAdGroupCriteriaResponse response =
        adGroupCriterionServiceClient.mutateAdGroupCriteria(
            Long.toString(customerId), ImmutableList.of(operation));
    System.out.printf(
        "Created ad group criterion with resource name '%s'.%n",
        response.getResults(0).getResourceName());
  }
}
      

C#

private void AttachUserList(GoogleAdsClient client, long customerId,
    string adGroupResourceName, long userListId)
{
    // Creates the ad group criterion service client.
    AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService
        (Services.V9.AdGroupCriterionService);

    string userListResourceName = ResourceNames.UserList(customerId, userListId);

    // Creates the ad group criterion that targets the user list.
    AdGroupCriterion adGroupCriterion = new AdGroupCriterion()
    {
        AdGroup = adGroupResourceName,
        UserList = new UserListInfo()
        {
            UserList = userListResourceName
        }
    };

    // Creates the ad group criterion operation.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation()
    {
        Create = adGroupCriterion
    };

    // Adds the ad group criterion.
    MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient
        .MutateAdGroupCriteria(customerId.ToString(), new[] { operation });
    Console.WriteLine("Created ad group criterion with resource name " +
                      $"'{response.Results.First().ResourceName}'.");
}
      

PHP

private static function attachUserList(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $adGroupResourceName,
    int $userListId
) {
    // Creates the ad group criterion that targets the user list.
    $adGroupCriterion = new AdGroupCriterion([
        'ad_group' => $adGroupResourceName,
        'user_list' => new UserListInfo([
            'user_list' => ResourceNames::forUserList($customerId, $userListId)
        ])
    ]);

    // Creates an ad group criterion operation.
    $adGroupCriterionOperation = new AdGroupCriterionOperation();
    $adGroupCriterionOperation->setCreate($adGroupCriterion);

    // Issues a mutate request to add the ad group criterion.
    $adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient();
    $response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
        $customerId,
        [$adGroupCriterionOperation]
    );

    /** @var AdGroupCriterion $addedAdGroupCriterion */
    $addedAdGroupCriterion = $response->getResults()[0];
    printf(
        "Created ad group criterion with resource name '%s'.%s",
        $addedAdGroupCriterion->getResourceName(),
        PHP_EOL
    );
}
      

Python

def _attach_user_list(
    client, customer_id, ad_group_resource_name, user_list_id
):
    """Targets a user list with an ad group.

    Args:
        client: An initialized GoogleAds client.
        customer_id: The Google Ads customer ID.
        ad_group_resource_name: The resource name of the target ad group.
        user_list_id: The ID of the user list to target for remarketing.
    """
    # Get the AdGroupCriterionService client.
    ad_group_criterion_service = client.get_service("AdGroupCriterionService")

    # Create an ad group criterion operation and set the ad group criterion
    # values.
    ad_group_criterion_operation = client.get_type("AdGroupCriterionOperation")
    ad_group_criterion = ad_group_criterion_operation.create
    ad_group_criterion.ad_group = ad_group_resource_name
    ad_group_criterion.user_list.user_list = client.get_service(
        "UserListService"
    ).user_list_path(customer_id, user_list_id)

    # Issue a mutate request to add the ad group criterion.
    ad_group_criterion_response = (
        ad_group_criterion_service.mutate_ad_group_criteria(
            customer_id=customer_id, operations=[ad_group_criterion_operation]
        )
    )
    print(
        "Created ad group criterion with resource name "
        f"'{ad_group_criterion_response.results[0].resource_name}'."
    )
      

Ruby

def attach_user_list(client, customer_id, ad_group_resource_name, user_list_id)
  user_list_resource_name = client.path.user_list(customer_id, user_list_id)

  # Creates the ad group criterion that targets the user list.
  ad_group_criterion = client.resource.ad_group_criterion do |agc|
    agc.ad_group = ad_group_resource_name
    agc.user_list = client.resource.user_list_info do |ul|
      ul.user_list = user_list_resource_name
    end
  end

  # Creates the ad group criterion operation.
  op = client.operation.create_resource.ad_group_criterion(ad_group_criterion)

  response = client.service.ad_group_criterion.mutate_ad_group_criteria(
    customer_id: customer_id,
    operations: [op]
  )

  puts "Created ad group criterion: #{response.results.first.resource_name}"
end
      

Perl

sub attach_user_list {
  my ($api_client, $customer_id, $ad_group_resource_name, $user_list_id) = @_;

  # Create the ad group criterion that targets the user list.
  my $ad_group_criterion =
    Google::Ads::GoogleAds::V9::Resources::AdGroupCriterion->new({
      adGroup  => $ad_group_resource_name,
      userList => Google::Ads::GoogleAds::V9::Common::UserListInfo->new({
          userList =>
            Google::Ads::GoogleAds::V9::Utils::ResourceNames::user_list(
            $customer_id, $user_list_id
            )})});

  # Create an ad group criterion operation.
  my $ad_group_criterion_operation =
    Google::Ads::GoogleAds::V9::Services::AdGroupCriterionService::AdGroupCriterionOperation
    ->new({create => $ad_group_criterion});

  # Issue a mutate request to add the ad group criterion.
  my $ad_group_criteria_response =
    $api_client->AdGroupCriterionService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_criterion_operation]});

  printf "Created ad group criterion with resource name '%s'.\n",
    $ad_group_criteria_response->{results}[0]{resourceName};
}
      

Download reports for your dynamic remarketing campaign

Currently there is no reporting available for assets in dynamic remarketing campaigns in order to maintain feature parity with the legacy feeds-based setup, which had no FeedItem-level stats. We may add reporting for dynamic remarketing assets in the future.

Specify asset tracking IDs

There are at least two IDs present in each dynamic remarketing asset. Each dynamic remarketing asset type defines its own unique ID.

For example, in the case of DynamicEducationAsset, you should specify the dynamic_education_asset.program_id and optionally dynamic_education_asset.location_id in the tracking pixel.

Do not specify asset.id in the tracking pixel as this has no meaning outside of the Google Ads API.