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, ?int $marketingImageAssetId, ?int $squareMarketingImageAssetId ) { // Creates a new image asset for marketing image and square marketing image if there are no // assets' IDs specified. $marketingImageAssetResourceName = $marketingImageAssetId ? ResourceNames::forAsset($customerId, $marketingImageAssetId) : self::createImageAsset( $googleAdsClient, $customerId, self::MARKETING_IMAGE_URL, 'Marketing Image' ); $squareMarketingImageAssetResourceName = $squareMarketingImageAssetId ? ResourceNames::forAsset($customerId, $squareMarketingImageAssetId) : 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' => 'Travel'])], 'long_headline' => new AdTextAsset(['text' => 'Travel the World']), 'descriptions' => [new AdTextAsset(['text' => 'Take to the air!'])], 'business_name' => 'Google', // Sets the marketing image and square marketing image to the previously created // image assets. 'marketing_images' => [ new AdImageAsset(['asset' => $marketingImageAssetResourceName]) ], 'square_marketing_images' => [ new AdImageAsset(['asset' => $squareMarketingImageAssetResourceName]) ], // Optional: Sets call to action text, price prefix and promotion text. 'call_to_action_text' => 'Shop Now', 'price_prefix' => 'as low as', 'promo_text' => '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' => ['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_id, square_marketing_image_asset_id, ): ad_group_ad_operation = client.get_type("AdGroupAdOperation", version="v6") ad_group_ad = ad_group_ad_operation.create ad_group_ad.ad_group = ad_group_resource_name ad_group_ad.status = client.get_type( "AdGroupAdStatusEnum", version="v6" ).PAUSED ad = ad_group_ad.ad ad.final_urls.append("https://www.example.com") responsive_display_ad = ad.responsive_display_ad headline = responsive_display_ad.headlines.add() headline.text = "Travel" responsive_display_ad.long_headline.text = "Travel the World" description = responsive_display_ad.descriptions.add() description.text = "Take to the air!" responsive_display_ad.business_name = "Google" asset_service = client.get_service("AssetService", version="v6") marketing_image = responsive_display_ad.marketing_images.add() marketing_image.asset = asset_service.asset_path( customer_id, marketing_image_asset_id ) square_marketing_image = responsive_display_ad.square_marketing_images.add() square_marketing_image.asset = asset_service.asset_path( customer_id, square_marketing_image_asset_id ) responsive_display_ad.call_to_action_text = "Shop Now" responsive_display_ad.price_prefix = "as low as" responsive_display_ad.promo_text = "Free shipping!" ad_group_ad_service = client.get_service("AdGroupAdService", version="v6") try: ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads( customer_id, [ad_group_ad_operation] ) except GoogleAdsException as ex: _handle_google_ads_exception(ex)
Perl
sub create_responsive_display_ad { my ($api_client, $customer_id, $ad_group_resource_name, $marketing_image_asset_id, $square_marketing_image_asset_id) = @_; # Create a new image asset for marketing image and square marketing image if # there are no assets' IDs specified. my $marketing_image_asset_resource_name = defined $marketing_image_asset_id ? Google::Ads::GoogleAds::V6::Utils::ResourceNames::asset($customer_id, $marketing_image_asset_id) : create_image_asset($api_client, $customer_id, MARKETING_IMAGE_URL, "Marketing Image"); my $square_marketing_image_asset_resource_name = defined $square_marketing_image_asset_id ? Google::Ads::GoogleAds::V6::Utils::ResourceNames::asset($customer_id, $square_marketing_image_asset_id) : create_image_asset($api_client, $customer_id, SQUARE_MARKETING_IMAGE_URL, "Square Marketing Image"); # Create a responsive display ad info. my $responsive_display_ad_info = Google::Ads::GoogleAds::V6::Common::ResponsiveDisplayAdInfo->new({ # Set some basic required information for the responsive display ad. headlines => [ Google::Ads::GoogleAds::V6::Common::AdTextAsset->new({ text => "Travel" }) ], longHeadline => Google::Ads::GoogleAds::V6::Common::AdTextAsset->new({ text => "Travel the World" } ), descriptions => [ Google::Ads::GoogleAds::V6::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::V6::Common::AdImageAsset->new({ asset => $marketing_image_asset_resource_name }) ], squareMarketingImages => [ Google::Ads::GoogleAds::V6::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::V6::Resources::AdGroupAd->new({ adGroup => $ad_group_resource_name, status => Google::Ads::GoogleAds::V6::Enums::AdGroupAdStatusEnum::PAUSED, ad => Google::Ads::GoogleAds::V6::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::V6::Services::AdGroupAdService::AdGroupAdOperation ->new({ create => $ad_group_ad }); # Issue a mutate request to add the ad group ad. my $ad_group_ads_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_ads_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
andaccent_color
. Setallow_flexible_color
totrue
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
andaccent_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.
- Ad controls
- Responsive display ads can tell you if they've been opted into generated
videos or asset enhancements through their
control_spec
.