Google Ads API is returning to beta status. Please read our blog post for more details.

Creating Responsive Display Ads

As with other ads, ad creation is accomplished using AdGroupAdService.MutateAdGroupAds.

To create a responsive display ad, you need to populate the following required fields of ResponsiveDisplayAdInfo:

  • marketing_images
  • square_marketing_images
  • headlines
  • long_headline
  • descriptions
  • business name

All other fields and images' specifications can be found in the reference page and the Help Center article.

PHP

private static function createResponsiveDisplayAd(
    GoogleAdsClient $googleAdsClient,
    int $customerId,
    string $adGroupResourceName,
    string $marketingImageAssetResourceName = null,
    string $squareMarketingImageAssetResourceName = null
) {
    // Creates a new image asset for marketing image and square marketing image if there are no
    // assets' resource names specified.
    $marketingImageAssetResourceName = $marketingImageAssetResourceName ?:
        self::createImageAsset(
            $googleAdsClient,
            $customerId,
            self::MARKETING_IMAGE_URL,
            'Marketing Image'
        );
    $squareMarketingImageAssetResourceName = $squareMarketingImageAssetResourceName ?:
        self::createImageAsset(
            $googleAdsClient,
            $customerId,
            self::SQUARE_MARKETING_IMAGE_URL,
            'Square Marketing Image'
        );

    // Creates a responsive display ad info.
    $responsiveDisplayAdInfo = new ResponsiveDisplayAdInfo([
        // Sets some basic required information for the responsive display ad.
        'headlines' => [new AdTextAsset(['text' => new StringValue(['value' => 'Travel'])])],
        'long_headline' => new AdTextAsset([
            'text' => new StringValue(['value' => 'Travel the World'])
        ]),
        'descriptions' => [
            new AdTextAsset(['text' => new StringValue(['value' => 'Take to the air!'])])
        ],
        'business_name' => new StringValue(['value' => 'Google']),
        // Sets the marketing image and square marketing image to the previously created
        // image assets.
        'marketing_images' => [
            new AdImageAsset([
                'asset' => new StringValue(['value' => $marketingImageAssetResourceName])
            ])
        ],
        'square_marketing_images' => [
            new AdImageAsset([
                'asset' => new StringValue(['value' => $squareMarketingImageAssetResourceName])
            ])
        ],
        // Optional: Sets call to action text, price prefix and promotion text.
        'call_to_action_text' => new StringValue(['value' => 'Shop Now']),
        'price_prefix' => new StringValue(['value' => 'as low as']),
        'promo_text' => new StringValue(['value' => 'Free shipping!']),
    ]);

    // Creates an ad group ad with the created responsive display ad info.
    $adGroupAd = new AdGroupAd([
        'ad_group' => $adGroupResourceName,
        'status' => AdGroupAdStatus::PAUSED,
        'ad' => new Ad([
            'final_urls' => [new StringValue(['value' => 'https://www.example.com'])],
            'responsive_display_ad' => $responsiveDisplayAdInfo
        ])
    ]);

    // Creates an ad group ad operation.
    $adGroupAdOperation = new AdGroupAdOperation();
    $adGroupAdOperation->setCreate($adGroupAd);

    // Issues a mutate request to add the ad group ad.
    $adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
    /** @var MutateAdGroupAdsResponse $adGroupAdResponse */
    $adGroupAdResponse = $adGroupAdServiceClient->mutateAdGroupAds(
        $customerId,
        [$adGroupAdOperation]
    );

    // Prints out some information about the newly created ad.
    $adGroupAdResourceName = $adGroupAdResponse->getResults()[0]->getResourceName();
    printf("Added ad group ad named '%s'.%s", $adGroupAdResourceName, PHP_EOL);
}

Python

