Stay organized with collectionsSave and categorize content based on your preferences.
Use thetargeting settingin
your ad groups or campaigns to specify whether to narrow your ads to only show
to specific audience segments, or on specific content you've selected.
Set up the targeting setting
You can set up details on how your various criteria types are used for targeting
by setting theTargetingSettingfield with
an array oftarget_restrictions.
EachTargetRestrictionlets you control
whether a type of criteria uses thebid_onlyoption or not.
When settingbid_onlytotrue, the targeting setting will be set to
"Observation", and the criteria won't be used to restrict traffic, but will
allow you to bid differently for different users on your lists. Settingbid_onlytofalsesets the targeting setting to "Targeting" and enables the
criteria to restrict ad group traffic only to users on the targeted list.
Best practices
By default,bid_onlyis set tofalse, which means the targeting setting will
be set to "Targeting". If you're adding audience segments to a search or
shopping campaign, consider changing the targeting setting ofbid_onlytotrueto set it to "Observation".
If you're setting up a duplicate campaign for audience segments for search ads,
keep the targeting ofbid_onlyset tofalse.
Restrictions
You cannot add or updatetargeting_settingon anAdGroupiftargeting_settingis set on the
parent campaign. If thetargeting_settingis set on the parentCampaign, you
must first remove thetargeting_settingon the parentCampaign. Likewise,
you must first remove thetargeting_settingon theAdGroupin order to set
it on theCampaign.
Retrieve the targeting setting
To verify that your targeting is set up as you intend, check thetargeting_settingon ad groups or campaigns by requesting thead_group.targeting_setting.target_restrictionsfield from thead_groupresource in a search query.
Example
This example updates thetargeting_settingon an ad group so thatbid_onlyistrueforTargetRestrictioninstances with atargeting_dimensionofAUDIENCE,
effectively ensuring that ads in the ad group are only shown to users in the
specified audience segment.
First, retrieve all thead_group.targeting_setting.target_restrictionsfrom
the ad group with the provided ID.
Next, loop through the target restrictions and reconstruct theTargetingSettingobjects. If the code encounters aTargetRestrictionwith atargeting_dimensionofAUDIENCEand abid_onlyvalue offalse, it
updates theTargetRestrictionobject'sbid_onlyfield totrue(or
"Observation") and add it to ourTargetingSettingobject.
Otherwise, add theTargetRestrictionobject as returned from the server to theTargetingSetting. It is important to note that you must reconstruct and pass
the entireTargetingSettingobject back to Google Ads. Google assumes that anytarget_restrictionsmissing from theTargetingSettingshould be removed.
target_restriction:TargetRestrictionfortarget_restrictionintarget_restrictions:targeting_dimension:TargetingDimensionEnum.TargetingDimension=(target_restriction.targeting_dimension)bid_only:bool=target_restriction.bid_onlyprint("\tTargeting restriction with targeting dimension "f"'{targeting_dimension.name}' "f"and bid only set to '{bid_only}'.")# Add the target restriction to the TargetingSetting object as# is if the targeting dimension has a value other than audience# because those should not change.iftargeting_dimension!=targeting_dimension_enum.AUDIENCE:targeting_setting.target_restrictions.append(target_restriction)elifnotbid_only:should_update_targeting_setting:bool=True# Add an audience target restriction with bid_only set to# true to the targeting setting object. This has the effect# of setting the audience target restriction to# "Observation". For more details about the targeting# setting, visit# https://support.google.com/google-ads/answer/7365594.new_target_restriction:TargetRestriction=(targeting_setting.target_restrictions.add())new_target_restriction.targeting_dimension=(targeting_dimension_enum.AUDIENCE)new_target_restriction.bid_only=True
ad_group.targeting_setting.target_restrictions.eachdo|r|# Prints the results.targeting_dimension=r.targeting_dimensionbid_only=r.bid_onlyputs"- Targeting restriction with targeting dimension "\"#{targeting_dimension}and bid only set to#{bid_only}."# Adds the target restriction to the TargetingSetting object as is if the# targeting dimension has a value other than AUDIENCE because those should# not change.iftargeting_dimension!=:AUDIENCEtarget_restrictions<<relsif!bid_onlyshould_update_targeting_setting=true# Adds an AUDIENCE target restriction with bid_only set to true to the# targeting setting object. This has the effect of setting the AUDIENCE# target restriction to "Observation".# For more details about the targeting setting, visit# https://support.google.com/google-ads/answer/7365594.target_restrictions<<client.resource.target_restrictiondo|tr|tr.targeting_dimension=:AUDIENCEtr.bid_only=trueendendend
foreachmy$target_restriction(@target_restrictions){my$targeting_dimension=$target_restriction->{targetingDimension};printf"\tTargeting restriction with targeting dimension '%s' and bid "."only set to '%s'.\n",$targeting_dimension,$target_restriction->{bidOnly}?"TRUE":"FALSE";# Add the target restriction to the TargetingSetting object as is if the# targeting dimension has a value other than AUDIENCE because those# should not change.if($targeting_dimensionneAUDIENCE){$target_restriction->{bidOnly}=$target_restriction->{bidOnly}?"true":"false";push@{$targeting_setting->{targetRestrictions}},$target_restriction;}elsif(!$target_restriction->{bidOnly}){$should_update_target_setting=1;# Add an AUDIENCE target restriction with bid_only set to true to the# targeting setting object. This has the effect of setting the# AUDIENCE target restriction to "Observation". For more details about# the targeting setting, visit# https://support.google.com/google-ads/answer/7365594.my$new_restriction=Google::Ads::GoogleAds::V21::Common::TargetRestriction->new({targetingDimension=>AUDIENCE,bidOnly=>"true"});push@{$targeting_setting->{targetRestrictions}},$new_restriction;}}
defupdate_targeting_setting(client:GoogleAdsClient,customer_id:str,ad_group_id:str,targeting_setting:TargetingSetting,)->None:"""Updates the given TargetingSetting of an ad group.Args:client: The Google Ads client.customer_id: The Google Ads customer ID.ad_group_id: The ad group ID for which to update the audience targetingrestriction.targeting_setting: The updated targeting setting."""# Get the AdGroupService client.ad_group_service:AdGroupServiceClient=client.get_service("AdGroupService")# Construct an operation that will update the ad group.ad_group_operation:AdGroupOperation=client.get_type("AdGroupOperation")# Populate the ad group object with the updated targeting setting.ad_group:AdGroup=ad_group_operation.updatead_group.resource_name=ad_group_service.ad_group_path(customer_id,ad_group_id)ad_group.targeting_setting.target_restrictions.extend(targeting_setting.target_restrictions)# Use the field_mask utility to derive the update mask. This mask tells the# Google Ads API which attributes of the ad group you want to change.client.copy_from(ad_group_operation.update_mask,protobuf_helpers.field_mask(None,ad_group._pb),)# Send the operation in a mutate request and print the resource name of the# updated object.mutate_ad_groups_response:MutateAdGroupsResponse=(ad_group_service.mutate_ad_groups(customer_id=customer_id,operations=[ad_group_operation]))print("Updated targeting setting of ad group with resource name "f"'{mutate_ad_groups_response.results[0].resource_name}'; set the ""audience target restriction to 'Observation'.")
defupdate_targeting_setting(client,customer_id,ad_group_id,targeting_setting)# Constructs an operation that will update the ad group with the specified# resource name.ad_group_resource_name=client.path.ad_group(customer_id,ad_group_id)operation=client.operation.update_resource.ad_group(ad_group_resource_name)do|ag|ag.targeting_setting=targeting_settingend# Issues a mutate request to update the ad group.response=client.service.ad_group.mutate_ad_groups(customer_id:customer_id,operations:[operation],)# Prints the resource name of the updated ad group.puts"Updated targeting setting of ad group with resource name "\"#{response.results.first.resource_name}; set the AUDIENCE target "\"restriction to 'Observation'."end
subupdate_targeting_setting{my($api_client,$customer_id,$ad_group_id,$targeting_setting)=@_;# Construct an ad group object with the updated targeting setting.my$ad_group=Google::Ads::GoogleAds::V21::Resources::AdGroup->new({resourceName=>Google::Ads::GoogleAds::V21::Utils::ResourceNames::ad_group($customer_id,$ad_group_id),targetingSetting=>$targeting_setting});# Create an operation that will update the ad group, using the FieldMasks# utility to derive the update mask. This mask tells the Google Ads API which# attributes of the ad group you want to change.my$ad_group_operation=Google::Ads::GoogleAds::V21::Services::AdGroupService::AdGroupOperation->new({update=>$ad_group,updateMask=>all_set_fields_of($ad_group)});# Send the operation in a mutate request and print the resource name of the# updated resource.my$ad_groups_response=$api_client->AdGroupService()->mutate({customerId=>$customer_id,operations=>[$ad_group_operation]});printf"Updated targeting setting of ad group with resourceName "."'%s'; set the AUDIENCE target restriction to 'Observation'.\n",$ad_groups_response->{results}[0]{resourceName};}
[[["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\u003eThe \u003ccode\u003eTargetingSetting\u003c/code\u003e field in the Google Ads API controls how targeting criteria are applied to ad groups and campaigns, allowing for either "Targeting" or "Observation" behavior.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ebid_only = true\u003c/code\u003e sets the targeting setting to "Observation" for bid adjustments without restricting ad delivery, while \u003ccode\u003ebid_only = false\u003c/code\u003e sets it to "Targeting" to only show ads to users matching the criteria.\u003c/p\u003e\n"],["\u003cp\u003eYou cannot set \u003ccode\u003etargeting_setting\u003c/code\u003e on both an ad group and its parent campaign simultaneously; remove it from one level before applying it to the other.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples demonstrate how to update an ad group's targeting setting to "Observation" for audience segments, retrieving existing settings, reconstructing \u003ccode\u003eTargetingSetting\u003c/code\u003e, and updating the ad group with the modified object.\u003c/p\u003e\n"],["\u003cp\u003eWhen updating the \u003ccode\u003eTargetingSetting\u003c/code\u003e, provide the entire object as missing \u003ccode\u003etarget_restrictions\u003c/code\u003e will be removed.\u003c/p\u003e\n"]]],[],null,[]]