Example: Creating a dynamic remarketing campaign with Google Merchant Center
Stay organized with collectionsSave and categorize content based on your preferences.
In this example, you have a retail site that uploads product listings to Google
Merchant Center and you want to remarket groups of products to users who visited
the retail site. These users might have visited a product page or placed an item
in a basket or checkout, recorded by the triggering of a remarketing tag. You
can then create a campaign to target only this group or expand to similar
audiences to increase your reach.
Set theCampaignBudgetfor the campaign. This can
be a newly created budget or a shared budget.
Set theShoppingSettingfor the
campaign. Note that theCampaignServiceis used here, rather thanAdGroupService, since the feed must be attached at campaign level.
First, set themerchant_idto that of the Merchant Center account
associated with the Google Ads account. This Merchant Center account must
already be linked to Google Ads as described inthis
article.
defcreate_campaign(client:GoogleAdsClient,customer_id:str,merchant_center_account_id:int,campaign_budget_id:int,)->str:"""Creates a campaign linked to a Merchant Center product feed.Args:client: An initialized GoogleAds client.customer_id: The Google Ads customer ID.merchant_center_account_id: The target Merchant Center account ID.campaign_budget_id: The ID of the campaign budget to utilize.Returns:The string resource name of the newly created campaign."""# Gets the CampaignService client.campaign_service:CampaignServiceClient=client.get_service("CampaignService")# Creates a campaign operation and configures the new campaign.campaign_operation:CampaignOperation=client.get_type("CampaignOperation")campaign:Campaign=campaign_operation.createcampaign.name=f"Shopping campaign #{uuid4()}"# Configures the settings for the shopping campaign.campaign.shopping_setting.campaign_priority=0# This connects the campaign to the Merchant Center account.campaign.shopping_setting.merchant_id=merchant_center_account_idcampaign.shopping_setting.enable_local=True# Dynamic remarketing campaigns are only available on the Google Display# Network.campaign.advertising_channel_type=(client.enums.AdvertisingChannelTypeEnum.DISPLAY)campaign.status=client.enums.CampaignStatusEnum.PAUSEDcampaign.campaign_budget=client.get_service("CampaignBudgetService").campaign_budget_path(customer_id,str(campaign_budget_id))client.copy_from(campaign.manual_cpc,client.get_type("ManualCpc"))# Declare whether or not this campaign serves political ads targeting the# EU. Valid values are:# CONTAINS_EU_POLITICAL_ADVERTISING# DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISINGcampaign.contains_eu_political_advertising=(client.enums.EuPoliticalAdvertisingStatusEnum.DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING)# Issues a mutate request to add the campaign.campaign_response:MutateCampaignsResponse=(campaign_service.mutate_campaigns(customer_id=customer_id,operations=[campaign_operation]))campaign_resource_name:str=campaign_response.results[0].resource_nameprint(f"Created campaign with resource name '{campaign_resource_name}'.")returncampaign_resource_name
defcreate_campaign(client,customer_id,merchant_center_id,campaign_budget_id)operation=client.operation.create_resource.campaigndo|c|c.name="Shopping campaign ##{(Time.new.to_f*1000).to_i}"# Dynamic remarketing campaigns are only available on the Google Display# Network.c.advertising_channel_type=:DISPLAYc.status=:PAUSEDc.campaign_budget=client.path.campaign_budget(customer_id,campaign_budget_id)c.manual_cpc=client.resource.manual_cpc# Declare whether or not this campaign serves political ads targeting the EU.# Valid values are CONTAINS_EU_POLITICAL_ADVERTISING and# DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING.c.contains_eu_political_advertising=:DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING# The settings for the shopping campaign.# This connects the campaign to the merchant center account.c.shopping_setting=client.resource.shopping_settingdo|ss|ss.campaign_priority=0ss.merchant_id=merchant_center_id.to_iss.enable_local=trueendendresponse=client.service.campaign.mutate_campaigns(customer_id:customer_id,operations:[operation])puts"Created campaign:#{response.results.first.resource_name}"response.results.first.resource_nameend
subcreate_campaign{my($api_client,$customer_id,$merchant_center_account_id,$campaign_budget_id)=@_;# Configure the settings for the shopping campaign.my$shopping_settings=Google::Ads::GoogleAds::V21::Resources::ShoppingSetting->new({campaignPriority=>0,merchantId=>$merchant_center_account_id,enableLocal=>"true"});# Create the campaign.my$campaign=Google::Ads::GoogleAds::V21::Resources::Campaign->new({name=>"Shopping campaign #".uniqid(),# Dynamic remarketing campaigns are only available on the Google Display Network.advertisingChannelType=>DISPLAY,status=>Google::Ads::GoogleAds::V21::Enums::CampaignStatusEnum::PAUSED,campaignBudget=>Google::Ads::GoogleAds::V21::Utils::ResourceNames::campaign_budget($customer_id,$campaign_budget_id),manualCpc=>Google::Ads::GoogleAds::V21::Common::ManualCpc->new(),# This connects the campaign to the Merchant Center account.shoppingSetting=>$shopping_settings,# Declare whether or not this campaign serves political ads targeting the EU.# Valid values are CONTAINS_EU_POLITICAL_ADVERTISING and# DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING.containsEuPoliticalAdvertising=>DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING});# Create a campaign operation.my$campaign_operation=Google::Ads::GoogleAds::V21::Services::CampaignService::CampaignOperation->new({create=>$campaign});# Issue a mutate request to add the campaign.my$campaigns_response=$api_client->CampaignService()->mutate({customerId=>$customer_id,operations=>[$campaign_operation]});my$campaign_resource_name=$campaigns_response->{results}[0]{resourceName};printf"Created campaign with resource name '%s'.\n",$campaign_resource_name;return$campaign_resource_name;}
defcreate_ad_group(client:GoogleAdsClient,customer_id:str,campaign_resource_name:str)->str:"""Creates an ad group for the remarketing campaign.Args:client: An initialized GoogleAds client.customer_id: The Google Ads customer ID.campaign_resource_name: The resource name of the target campaign.Returns:The string resource name of the newly created ad group."""# Gets the AdGroupService.ad_group_service:AdGroupServiceClient=client.get_service("AdGroupService")# Creates an ad group operation and configures the new ad group.ad_group_operation:AdGroupOperation=client.get_type("AdGroupOperation")ad_group:AdGroup=ad_group_operation.createad_group.name="Dynamic remarketing ad group"ad_group.campaign=campaign_resource_namead_group.status=client.enums.AdGroupStatusEnum.ENABLED# Issues a mutate request to add the ad group.ad_group_response:MutateAdGroupsResponse=(ad_group_service.mutate_ad_groups(customer_id=customer_id,operations=[ad_group_operation]))ad_group_resource_name:str=ad_group_response.results[0].resource_namereturnad_group_resource_name
defcreate_ad_group(client,customer_id,campaign_resource_name)# Creates the ad group.ad_group=client.resource.ad_groupdo|ag|ag.name="Dynamic remarketing ad group#{(Time.now.to_f*1000).to_i}"ag.campaign=campaign_resource_nameag.status=:ENABLEDend# Creates the ad group operation.operation=client.operation.create_resource.ad_group(ad_group)response=client.service.ad_group.mutate_ad_groups(customer_id:customer_id,operations:[operation])puts"Created ad group:#{response.results.first.resource_name}"response.results.first.resource_nameend
subcreate_ad_group{my($api_client,$customer_id,$campaign_resource_name)=@_;# Create the ad group.my$ad_group=Google::Ads::GoogleAds::V21::Resources::AdGroup->new({name=>"Dynamic remarketing ad group",campaign=>$campaign_resource_name,status=>Google::Ads::GoogleAds::V21::Enums::AdGroupStatusEnum::ENABLED});# Create an ad group operation.my$ad_group_operation=Google::Ads::GoogleAds::V21::Services::AdGroupService::AdGroupOperation->new({create=>$ad_group});# Issue a mutate request to add the ad group.my$ad_groups_response=$api_client->AdGroupService()->mutate({customerId=>$customer_id,operations=>[$ad_group_operation]});my$ad_group_resource_name=$ad_groups_response->{results}[0]{resourceName};printf"Created ad group with resource name '%s'.\n",$ad_group_resource_name;return$ad_group_resource_name;}
defcreate_ad(client:GoogleAdsClient,customer_id:str,ad_group_resource_name:str)->None:"""Creates the responsive display ad.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."""# Get the AdGroupAdService client.ad_group_ad_service:AdGroupAdServiceClient=client.get_service("AdGroupAdService")# Upload image assets for the ad.marketing_image_resource_name:str=upload_image_asset(client,customer_id,"https://gaagl.page.link/Eit5","Marketing Image")square_marketing_image_resource_name:str=upload_image_asset(client,customer_id,"https://gaagl.page.link/bjYi","Square Marketing Image",)# Create the relevant asset objects for the ad.marketing_image:AdImageAsset=client.get_type("AdImageAsset")marketing_image.asset=marketing_image_resource_namesquare_marketing_image:AdImageAsset=client.get_type("AdImageAsset")square_marketing_image.asset=square_marketing_image_resource_nameheadline:AdTextAsset=client.get_type("AdTextAsset")headline.text="Travel"description:AdTextAsset=client.get_type("AdTextAsset")description.text="Take to the air!"# Create an ad group ad operation and set the ad group ad values.ad_group_ad_operation:AdGroupAdOperation=client.get_type("AdGroupAdOperation")ad_group_ad:AdGroupAd=ad_group_ad_operation.createad_group_ad.ad_group=ad_group_resource_namead_group_ad.ad.final_urls.append("http://www.example.com/")# Configure the responsive display ad info object.responsive_display_ad_info:ResponsiveDisplayAdInfo=(ad_group_ad.ad.responsive_display_ad)responsive_display_ad_info.marketing_images.append(marketing_image)responsive_display_ad_info.square_marketing_images.append(square_marketing_image)responsive_display_ad_info.headlines.append(headline)responsive_display_ad_info.long_headline.text="Travel the World"responsive_display_ad_info.descriptions.append(description)responsive_display_ad_info.business_name="Interplanetary Cruises"# Optional: Call to action text.# Valid texts: https://support.google.com/google-ads/answer/7005917responsive_display_ad_info.call_to_action_text="Apply Now"# Optional: Set the ad colors.responsive_display_ad_info.main_color="#0000ff"responsive_display_ad_info.accent_color="#ffff00"# Optional: Set to false to strictly render the ad using the colors.responsive_display_ad_info.allow_flexible_color=False# Optional: Set the format setting that the ad will be served in.responsive_display_ad_info.format_setting=(client.enums.DisplayAdFormatSettingEnum.NON_NATIVE)# Optional: Create a logo image and set it to the ad.# logo_image = client.get_type("AdImageAsset")# logo_image.asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"# responsive_display_ad_info.logo_images.append(logo_image)# Optional: Create a square logo image and set it to the ad.# square_logo_image = client.get_type("AdImageAsset")# square_logo_image.asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"# responsive_display_ad_info.square_logo_images.append(square_logo_image)# Issue a mutate request to add the ad group ad.ad_group_ad_response:MutateAdGroupAdsResponse=(ad_group_ad_service.mutate_ad_group_ads(customer_id=customer_id,operations=[ad_group_ad_operation]))print("Created ad group ad with resource name "f"'{ad_group_ad_response.results[0].resource_name}'.")
defcreate_ad(client,customer_id,ad_group_resource_name)marketing_image_url="https://gaagl.page.link/Eit5"square_marketing_image_url="https://gaagl.page.link/bjYi"marketing_image_asset_resource_name=upload_asset(client,customer_id,marketing_image_url,"Marketing Image")square_marketing_image_asset_resource_name=upload_asset(client,customer_id,square_marketing_image_url,"Square Marketing Image")# Creates an ad group ad operation.operation=client.operation.create_resource.ad_group_addo|aga|aga.ad_group=ad_group_resource_nameaga.status=:PAUSEDaga.ad=client.resource.addo|a|a.final_urls<<"https://www.example.com"# Creates the responsive display ad info object.a.responsive_display_ad=client.resource.responsive_display_ad_infodo|rda|rda.headlines<<client.resource.ad_text_assetdo|ata|ata.text="Travel"endrda.long_headline=client.resource.ad_text_assetdo|ata|ata.text="Travel the World"endrda.descriptions<<client.resource.ad_text_assetdo|ata|ata.text="Take to the air!"endrda.business_name="Interplanetary Cruises"rda.marketing_images<<client.resource.ad_image_assetdo|aia|aia.asset=marketing_image_asset_resource_nameendrda.square_marketing_images<<client.resource.ad_image_assetdo|aia|aia.asset=square_marketing_image_asset_resource_nameend# Optional: Call to action text.# Valid texts: https://support.google.com/google-ads/answer/7005917rda.call_to_action_text="Apply Now"# Optional: Sets the ad colors.rda.main_color="#0000ff"rda.accent_color="#ffff00"# Optional: Sets to false to strictly render the ad using the colors.rda.allow_flexible_color=false# Optional: Sets the format setting that the ad will be served in.rda.format_setting=:NON_NATIVE# Optional: Creates a logo image and sets it to the ad.# rda.logo_images << client.resource.ad_image_asset do |aia|# aia.asset = "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"# end# Optional: Creates a square logo image and sets it to the ad.# rda.square_logo_images << client.resource.ad_image_asset do |aia|# aia.asset = "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"# endendendend# Issues a mutate request to add the ad group ad.response=client.service.ad_group_ad.mutate_ad_group_ads(customer_id:customer_id,operations:[operation])# Prints out some information about the newly created ad.resource_name=response.results.first.resource_nameputs"Created ad group ad:#{resource_name}"resource_nameend
subcreate_ad{my($api_client,$customer_id,$ad_group_resource_name)=@_;my$marketing_image_resource_name=upload_asset($api_client,$customer_id,"https://gaagl.page.link/Eit5","Marketing Image");my$square_marketing_image_resource_name=upload_asset($api_client,$customer_id,"https://gaagl.page.link/bjYi","Square Marketing Image");# Create the responsive display ad info object.my$responsive_display_ad_info=Google::Ads::GoogleAds::V21::Common::ResponsiveDisplayAdInfo->new({marketingImages=>[Google::Ads::GoogleAds::V21::Common::AdImageAsset->new({asset=>$marketing_image_resource_name})],squareMarketingImages=>[Google::Ads::GoogleAds::V21::Common::AdImageAsset->new({asset=>$square_marketing_image_resource_name})],headlines=>[Google::Ads::GoogleAds::V21::Common::AdTextAsset->new({text=>"Travel"})],longHeadline=>Google::Ads::GoogleAds::V21::Common::AdTextAsset->new({text=>"Travel the World"}),descriptions=>[Google::Ads::GoogleAds::V21::Common::AdTextAsset->new({text=>"Take to the air!"})],businessName=>"Interplanetary Cruises",# Optional: Call to action text.# Valid texts: https://support.google.com/google-ads/answer/7005917callToActionText=>"Apply Now",# Optional: Set the ad colors.mainColor=>"#0000ff",accentColor=>"#ffff00",# Optional: Set to false to strictly render the ad using the colors.allowFlexibleColor=>"false",# Optional: Set the format setting that the ad will be served in.formatSetting=>NON_NATIVE,# Optional: Create a logo image and set it to the ad.# logoImages => [# Google::Ads::GoogleAds::V21::Common::AdImageAsset->new({# asset => "INSERT_LOGO_IMAGE_RESOURCE_NAME_HERE"# })# ],# Optional: Create a square logo image and set it to the ad.# squareLogoImages => [# Google::Ads::GoogleAds::V21::Common::AdImageAsset->new({# asset => "INSERT_SQUARE_LOGO_IMAGE_RESOURCE_NAME_HERE"# })# ]});# Create an ad group ad.my$ad_group_ad=Google::Ads::GoogleAds::V21::Resources::AdGroupAd->new({adGroup=>$ad_group_resource_name,ad=>Google::Ads::GoogleAds::V21::Resources::Ad->new({responsiveDisplayAd=>$responsive_display_ad_info,finalUrls=>["http://www.example.com/"]})});# Create an ad group ad operation.my$ad_group_ad_operation=Google::Ads::GoogleAds::V21::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]});printf"Created ad group ad with resource name '%s'.\n",$ad_group_ads_response->{results}[0]{resourceName};}
defattach_user_list(client:GoogleAdsClient,customer_id:str,ad_group_resource_name:str,user_list_id:int,)->None:"""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:AdGroupCriterionServiceClient=(client.get_service("AdGroupCriterionService"))# Create an ad group criterion operation and set the ad group criterion# values.ad_group_criterion_operation:AdGroupCriterionOperation=client.get_type("AdGroupCriterionOperation")ad_group_criterion:AdGroupCriterion=ad_group_criterion_operation.createad_group_criterion.ad_group=ad_group_resource_namead_group_criterion.user_list.user_list=client.get_service("UserListService").user_list_path(customer_id,str(user_list_id))# Issue a mutate request to add the ad group criterion.ad_group_criterion_response:MutateAdGroupCriteriaResponse=(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}'.")
defattach_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_criteriondo|agc|agc.ad_group=ad_group_resource_nameagc.user_list=client.resource.user_list_infodo|ul|ul.user_list=user_list_resource_nameendend# 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
subattach_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::V21::Resources::AdGroupCriterion->new({adGroup=>$ad_group_resource_name,userList=>Google::Ads::GoogleAds::V21::Common::UserListInfo->new({userList=>Google::Ads::GoogleAds::V21::Utils::ResourceNames::user_list($customer_id,$user_list_id)})});# Create an ad group criterion operation.my$ad_group_criterion_operation=Google::Ads::GoogleAds::V21::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};}
Once you've set up the dynamic remarketing campaign for your Merchant Center
feeds, you can use theAd Preview
toolfrom your Google Ads
account to see the contents pulled from your Merchant Center feeds.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[[["\u003cp\u003eThis guide details setting up dynamic remarketing campaigns in Google Ads for retail sites using Google Merchant Center product listings.\u003c/p\u003e\n"],["\u003cp\u003ePrerequisites include a remarketing list, Merchant Center account linked to Google Ads, a product feed, and ad creatives.\u003c/p\u003e\n"],["\u003cp\u003eSteps involve creating a campaign linked to Merchant Center, creating an ad group, and designing a responsive display ad.\u003c/p\u003e\n"],["\u003cp\u003eCode examples in various languages demonstrate programmatic campaign creation and management using the Google Ads API.\u003c/p\u003e\n"],["\u003cp\u003eKey concepts include dynamic remarketing, Google Merchant Center, and responsive display ads.\u003c/p\u003e\n"]]],[],null,[]]