Targeting Settings Stay organized with collections Save and categorize content based on your preferences.
Use thetargeting setting inyour ad groups or campaigns to specify whether to narrow your ads to only showto specific audience segments, or on specific content you've selected.
Tip: This guide focuses on targeting and observation settings. If you want tolearn how to set targeting criteria for a campaign or ad group—forexample, audience targeting to specify who you want to reach—refer to theTargeting Criteria guide and theAdd Campaign Targeting Criteriasample.Set up the targeting setting
You can set up details on how your various criteria types are used for targetingby setting theTargetingSetting
field withan array oftarget_restrictions
.EachTargetRestriction
lets you controlwhether a type of criteria uses thebid_only
option or not.
When settingbid_only
totrue
, the targeting setting will be set to"Observation", and the criteria won't be used to restrict traffic, but willallow you to bid differently for different users on your lists. Settingbid_only
tofalse
sets the targeting setting to "Targeting" and enables thecriteria to restrict ad group traffic only to users on the targeted list.
Best practices
By default,bid_only
is set tofalse
, which means the targeting setting willbe set to "Targeting". If you're adding audience segments to a search orshopping campaign, consider changing the targeting setting ofbid_only
totrue
to set it to "Observation".
If you're setting up a duplicate campaign for audience segments for search ads,keep the targeting ofbid_only
set tofalse
.
Restrictions
You cannot add or updatetargeting_setting
on anAdGroup
iftargeting_setting
is set on theparent campaign. If thetargeting_setting
is set on the parentCampaign
, youmust first remove thetargeting_setting
on the parentCampaign
. Likewise,you must first remove thetargeting_setting
on theAdGroup
in order to setit on theCampaign
.
Retrieve the targeting setting
To verify that your targeting is set up as you intend, check thetargeting_setting
on ad groups or campaigns by requesting thead_group.targeting_setting.target_restrictions
field from thead_group
resource in a search query.
Example
This example updates thetargeting_setting
on an ad group so thatbid_only
istrue
forTargetRestriction
instances with atargeting_dimension
ofAUDIENCE
,effectively ensuring that ads in the ad group are only shown to users in thespecified audience segment.
First, retrieve all thead_group.targeting_setting.target_restrictions
fromthe ad group with the provided ID.
Java
StringsearchQuery="SELECT ad_group.id, ad_group.name, ad_group.targeting_setting.target_restrictions "+"FROM ad_group "+"WHERE ad_group.id = "+adGroupId;
C#
stringquery=$@" SELECT ad_group.id, ad_group.name, ad_group.targeting_setting.target_restrictions FROM ad_group WHERE ad_group.id = {adGroupId}";
PHP
$query = "SELECT ad_group.id, ad_group.name, " . "ad_group.targeting_setting.target_restrictions " . "FROM ad_group " . "WHERE ad_group.id = $adGroupId";
Python
query=f""" SELECT ad_group.id, ad_group.name, ad_group.targeting_setting.target_restrictions FROM ad_group WHERE ad_group.id ={ad_group_id}"""
Ruby
query=<<~QUERYSELECTad_group.id,ad_group.name,ad_group.targeting_setting.target_restrictionsFROMad_groupWHEREad_group.id=#{ad_group_id}QUERY
Perl
my$query="SELECT ad_group.id, ad_group.name, "."ad_group.targeting_setting.target_restrictions FROM ad_group "."WHERE ad_group.id = $ad_group_id";
Next, loop through the target restrictions and reconstruct theTargetingSetting
objects. If the code encounters aTargetRestriction
with atargeting_dimension
ofAUDIENCE
and abid_only
value offalse
, itupdates theTargetRestriction
object'sbid_only
field totrue
(or"Observation") and add it to ourTargetingSetting
object.
Otherwise, add theTargetRestriction
object as returned from the server to theTargetingSetting
. It is important to note that you must reconstruct and passthe entireTargetingSetting
object back to Google Ads. Google assumes that anytarget_restrictions
missing from theTargetingSetting
should be removed.
Java
for(TargetRestrictiontargetRestriction:targetRestrictions){TargetingDimensiontargetingDimension=targetRestriction.getTargetingDimension();booleanbidOnly=targetRestriction.getBidOnly();System.out.printf("- Targeting restriction with targeting dimension '%s' and bid only set to '%b'.%n",targetingDimension,bidOnly);// 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.if(!targetingDimension.equals(TargetingDimension.AUDIENCE)){targetingSettingBuilder.addTargetRestrictions(targetRestriction);}elseif(!bidOnly){shouldUpdateTargetingSetting=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.targetingSettingBuilder.addTargetRestrictions(TargetRestriction.newBuilder().setTargetingDimensionValue(TargetingDimension.AUDIENCE_VALUE).setBidOnly(true));}}
C#
foreach(TargetRestrictiontargetRestrictionintargetRestrictions){TargetingDimensiontargetingDimension=targetRestriction.TargetingDimension;boolbidOnly=targetRestriction.BidOnly;Console.WriteLine("\tTargeting restriction with targeting dimension "+$"'{targetingDimension}' and bid only set to '{bidOnly}'.");// 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(targetingDimension!=TargetingDimension.Audience){targetingSetting.TargetRestrictions.Add(targetRestriction);}elseif(!bidOnly){shouldUpdateTargetingSetting=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.targetingSetting.TargetRestrictions.Add(newTargetRestriction{TargetingDimension=TargetingDimension.Audience,BidOnly=true});}}
PHP
foreach ( $adGroup->getTargetingSetting()->getTargetRestrictions() as $targetRestriction) { // Prints the results. $targetingDimension = $targetRestriction->getTargetingDimension(); $bidOnly = $targetRestriction->getBidOnly(); printf( "- Targeting restriction with targeting dimension '%s' and bid only set to " . "'%s'.%s", TargetingDimension::name($targetingDimension), $bidOnly ? 'true' : 'false', PHP_EOL ); // 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. if ($targetingDimension !== TargetingDimension::AUDIENCE) { $targetRestrictions[] = $targetRestriction; } elseif (!$bidOnly) { $shouldUpdateTargetingSetting = 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. $targetRestrictions[] = new TargetRestriction([ 'targeting_dimension' => TargetingDimension::AUDIENCE, 'bid_only' => true ]); }}
Python
fortarget_restrictionintarget_restrictions:targeting_dimension=target_restriction.targeting_dimensionbid_only=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=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=targeting_setting.target_restrictions.add()new_target_restriction.targeting_dimension=(targeting_dimension_enum.AUDIENCE)new_target_restriction.bid_only=True
Ruby
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
Perl
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::V20::Common::TargetRestriction->new({targetingDimension=>AUDIENCE,bidOnly=>"true"});push@{$targeting_setting->{targetRestrictions}},$new_restriction;}}
Finally, if the code encounters a target restriction that requires updating, itupdates the ad group with the new targeting settings.
Java
privatevoidupdateTargetingSetting(GoogleAdsClientgoogleAdsClient,longcustomerId,longadGroupId,TargetingSettingtargetingSetting){// Creates the ad group service client.try(AdGroupServiceClientadGroupServiceClient=googleAdsClient.getLatestVersion().createAdGroupServiceClient()){// Creates an ad group object with the proper resource name and updated targeting setting.AdGroupadGroup=AdGroup.newBuilder().setResourceName(ResourceNames.adGroup(customerId,adGroupId)).setTargetingSetting(targetingSetting).build();// Constructs 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.AdGroupOperationoperation=AdGroupOperation.newBuilder().setUpdate(adGroup).setUpdateMask(FieldMasks.allSetFieldsOf(adGroup)).build();// Sends the operation in a mutate request.MutateAdGroupsResponseresponse=adGroupServiceClient.mutateAdGroups(Long.toString(customerId),ImmutableList.of(operation));// Prints the resource name of the updated object.System.out.printf("Updated targeting setting of ad group with resource name '%s'; set the AUDIENCE "+"target restriction to 'Observation'.%n",response.getResults(0).getResourceName());}}
C#
privatevoidUpdateTargetingSetting(GoogleAdsClientclient,longcustomerId,longadGroupId,TargetingSettingtargetingSetting){// Get the AdGroupService client.AdGroupServiceClientadGroupServiceClient=client.GetService(Services.V20.AdGroupService);// Create an ad group object with the updated targeting setting.AdGroupadGroup=newAdGroup{ResourceName=ResourceNames.AdGroup(customerId,adGroupId),TargetingSetting=targetingSetting};// Construct 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.AdGroupOperationoperation=newAdGroupOperation{Update=adGroup,UpdateMask=FieldMasks.AllSetFieldsOf(adGroup)};// Send the operation in a mutate request.MutateAdGroupsResponseresponse=adGroupServiceClient.MutateAdGroups(customerId.ToString(),new[]{operation});// Print the resource name of the updated object.Console.WriteLine("Updated targeting setting of ad group with resource name "+$"'{response.Results.First().ResourceName}'; set the AUDIENCE target restriction "+"to 'Observation'.");}
PHP
private static function updateTargetingSetting( GoogleAdsClient $googleAdsClient, int $customerId, int $adGroupId, TargetingSetting $targetingSetting) { // Creates an ad group object with the proper resource name and updated targeting setting. $adGroup = new AdGroup([ 'resource_name' => ResourceNames::forAdGroup($customerId, $adGroupId), 'targeting_setting' => $targetingSetting ]); // Constructs an operation that will update the ad group with the specified resource name, // 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. $adGroupOperation = new AdGroupOperation(); $adGroupOperation->setUpdate($adGroup); $adGroupOperation->setUpdateMask(FieldMasks::allSetFieldsOf($adGroup)); // Issues a mutate request to update the ad group. $adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient(); $response = $adGroupServiceClient->mutateAdGroups( MutateAdGroupsRequest::build($customerId, [$adGroupOperation]) ); // Prints the resource name of the updated ad group. printf( "Updated targeting setting of ad group with resource name '%s'; set the AUDIENCE " . "target restriction to 'Observation'.%s", $response->getResults()[0]->getResourceName(), PHP_EOL );}
Python
defupdate_targeting_setting(client,customer_id,ad_group_id,targeting_setting):"""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 targeting restriction. targeting_setting: The updated targeting setting. """# Get the AdGroupService client.ad_group_service=client.get_service("AdGroupService")# Construct an operation that will update the ad group.ad_group_operation=client.get_type("AdGroupOperation")# Populate the ad group object with the updated targeting setting.ad_group=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=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'.")
Ruby
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
Perl
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::V20::Resources::AdGroup->new({resourceName=>Google::Ads::GoogleAds::V20::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::V20::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};}
The process for setting thebid_only
field for campaigns is nearly identical.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-11 UTC.