The management of resource targeting is a central feature of the Display & Video 360 API. Targeting can be assigned to multiple resource types and utilizes a number of other resources and ID spaces. This page details limitations to note and best practices to implement in your adoption of the Display & Video 360 API Assigned Targeting Options services.
Utilize targeting inheritance
Targeting assigned to some resources can be inherited by their child resources. Targeting options inherited by a child resource are retrievable but not editable on the child resource level. This enables brand safety settings and other targeting to be enforced across the entirety of a partner or advertiser.
The path of inheritance can be seen in the diagram below:
As specified in the diagram, some targeting levels only support a subset of targeting types. This means that some targeting options cannot be set at higher levels and inherited, but instead need to be set at a lower level.
Inheritance in YouTube & Partners resources
Targeting inheritance is not reflected for YouTube & Partners resources in
Display & Video 360 API. Targeting inherited by Ad Groups won't be
retrievable on the AdGroup
level and YouTube targeting
assigned to parent resources won't be inherited by child resources.
To retrieve all of the functional targeting settings for an ad group, you should retrieve the assigned targeting options for the Ad Group, the parent line item, and the parent advertiser.
Be aware of targeting assigned at line item creation
Other than inherited targeting options, most targeting can only be assigned after a line item is created. However, there are a few targeting types that have a default subset of values assigned to line items at line item creation. Those targeting types are:
Attempting to create existing or delete non-existing assigned targeting options
returns an error, so we recommend that you be aware of the full targeting suite
that is assigned to your line items upon creation. If you need to retrieve the
targeting assigned to a line item across targeting types, use
advertisers.lineItems.bulkListAssignedTargetingOptions
.
In addition, some settings are set by default when no targeting option of that
type is assigned to the resource. For example, if a resource does not have a
TARGETING_TYPE_AUTHORIZED_SELLER_STATUS
targeting option defined, that means that it is using the "Authorized Direct
Sellers and Resellers" status.
Do not expect automatic "default targeting"
In Display & Video 360, targeting set at the campaign or insertion order level is not immediately passed to their child line items. This targeting is known as "default targeting" and is used as a targeting template that is applied to line items subsequently created in the UI.
In the Display & Video 360 API, default targeting is not automatically applied to newly created line items. Basic line item creation does not copy over any campaign or insertion order level targeting. In this case, desired targeting must be applied to line items separately through assigned targeting option create or bulk edit methods.
Special methods can be an exception. For example, line items created through
advertisers.lineItems.generateDefault
copy
settings from their parent insertion order, including assigned targeting.
Similarly, line items created through duplication will be assigned the
same targeting as the original line item.
YouTube & Partners targeting cannot be modified
Targeting specifically for YouTube & Partners campaigns cannot be updated using the Display & Video 360 API.
YouTube & Partners targeting consists of all targeting assigned directly to YouTube & Partners Line Items and Ad Groups, as well as any targeting of the following targeting types:
TARGETING_TYPE_SESSION_POSITION
TARGETING_TYPE_YOUTUBE_CHANNEL
TARGETING_TYPE_YOUTUBE_VIDEO
This targeting can be updated using the Display & Video 360 UI directly or by uploading a Structured Data File.
Assign audience targeting with a single option
Targeting options for most targeting types are assigned individually. Audience
group targeting does not follow this modular convention, but instead is assigned
in a single, configurable
audience group targeting details object that lists the
IDs of audiences to include and exclude when serving ads. The
assignedTargetingOptionId
for this audience group option,
once assigned, is always "audienceGroup".
This design means that any change to audience group targeting must be done by
first deleting the existing audience group assigned
targeting option and then creating a new audience group
targeting option with the desired changes. This can be done in a single request
using
advertisers.lineItems.bulkEditAssignedTargetingOptions
.
Here's an example of how to update audience targeting in order to positively target additional Google audiences:
Java
long advertiserId = advertiser-id; long lineItemId = line-item-id List<Long> addedGoogleAudienceIds = Arrays.asList(google-audience-id-to-add,...); // Build Google audience targeting settings objects to add to audience // targeting. ArrayList<GoogleAudienceTargetingSetting> newGoogleAudienceSettings = new ArrayList<GoogleAudienceTargetingSetting>(); // Convert list of Google Audience IDs into list of settings. for (Long googleAudienceId : addedGoogleAudienceIds) { newGoogleAudienceSettings.add(new GoogleAudienceTargetingSetting() .setGoogleAudienceId(googleAudienceId)); } // Create relevant bulk edit request objects. BulkEditLineItemAssignedTargetingOptionsRequest requestContent = new BulkEditLineItemAssignedTargetingOptionsRequest(); AudienceGroupAssignedTargetingOptionDetails updatedAudienceGroupDetails; ArrayList<DeleteAssignedTargetingOptionsRequest> audienceGroupDeleteRequests = new ArrayList<DeleteAssignedTargetingOptionsRequest>(); try { // Retrieve existing audience group targeting. AssignedTargetingOption existingAudienceGroupTargetingOption = service .advertisers() .lineItems() .targetingTypes() .assignedTargetingOptions() .get( advertiserId, lineItemId, "TARGETING_TYPE_AUDIENCE_GROUP", "audienceGroup" ).execute(); // Extract existing audience group targeting details. updatedAudienceGroupDetails = existingAudienceGroupTargetingOption.getAudienceGroupDetails(); // Build and add delete request for existing audience group targeting. ArrayList<String> deleteAudienceGroupAssignedTargetingIds = new ArrayList<String>(); deleteAudienceGroupAssignedTargetingIds.add("audienceGroup"); audienceGroupDeleteRequests .add(new DeleteAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_AUDIENCE_GROUP") .setAssignedTargetingOptionIds( deleteAudienceGroupAssignedTargetingIds ) ); } catch (GoogleJsonResponseException e) { updatedAudienceGroupDetails = new AudienceGroupAssignedTargetingOptionDetails(); } // Set delete requests in edit request. requestContent.setDeleteRequests(audienceGroupDeleteRequests); // Construct new group of Google Audiences to include in targeting. GoogleAudienceGroup updatedIncludedGoogleAudienceGroup = updatedAudienceGroupDetails.getIncludedGoogleAudienceGroup(); if (updatedIncludedGoogleAudienceGroup != null) { List<GoogleAudienceTargetingSetting> updatedGoogleAudienceSettings = updatedIncludedGoogleAudienceGroup.getSettings(); updatedGoogleAudienceSettings.addAll(newGoogleAudienceSettings); updatedIncludedGoogleAudienceGroup .setSettings(updatedGoogleAudienceSettings); } else { updatedIncludedGoogleAudienceGroup = new GoogleAudienceGroup(); updatedIncludedGoogleAudienceGroup.setSettings(newGoogleAudienceSettings); } // Add new Google Audience group to audience group targeting details. updatedAudienceGroupDetails .setIncludedGoogleAudienceGroup(updatedIncludedGoogleAudienceGroup); // Create new targeting option to assign. AssignedTargetingOption newAudienceGroupTargeting = new AssignedTargetingOption(); newAudienceGroupTargeting .setAudienceGroupDetails(updatedAudienceGroupDetails); // Build audience group targeting create request and add to list of create // requests. ArrayList<AssignedTargetingOption> createAudienceGroupAssignedTargetingOptions = new ArrayList<AssignedTargetingOption>(); createAudienceGroupAssignedTargetingOptions.add(newAudienceGroupTargeting); ArrayList<CreateAssignedTargetingOptionsRequest> targetingCreateRequests = new ArrayList<CreateAssignedTargetingOptionsRequest>(); targetingCreateRequests.add(new CreateAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_AUDIENCE_GROUP") .setAssignedTargetingOptions( createAudienceGroupAssignedTargetingOptions ) ); // Set create requests in edit request. requestContent.setCreateRequests(targetingCreateRequests); // Configure and execute the bulk list request. BulkEditLineItemAssignedTargetingOptionsResponse response = service.advertisers().lineItems() .bulkEditLineItemAssignedTargetingOptions( advertiserId, lineItemId, requestContent).execute();
Python
advertiser_id = advertiser-id line_item_id = line-item-id added_google_audiences = [google-audience-id-to-add,...] # Build Google audience targeting settings objects to create. new_google_audience_targeting_settings = [] for google_audience_id in added_google_audiences: new_google_audience_targeting_settings.append( {'googleAudienceId': google_audience_id} ) # Retrieve any existing line item audience targeting. retrieved_audience_targeting = service.advertisers().lineItems( ).targetingTypes().assignedTargetingOptions().get( advertiserId=advertiser_id, lineItemId=line_item_id, targetingType="TARGETING_TYPE_AUDIENCE_GROUP", assignedTargetingOptionId="audienceGroup" ).execute() updated_audience_group_details = {} # Copy over any existing audience targeting. if 'audienceGroupDetails' in retrieved_audience_targeting: updated_audience_group_details = retrieved_audience_targeting[ 'audienceGroupDetails'] # Append the new Google audience IDs to any existing positive Google # audience targeting. if 'includedGoogleAudienceGroup' in updated_audience_group_details: updated_audience_group_details[ 'includedGoogleAudienceGroup']['settings'].extend( new_google_audience_targeting_settings) else: updated_audience_group_details['includedGoogleAudienceGroup'] = { 'settings': new_google_audience_targeting_settings } # Build bulk edit request. bulk_edit_request = { 'deleteRequests': [ { 'targetingType': "TARGETING_TYPE_AUDIENCE_GROUP", 'assignedTargetingOptionIds': [ "audienceGroup" ] } ], 'createRequests': [ { 'targetingType': "TARGETING_TYPE_AUDIENCE_GROUP", 'assignedTargetingOptions': [ {'audienceGroupDetails': updated_audience_group_details} ] } ] } # Update the audience targeting updated_audience_targeting = service.advertisers().lineItems( ).bulkEditLineItemAssignedTargetingOptions( advertiserId=advertiser_id, lineItemId=line_item_id, body=bulk_edit_request ).execute()
PHP
$advertiserId = advertiser-id; $lineItemId = line-item-id; $addedGoogleAudienceIds = array(google-audience-id-to-add,...); // Convert list of Google Audience IDs into list of Google audience // settings. $newGoogleAudienceSettings = array(); foreach ($addedGoogleAudienceIds as $googleAudienceId) { $newSetting = new Google_Service_DisplayVideo_GoogleAudienceTargetingSetting(); $newSetting->setGoogleAudienceId($googleAudienceId); $newGoogleAudienceSettings[] = $newSetting; } // Create a bulk edit request. $requestBody = new Google_Service_DisplayVideo_BulkEditLineItemAssignedTargetingOptionsRequest(); $audienceGroupDeleteRequests = array(); try { // Retrieve existing audience group targeting. $existingAudienceGroupTargetingOption = $this ->service ->advertisers_lineItems_targetingTypes_assignedTargetingOptions ->get( $advertiserId, $lineItemId, 'TARGETING_TYPE_AUDIENCE_GROUP', 'audienceGroup' ); // Extract existing audience group targeting details. $updatedAudienceGroupDetails = $existingAudienceGroupTargetingOption ->getAudienceGroupDetails(); // Build and add delete request for existing audience group // targeting. $deleteAudienceGroupAssignedTargetingIds = array(); $deleteAudienceGroupAssignedTargetingIds[] = "audienceGroup"; $audienceGroupDeleteRequest = new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest(); $audienceGroupDeleteRequest ->setTargetingType('TARGETING_TYPE_AUDIENCE_GROUP'); $audienceGroupDeleteRequest ->setAssignedTargetingOptionIds( $deleteAudienceGroupAssignedTargetingIds ); $audienceGroupDeleteRequests[] = $audienceGroupDeleteRequest; } catch (\Exception $e) { $updatedAudienceGroupDetails = new Google_Service_DisplayVideo_AudienceGroupAssignedTargetingOptionDetails(); } // Set delete requests in edit request. $requestBody->setDeleteRequests($audienceGroupDeleteRequests); // Construct new group of Google audiences to include in targeting. $updatedIncludedGoogleAudienceGroup = $updatedAudienceGroupDetails ->getIncludedGoogleAudienceGroup(); if (!empty($updatedIncludedGoogleAudienceGroup)) { // Get existing settings. $updatedGoogleAudienceSettings = $updatedIncludedGoogleAudienceGroup->getSettings(); // Add new Google audiences to existing list. $updatedGoogleAudienceSettings = array_merge( $updatedGoogleAudienceSettings, $newGoogleAudienceSettings ); // Set updated Google audience list. $updatedIncludedGoogleAudienceGroup ->setSettings($updatedGoogleAudienceSettings); } else { // Create new Google audience group. $updatedIncludedGoogleAudienceGroup = new Google_Service_DisplayVideo_GoogleAudienceGroup(); // Set list of new Google audiences for targeting. $updatedIncludedGoogleAudienceGroup ->setSettings($newGoogleAudienceSettings); } // Add new Google Audience group to audience group targeting details. $updatedAudienceGroupDetails ->setIncludedGoogleAudienceGroup( $updatedIncludedGoogleAudienceGroup ); // Create new targeting option to assign. $newAudienceGroupTargeting = new Google_Service_DisplayVideo_AssignedTargetingOption(); $newAudienceGroupTargeting ->setAudienceGroupDetails($updatedAudienceGroupDetails); // Build audience group targeting create request and add to list of // create requests. $createAudienceGroupAssignedTargetingOptions = array(); $createAudienceGroupAssignedTargetingOptions[] = $newAudienceGroupTargeting; $createAudienceGroupTargetingRequest = new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest(); $createAudienceGroupTargetingRequest->setTargetingType( "TARGETING_TYPE_AUDIENCE_GROUP" ); $createAudienceGroupTargetingRequest->setAssignedTargetingOptions( $createAudienceGroupAssignedTargetingOptions ); $createRequests[] = $createAudienceGroupTargetingRequest; // Set create requests in edit request. $requestBody->setCreateRequests($createRequests); // Call the API, editing the assigned targeting options for the // identified line item. $response = $this ->service ->advertisers_lineItems ->bulkEditLineItemAssignedTargetingOptions( $advertiserId, $lineItemId, $requestBody );
Be prepared for targeting options to be deprecated
Targeting options are not static, and a small number may be deprecated from time to time. Targeting options, once deprecated, do not affect a line item’s ad serving. After deprecation, these options will be unassigned from existing line items and requests that attempt to retrieve or assign these options will result in errors.
In order to avoid these errors, we recommend that you regularly check stored
targeting option IDs. In order to conserve quota, we recommend that you cache
regularly-used IDs. However, storing IDs means that you may not
realize a targeting option has been deprecated. For this reason, you should
regularly use targetingOptions.targetingTypes.get
to
retrieve all stored targeting option IDs to confirm that they are still
supported by Display & Video 360.
See our Announced Deprecations page for details on significant previous and upcoming deprecations.
Do not make concurrent requests updating the same line item
Attempting to update the settings or assigned targeting for a single line item using multiple concurrent requests will return an error. Applicable requests include:
advertisers.lineItems.bulkEditAssignedTargetingOptions
advertisers.lineItems.bulkUpdate
advertisers.lineItems.patch
advertisers.lineItems.targetingTypes.assignedTargetingOptions.create
advertisers.lineItems.targetingTypes.assignedTargetingOptions.delete
If you need to add or remove multiple assigned targeting options for a single
line item at the same time, you should use a single
advertisers.lineItems.bulkEditAssignedTargetingOptions
request. If you want to update a line item's settings and targeting, queue
the patch
or bulkUpdate
request and relevant
targeting request to ensure the second request isn't sent until the first
returns a response.