Stay organized with collectionsSave and categorize content based on your preferences.
InGet suggestions, we demonstrated
how to retrieve a set ofKeywordThemeConstantobjects using a
word or phrase. In this step, we use those same keyword theme constants to
create a set ofCampaignCriterionobjects
for the Smart campaign to target.
Similar to how we used the budget amount suggested by theSmartCampaignSuggestServicewhencreating a
budget, we recommend that you create
campaign criteria based on the keyword theme constants retrieved from theKeywordThemeConstantServiceinGet suggestions.
Here are the key requirements for Smart campaign criteria:
Smart campaigns only support the following criterion types:
defcreate_campaign_criterion_operations(client:GoogleAdsClient,customer_id:str,keyword_theme_infos:List[KeywordThemeInfo],suggestion_info:SmartCampaignSuggestionInfo,)->List[MutateOperation]:"""Creates a list of MutateOperations that create new campaign criteria.Args:client: an initialized GoogleAdsClient instance.customer_id: a client customer ID.keyword_theme_infos: a list of KeywordThemeInfos.suggestion_info: A SmartCampaignSuggestionInfo instance.Returns:a list of MutateOperations that create new campaign criteria."""campaign_service:CampaignServiceClient=client.get_service("CampaignService")operations:List[MutateOperation]=[]info:KeywordThemeInfoforinfoinkeyword_theme_infos:mutate_operation:MutateOperation=client.get_type("MutateOperation")campaign_criterion_operation:CampaignCriterionOperation=(mutate_operation.campaign_criterion_operation)campaign_criterion:CampaignCriterion=(campaign_criterion_operation.create)# Set the campaign ID to a temporary ID.campaign_criterion.campaign=campaign_service.campaign_path(customer_id,_SMART_CAMPAIGN_TEMPORARY_ID)# Set the keyword theme to the given KeywordThemeInfo.campaign_criterion.keyword_theme.CopyFrom(info)# Add the mutate operation to the list of other operations.operations.append(mutate_operation)# Create a location criterion for each location in the suggestion info# object to add corresponding location targeting to the Smart campaignlocation_info:LocationInfoforlocation_infoinsuggestion_info.location_list.locations:mutate_operation:MutateOperation=client.get_type("MutateOperation")campaign_criterion_operation:CampaignCriterionOperation=(mutate_operation.campaign_criterion_operation)campaign_criterion:CampaignCriterion=(campaign_criterion_operation.create)# Set the campaign ID to a temporary ID.campaign_criterion.campaign=campaign_service.campaign_path(customer_id,_SMART_CAMPAIGN_TEMPORARY_ID)# Set the location to the given location.campaign_criterion.location.CopyFrom(location_info)# Add the mutate operation to the list of other operations.operations.append(mutate_operation)returnoperations
# Creates a list of mutate_operations that create new campaign criteria.defcreate_campaign_criterion_operations(client,customer_id,keyword_theme_infos,suggestion_info)operations=[]keyword_theme_infos.eachdo|info|operations<<client.operation.mutatedo|m|m.campaign_criterion_operation=client.operation.create_resource.campaign_criteriondo|cc|# Sets the campaign ID to a temporary ID.cc.campaign=client.path.campaign(customer_id,SMART_CAMPAIGN_TEMPORARY_ID)# Sets the keyword theme to the given keyword_theme_info.cc.keyword_theme=infoendendend# Create a location criterion for each location in the suggestion info object# to add corresponding location targeting to the Smart campaignsuggestion_info.location_list.locations.eachdo|location|operations<<client.operation.mutatedo|m|m.campaign_criterion_operation=client.operation.create_resource.campaign_criteriondo|cc|# Sets the campaign ID to a temporary ID.cc.campaign=client.path.campaign(customer_id,SMART_CAMPAIGN_TEMPORARY_ID)# Sets the location to the given location.cc.location=locationendendendoperationsend
# Creates a list of MutateOperations that create new campaign criteria.sub_create_campaign_criterion_operations{my($customer_id,$keyword_theme_infos,$suggestion_info)=@_;my$campaign_criterion_operations=[];foreachmy$keyword_theme_info(@$keyword_theme_infos){push@$campaign_criterion_operations,Google::Ads::GoogleAds::V21::Services::GoogleAdsService::MutateOperation->new({campaignCriterionOperation=>Google::Ads::GoogleAds::V21::Services::CampaignCriterionService::CampaignCriterionOperation->new({create=>Google::Ads::GoogleAds::V21::Resources::CampaignCriterion->new({# Set the campaign ID to a temporary ID.campaign=>Google::Ads::GoogleAds::V21::Utils::ResourceNames::campaign($customer_id,SMART_CAMPAIGN_TEMPORARY_ID),# Set the keyword theme to the given KeywordThemeInfo.keywordTheme=>$keyword_theme_info})})});}# Create a location criterion for each location in the suggestion info object# to add corresponding location targeting to the Smart campaign.foreachmy$location_info(@{$suggestion_info->{locationList}{locations}}){push@$campaign_criterion_operations,Google::Ads::GoogleAds::V21::Services::GoogleAdsService::MutateOperation->new({campaignCriterionOperation=>Google::Ads::GoogleAds::V21::Services::CampaignCriterionService::CampaignCriterionOperation->new({create=>Google::Ads::GoogleAds::V21::Resources::CampaignCriterion->new({# Set the campaign ID to a temporary ID.campaign=>Google::Ads::GoogleAds::V21::Utils::ResourceNames::campaign($customer_id,SMART_CAMPAIGN_TEMPORARY_ID),# Set the location to the given location.location=>$location_info})})});}return$campaign_criterion_operations;}
Negative keyword theme criteria behave differently from positive keyword theme
criteria. Whereas a positive keyword theme criterion is adjusted to target other
similar criteria automatically, a negative keyword theme criterion is restricted
to only negatively target the exact given term. The behavior is equivalent to
how anegative phrase matchkeyword behaves.
[[["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 page demonstrates how to create campaign criteria for Smart campaigns using keyword themes and location targeting retrieved from suggestions.\u003c/p\u003e\n"],["\u003cp\u003eSmart campaigns support specific criteria types such as ad schedule, keyword theme, location, and proximity.\u003c/p\u003e\n"],["\u003cp\u003eWhile multiple location criteria are allowed, only one proximity criterion can be used, and location and proximity targeting cannot be combined.\u003c/p\u003e\n"],["\u003cp\u003eKeyword theme constants from suggestions are converted into KeywordThemeInfo objects and used to create campaign criteria.\u003c/p\u003e\n"],["\u003cp\u003eFree-form keyword themes can be used to negatively target specific terms in Smart campaigns.\u003c/p\u003e\n"]]],[],null,[]]