def _create_responsive_display_ad(client, customer_id, ad_group_resource_name,
                                  marketing_image_asset_resource_name,
                                  square_marketing_image_asset_resource_name):
    ad_group_ad_operation = client.get_type('AdGroupAdOperation', version='v2')
    ad_group_ad = ad_group_ad_operation.create
    ad_group_ad.ad_group.value = ad_group_resource_name
    ad_group_ad.status = client.get_type(
        'AdGroupAdStatusEnum', version='v2').PAUSED
    ad = ad_group_ad.ad
    final_url = ad.final_urls.add()
    final_url.value = 'https://www.example.com'
    responsive_display_ad = ad.responsive_display_ad
    headline = responsive_display_ad.headlines.add()
    headline.text.value = 'Travel'
    responsive_display_ad.long_headline.text.value = 'Travel the World'
    description = responsive_display_ad.descriptions.add()
    description.text.value = 'Take to the air!'
    responsive_display_ad.business_name.value = 'Google'
    marketing_image = responsive_display_ad.marketing_images.add()
    marketing_image.asset.value = marketing_image_asset_resource_name
    square_marketing_image = responsive_display_ad.square_marketing_images.add()
    square_marketing_image.asset.value = (
        square_marketing_image_asset_resource_name)
    responsive_display_ad.call_to_action_text.value = 'Shop Now'
    responsive_display_ad.price_prefix.value = 'as low as'
    responsive_display_ad.promo_text.value = 'Free shipping!'

    ad_group_ad_service = client.get_service('AdGroupAdService', version='v2')

    try:
        ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(
            customer_id, [ad_group_ad_operation])
    except google.ads.google_ads.errors.GoogleAdsException as ex:
        print(f'Request with ID "{ex.request_id}" failed with status '
              f'"{ex.error.code().name}" and includes the following errors:')
        for error in ex.failure.errors:
            print(f'\tError with message "{error.message}".')
            if error.location:
                for field_path_element in error.location.field_path_elements:
                    print(f'\t\tOn field: {field_path_element.field_name}')
        sys.exit(1)

    return ad_group_ad_response.results[0].resource_name

Perl

sub create_responsive_display_ad {
  my (
    $api_client, $customer_id, $ad_group_resource_name,
    $marketing_image_asset_resource_name,
    $square_marketing_image_asset_resource_name
  ) = @_;

  # Create a new image asset for marketing image and square marketing image if
  # there are no assets' resource names specified.
  $marketing_image_asset_resource_name =
    create_image_asset($api_client, $customer_id, MARKETING_IMAGE_URL,
    "Marketing Image")
    if not $marketing_image_asset_resource_name;

  $square_marketing_image_asset_resource_name =
    create_image_asset($api_client, $customer_id, SQUARE_MARKETING_IMAGE_URL,
    "Square Marketing Image")
    if not $square_marketing_image_asset_resource_name;

  # Create a responsive display ad info.
  my $responsive_display_ad_info =
    Google::Ads::GoogleAds::V3::Common::ResponsiveDisplayAdInfo->new({
      # Set some basic required information for the responsive display ad.
      headlines => [
        Google::Ads::GoogleAds::V3::Common::AdTextAsset->new({
            text => "Travel"
          })
      ],
      longHeadline => Google::Ads::GoogleAds::V3::Common::AdTextAsset->new({
          text => "Travel the World"
        }
      ),
      descriptions => [
        Google::Ads::GoogleAds::V3::Common::AdTextAsset->new({
            text => "Take to the air!"
          })
      ],
      businessName => "Google",
      # Set the marketing image and square marketing image to the previously
      # created image assets.
      marketingImages => [
        Google::Ads::GoogleAds::V3::Common::AdImageAsset->new({
            asset => $marketing_image_asset_resource_name
          })
      ],
      squareMarketingImages => [
        Google::Ads::GoogleAds::V3::Common::AdImageAsset->new({
            asset => $square_marketing_image_asset_resource_name
          })
      ],
      # Optional: Set call to action text, price prefix and promotion text.
      callToActionText => "Shop Now",
      pricePrefix      => "as low as",
      promoText        => "Free shipping!"
    });

  # Create an ad group ad with the created responsive display ad info.
  my $ad_group_ad = Google::Ads::GoogleAds::V3::Resources::AdGroupAd->new({
      adGroup => $ad_group_resource_name,
      status  => Google::Ads::GoogleAds::V3::Enums::AdGroupAdStatusEnum::PAUSED,
      ad      => Google::Ads::GoogleAds::V3::Resources::Ad->new({
          finalUrls           => ["https://www.example.com"],
          responsiveDisplayAd => $responsive_display_ad_info
        })});

  # Create an ad group ad operation.
  my $ad_group_ad_operation =
    Google::Ads::GoogleAds::V3::Services::AdGroupAdService::AdGroupAdOperation
    ->new({
      create => $ad_group_ad
    });

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

  # Print out some information about the newly created ad.
  my $ad_group_ad_resource_name =
    $ad_group_ad_response->{results}[0]{resourceName};
  printf "Added ad group ad named '%s'.\n", $ad_group_ad_resource_name;
}

Advanced Features

Color controls
You can customize colors for your responsive display ads to fit your branding needs by specifying main_color and accent_color. Set allow_flexible_color to true when you want to allow for serving ads with different colors than what you've specified when necessary.
Display ad format setting
Responsive display ads can run as both native and non-native formats. The difference between these two formats is that native format rendering is controlled by publishers, whereas non-native format rendering is optimized by Google models with advertisers' inputs (e.g., color information from main_color and accent_color).

You can set the format_setting field to select the format that the ads should run as. However, you cannot set the format_setting to NATIVE when the allow_flexible_color is false, as the coloring needs to be controlled by publishers in the case of native formats.