The Targeting Options, Assigned Targeting Options, and Line items services are all used in conjunction to set line item targeting in the Display & Video 360 API. This page describes and gives examples of how to find available targeting options, assign targeting options to line items, and execute bulk operations on line items to list and edit assigned targeting options.
Find available targeting options
Targeting options use either user-specified variables, existing targetable entities, or pre-existing options to define the desired targeted audience. Pre-existing options are identified using either enum values or targeting option IDs, depending on the targeting type. Targetable entities are identified using their entity IDs. Targeting option IDs and entity IDs can be found using the Display & Video 360 API.
Use set enum values
Targeting options for the following targeting types are assigned using specific enum types:
TargetingType |
Enum |
---|---|
TARGETING_TYPE_AGE_RANGE |
AgeRange |
TARGETING_TYPE_CONTENT_INSTREAM_POSITION |
ContentInstreamPosition |
TARGETING_TYPE_CONTENT_OUTSTREAM_POSITION |
ContentOutstreamPosition |
TARGETING_TYPE_DEVICE_TYPE |
DeviceType |
TARGETING_TYPE_DIGITAL_CONTENT_LABEL_EXCLUSION |
ContentRatingTier |
TARGETING_TYPE_ENVIRONMENT |
Environment |
TARGETING_TYPE_EXCHANGE |
Exchange |
TARGETING_TYPE_GENDER |
Gender |
TARGETING_TYPE_HOUSEHOLD_INCOME |
HouseholdIncome |
TARGETING_TYPE_NATIVE_CONTENT_POSITION |
NativeContentPosition |
TARGETING_TYPE_OMID |
Omid |
TARGETING_TYPE_PARENTAL_STATUS |
ParentalStatus |
TARGETING_TYPE_SENSITIVE_CATEGORY_EXCLUSION |
SensitiveCategory |
TARGETING_TYPE_VIDEO_PLAYER_SIZE |
VideoPlayerSize |
TARGETING_TYPE_VIEWABILITY |
Viewability |
A string version of the relevant enum value can be used to identify existing
AssignedTargetingOption
resources of these targeting types and is
available in the assignedTargetingOptionIdAlias
field. You can
use this alias value in place of the assignedTargetingOptionId
when
retrieving or deleting assigned targeting options.
Retrieve targeting option IDs
Targeting types that use pre-existing options are assigned using corresponding targeting option IDs.
For example, there are a finite number of positions on screen that
can be targeted using targeting type TARGETING_TYPE_ON_SCREEN_POSITION
. Each
of these position have a corresponding targeting option ID.
These targeting option IDs can be retrieved through the Targeting Options service. Depending on the targeting type, retrieval is done in one of two ways:
- Individual retrieval or exhaustive list: Retrieval of options for the
majority of targeting types can be done using the
get
andlist
methods. UsetargetingTypes.targetingOptions.get
to retrieve the details of a targeting option identified by a targeting type and targeting option ID. UsetargetingTypes.targetingOptions.list
to list all available targeting options of a given targeting type. - Search: Options for a location-based targeting types
(
TARGETING_TYPE_GEO_REGION
,TARGETING_TYPE_POI
andTARGETING_TYPE_BUSINESS_CHAIN
) must be retrieved using thesearch
method. UsetargetingTypes.targetingOptions.search
to retrieve targeting options of a given type that match given query strings.
Here's an example of how to retrieve a list of possible targeting
options for targeting type TARGETING_TYPE_BROWSER
:
Java
// Configure the list request. TargetingOptions.List request = service .targetingTypes() .targetingOptions() .list("TARGETING_TYPE_BROWSER") .setAdvertiserId(advertiser-id); // Create the response and nextPageToken variables. ListTargetingOptionsResponse response; String nextPageToken = null; do { // Create and execute the list request. response = request.setPageToken(nextPageToken).execute(); // Check if the response is empty. if (response.isEmpty()) { System.out.print("List request returned no Targeting Options"); break; } // Iterate over retrieved targeting options. for (TargetingOption option : response.getTargetingOptions()) { System.out.printf( "Targeting Option ID: %s, Browser Display Name: '%s'\n", option.getTargetingOptionId(), option.getBrowserDetails().getDisplayName()); } // Update the next page token. nextPageToken = response.getNextPageToken(); } while (!Strings.isNullOrEmpty(nextPageToken));
Python
# Create the page token variable. next_page_token = "" while True: # Request the targeting options list. response = service.targetingTypes() \ .targetingOptions().list( advertiserId=advertiser-id, targetingType="TARGETING_TYPE_BROWSER", pageToken=next_page_token ).execute() # Check if response is empty. if not response: print("List request returned no Targeting Options") break # Iterate over retrieved targeting options. for option in response['targetingOptions']: print("Targeting Option ID: %s, Browser Display Name: %s" % (option['targetingOptionId'], option['browserDetails']['displayName'])) # Break out of loop if there is no next page. if 'nextPageToken' not in response: break # Update the next page token. next_page_token = response['nextPageToken']
PHP
// Create the page token variable. $nextPageToken = null; do { // Build the query parameters object for the request. $optParams = array( 'advertiserId' => advertiser-id, 'pageToken' => $nextPageToken ); // Call the API, getting the browser targeting options for the // identified advertiser. $response = $this ->service ->targetingTypes_targetingOptions ->listTargetingTypesTargetingOptions( 'TARGETING_TYPE_BROWSER', $optParams ); // Print the resulting targeting options. if (!empty($response->getTargetingOptions())) { foreach ($response->getTargetingOptions() as $option) { printf( 'Targeting Option ID: %s, Browser Display Name: %s\n', $option['targetingOptionId'], $option['browserDetails']['displayName'] ); } } else { print('No targeting options returned\n'); } // Update the next page token. $nextPageToken = $response->getNextPageToken(); } while ( !empty($response->getTargetingOptions()) && $nextPageToken );
List targetable entities
In order to target a line item using an existing targetable entity, you need the ID of that entity. Targetable entities, such as channels, combined audiences, and inventory source groups, are retrievable through their own services in the Display & Video 360 API.
Each service has its own get
and list
methods. Use the get
method to
confirm that an entity is available under a given advertiser. Use the list
method to discover all entities of that resource type that are available to a
given advertiser and, therefore, able to be used in assigning targeting to a
line item under that advertiser.
A subset of targetable entities can also be managed through the API. This is
done through the create
and patch
methods in the corresponding service, as
well as services for the individual values listed in the entities, such as
inventory sources,
negative keywords, and
locations.
Build POI targeting option IDs
Named points of interest targeting options, under TARGETING_TYPE_POI
can be
retrieved using targetingTypes.targetingOptions.search
. In
addition, you can build bespoke TARGETING_TYPE_POI
targeting option IDs to
target specific latitude-longitude coordinates.
Follow these steps to build a POI targeting option ID:
- Retrieve latitude-longitude coordinates (ex: "40.7414691, -74.003387")
- Round coordinate values to the sixth decimal place (ex: "40.741469, -74.003387")
- Remove the decimal places from the coordinate values (ex: "40741469, -74003387")
- Concatenate the two values to make a single string, separated by a semicolon (ex: "40741469;-74003387")
The resulting string can be used as a targetingOptionId
when creating a
TARGETING_TYPE_POI
assigned targeting option.
Upon creation, the targetingOptionId
and assignedTargetingOptionId
fields of
the assigned targeting option resource will be updated, appending a semicolon
and alphanumeric hash.
Assign a targeting option
Targeting assigned to a line item is represented as an Assigned Targeting Option. You can manage these entities using the Assigned Targeting Options service. Creating an assigned targeting option applies those targeting details to the parent line item. Deleting an existing assigned targeting option removes that targeting.
Use
advertisers.lineItems.targetingTypes.assignedTargetingOptions.create
to create assigned targeting options. Specify the targeting parameters in the
details
field of the assigned targeting option resource that
corresponds to its intended targeting type.
Here's an example of how to create an assigned targeting option
of targeting type TARGETING_TYPE_BROWSER
:
Java
// Create an AssignedTargetingOption object of the // browser targeting type. AssignedTargetingOption assignedTargetingOption = new AssignedTargetingOption() .setBrowserDetails( new BrowserAssignedTargetingOptionDetails() .setTargetingOptionId(targeting-option-id)); // Configure the create request. AssignedTargetingOptions.Create request = service .advertisers() .lineItems() .targetingTypes() .assignedTargetingOptions() .create( advertiser-id, line-item-id, "TARGETING_TYPE_BROWSER", assignedTargetingOption); // Send the request. AssignedTargetingOption response = request.execute(); // Display the new assigned targeting option. System.out.printf("AssignedTargetingOption %s was created.", response.getName());
Python
# Create a assigned targeting option object. assigned_targeting_option_obj = { 'browserDetails': { 'targetingOptionId': targeting-option-id } } # Create the assigned targeting option. assigned_targeting_option = service.advertisers().lineItems()\ .targetingTypes().assignedTargetingOptions().create( advertiserId=advertiser-id, lineItemId=line-item-id, targetingType="TARGETING_TYPE_BROWSER", body=assigned_targeting_option_obj ).execute() # Display the new assigned targeting option. print("Assigned Targeting Option %s was created." % assigned_targeting_option["name"])
PHP
// Create a assigned targeting option object. $assignedTargetingOption = new Google_Service_DisplayVideo_AssignedTargetingOption(); // Create and set browser details. $details = new Google_Service_DisplayVideo_BrowserAssignedTargetingOptionDetails(); $details->setTargetingOptionId(targeting-option-id); $assignedTargetingOption->setBrowserDetails($details); // Call the API, creating the browser assigned targeting option for the // given line item. $result = $this ->service ->advertisers_lineItems_targetingTypes_assignedTargetingOptions ->create( advertiser-id, line-item-id, 'TARGETING_TYPE_BROWSER', $assignedTargetingOption ); printf( 'Assigned Targeting Option %s was created.\n', $result['name'] );
Errors
Targeting configuration errors
There are a number of intricate rules regarding targeting in Display & Video 360. These are enforced in the Display & Video 360 API through errors returned on assigned targeting option creation. The error returned by the API will specify the violation.
Errors are mostly caused by existing targeting assigned to a line item. Use
advertisers.lineItems.targetingTypes.assignedTargetingOptions.list
to retrieve all targeting options of a given targeting type assigned to a line
item, assess whether the desired targeting is possible given the limitations,
and use
advertisers.lineItems.targetingTypes.assignedTargetingOptions.delete
to remove any unwanted targeting before again attempting to create the desired
assigned targeting option.
YouTube & Partners targeting errors
Targeting specifically for YouTube & Partners campaigns cannot be updated using the Display & Video 360 API and attempting to do so will result in error.
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
Concurrency errors
Attempting to update the settings or targeting of a single line item through multiple concurrent requests will result in error.
If you need to add or remove multiple assigned targeting options for a single
line item at the same time, you should use a
bulk edit request. If you want to update a line item's
settings and targeting, make the advertisers.lineItems.patch
request and relevant targeting request consecutively to ensure the second
request isn't sent until the first returns a response.
Bulk and resource-wide targeting operations
You can use bulk and resource-wide targeting methods to manage assigned targeting options across targeting types:
- Use bulk targeting methods to retrieve or edit targeting options across
multiple targeting types and under multiple resources. You can retrieve the
full targeting configurations of multiple line items using
advertisers.lineItems.bulkListAssignedTargetingOptions
or make identical updates to targeting across multiple line items usingadvertisers.lineItems.bulkEditAssignedTargetingOptions
. These are only available in theadvertisers.lineItems
service. - Use Resource-wide targeting methods to retrieve or edit targeting options
across multiple targeting types under a single resource. These are available
in
partners
,advertisers
,advertisers.campaigns
, andadvertisers.insertionOrders
services and are namedlistAssignedTargetingOptions
oreditAssignedTargetingOptions
.
If you want a complete view of a line item’s current targeting, want to apply a pre-set targeting configuration to a line item, or need to make multiple changes to the targeting of a line item simultaneously, consider using these targeting methods.
List targeting in bulk
advertisers.lineItems.bulkListAssignedTargetingOptions
provides a way to look at all targeting assigned to one or more line items
across varying targeting types. It operates similarly to any other list
method. You can use the filter
query parameter to filter
the results by TargetingType
or
Inheritance
.
Here's an example of how to list all targeting options assigned to a line item that are inherited by the parent partner or advertiser:
Java
// Configure the bulk list request. LineItems.BulkListAssignedTargetingOptions request = service.advertisers().lineItems() .bulkListAssignedTargetingOptions(advertiser-id); // Set Line Items to retrieve targeting for. request.setLineItemIds(line-item-ids); // Set filter to only return inherited assigned targeting options. request.setFilter( "inheritance=\"INHERITED_FROM_ADVERTISER\" OR inheritance=\"INHERITED_FROM_PARTNER\""); // Create the response and nextPageToken variables. BulkListAssignedTargetingOptionsResponse response; String nextPageToken = null; do { // Set page token and execute the list request. response = request.setPageToken(nextPageToken).execute(); // Check if the response is empty. if (response.isEmpty()) { System.out.print("Bulk list request returned no Assigned Targeting Options"); break; } // Iterate over retrieved line item assigned targeting option wrapper objects. for (LineItemAssignedTargetingOption lineItemAssignedTargetingOption : response.getLineItemAssignedTargetingOptions()) { System.out.printf( "Assigned Targeting Option %s found\n", lineItemAssignedTargetingOption.getAssignedTargetingOption().getName()); } // Update the next page token. nextPageToken = response.getNextPageToken(); } while (!Strings.isNullOrEmpty(nextPageToken));
Python
# Create the page token variable. next_page_token = "" while True: # Execute the list request. response = service.advertisers().lineItems() \ .bulkListAssignedTargetingOptions( advertiserId=advertiser-id, lineItemIds=line-item-ids, filter="inheritance=\"INHERITED_FROM_ADVERTISER\" OR " "inheritance=\"INHERITED_FROM_PARTNER\"", pageToken=next_page_token ).execute() # Check if response is empty. if not response: print("Bulk list request returned no Assigned Targeting Options") break # Iterate over retrieved assigned targeting options. for lineItemAssignedTargetingOption in response['lineItemAssignedTargetingOptions']: print("Assigned Targeting Option %s found" % (lineItemAssignedTargetingOption['assignedTargetingOption']['name'])) # Break out of loop if there is no next page. if 'nextPageToken' not in response: break # Update the next page token. next_page_token = response['nextPageToken']
PHP
// Create the page token variable. $nextPageToken = null; do { // Build the query parameters object for the request. $optParams = array( 'lineItemIds' => line-item-ids, 'filter' => "inheritance=\"INHERITED_FROM_ADVERTISER\" OR " . "inheritance=\"INHERITED_FROM_PARTNER\"", 'pageToken' => $nextPageToken ); // Call the API, getting all the assigned targeting options for the // identified line item. $response = $service ->advertisers_lineItems ->bulkListAssignedTargetingOptions( advertiser-id, $optParams ); // Print the returned assigned targeting options. if (!empty($response->getLineItemAssignedTargetingOptions())) { foreach ($response->getLineItemAssignedTargetingOptions() as $option) { printf('Assigned Targeting Option %s found\n', $option->getAssignedTargetingOption()['name']); } } else { print('No targeting options returned\n'); } // Update the next page token. $nextPageToken = $response->getNextPageToken(); } while ( !empty($response->getLineItemAssignedTargetingOptions()) && $nextPageToken);
Edit targeting in bulk
advertisers.lineItems.bulkEditAssignedTargetingOptions
provides a way to add and remove multiple targeting options of various targeting
types from one or more line items simultaneously.
The method takes a list of
DeleteAssignedTargetingOptionsRequests
and a list of
CreateAssignedTargetingOptionsRequests
. A single request
object can represent the deletion or creation of multiple assigned targeting
options of the same targeting type.
If the attempted deletion or creation of an assigned targeting option causes an error for a line item, the bulk action is abandoned for that line item. The request returns a list of successfully-updated line items, as well as lists of line items that failed to update and the relevant errors.
Here's an example of how to bulk edit assigned targeting options for one or more line items given lists of assigned targeting options to delete and targeting options to create:
Java
// Create a bulk edit request. BulkEditAssignedTargetingOptionsRequest requestContent = new BulkEditAssignedTargetingOptionsRequest(); // Set line item IDs in edit request. requestContent.setLineItemIds(line-item-ids); // Build delete request list. ArrayList<DeleteAssignedTargetingOptionsRequest> deleteRequests = new ArrayList<DeleteAssignedTargetingOptionsRequest>(); // Add browser assigned targeting option IDs to delete request list. deleteRequests.add(new DeleteAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_BROWSER") .setAssignedTargetingOptionIds(delete-browser-assigned-targeting-ids)); // Add device make or model assigned targeting option IDs to delete request list. deleteRequests.add(new DeleteAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_DEVICE_MAKE_MODEL") .setAssignedTargetingOptionIds( delete-device-make-model-assigned-targeting-ids)); // Set delete requests in edit request. requestContent.setDeleteRequests(deleteRequests); // Build create request list. ArrayList<CreateAssignedTargetingOptionsRequest> createRequests = new ArrayList<CreateAssignedTargetingOptionsRequest>(); // Create browser assigned targeting option create request. CreateAssignedTargetingOptionsRequest createBrowserTargetingRequest = new CreateAssignedTargetingOptionsRequest(); createBrowserTargetingRequest.setTargetingType("TARGETING_TYPE_BROWSER"); // Create and set list of browser assigned targeting options. ArrayList<AssignedTargetingOption> createBrowserAssignedTargetingOptions = new ArrayList<AssignedTargetingOption>(); for (String targetingOptionId : create-browser-assigned-targeting-ids) { createBrowserAssignedTargetingOptions.add(new AssignedTargetingOption() .setBrowserDetails( new BrowserAssignedTargetingOptionDetails() .setTargetingOptionId(targetingOptionId))); } createBrowserTargetingRequest .setAssignedTargetingOptions(createBrowserAssignedTargetingOptions); // Add browser assigned targeting options to list of create requests. createRequests.add(createBrowserTargetingRequest); // Set create requests in edit request. requestContent.setCreateRequests(createRequests); // Configure the bulk edit request. LineItems.BulkEditAssignedTargetingOptions request = service.advertisers().lineItems() .bulkEditAssignedTargetingOptions( advertiser-id, requestContent); // Execute bulk edit request. BulkEditAssignedTargetingOptionsResponse response = request.execute(); // Check if any line items updated successfully. if (response.getUpdatedLineItemIds() == null || response.getUpdatedLineItemIds().isEmpty()) { System.out.println("No line items were updated successfully."); } else { System.out.printf( "Targeting configurations for the following line item IDs were updated: %s.\n", Arrays.toString(response.getUpdatedLineItemIds().toArray())); } // Check if any line items failed to update. if (response.getFailedLineItemIds() == null || response.getFailedLineItemIds().isEmpty()) { System.out.println("No line items failed to update."); } else { // Print the line items that failed to update. System.out.printf( "Targeting configurations for the following line item IDs failed to update: %s.\n", Arrays.toString(response.getFailedLineItemIds().toArray())); // Print errors thrown for failed updates. System.out.println("The failed updates were caused by the following errors:"); for (Status error : response.getErrors()) { System.out.printf("Error Code: %s, Message: %s\n", error.getCode(), error.getMessage()); } }
Python
# Build assigned targeting option objects to create. createBrowserAssignedTargetingOptions = [] for targeting_id in create-browser-assigned-targeting-ids: createBrowserAssignedTargetingOptions.append( {'browserDetails': {'targetingOptionId': targeting_id}} ) # Create a bulk edit request. bulk_edit_line_item_request = { 'lineItemIds': line-item-ids, 'deleteRequests': [ { 'targetingType': 'TARGETING_TYPE_BROWSER', 'assignedTargetingOptionIds': delete-browser-assigned-targeting-ids }, { 'targetingType': 'TARGETING_TYPE_DEVICE_MAKE_MODEL', 'assignedTargetingOptionIds': delete-device-make-model-assigned-targeting-ids } ], 'createRequests': [ { 'targetingType': 'TARGETING_TYPE_BROWSER', 'assignedTargetingOptions': createBrowserAssignedTargetingOptions } ] } # Edit the line item targeting. response = service.advertisers().lineItems()\ .bulkEditAssignedTargetingOptions( advertiserId=advertiser-id, body=bulk_edit_line_item_request ).execute() # Print successfully updated line items. if 'updatedLineItemIds' not in response: print("No line items were updated successfully.") else: print("Targeting configurations for the following line item IDs were updated: %s" % response['updatedLineItemIds']) # Print line items that failed to update. if 'failedLineItemIds' not in response: print("No line items failed to update.") else: print("Targeting configurations for the following line item IDs failed to update: %s" % response['failedLineItemIds']) if 'errors' in response: print("The failed updates were caused by the following errors:") for error in response["errors"]: print("Error code: %s, Message: %s" % (error["code"], error["message"]))
PHP
// Create delete request list. $deleteRequests = array(); // Create and add browser assigned targeting option IDs to delete request list. $deleteBrowserTargetingRequest = new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest(); $deleteBrowserTargetingRequest->setTargetingType( "TARGETING_TYPE_BROWSER" ); $deleteBrowserTargetingRequest->setAssignedTargetingOptionIds( delete-browser-assigned-targeting-ids ); $deleteRequests[] = $deleteBrowserTargetingRequest; // Create and add device assigned targeting option IDs to delete request list. $deleteDeviceTargetingRequest = new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest(); $deleteDeviceTargetingRequest->setTargetingType( "TARGETING_TYPE_DEVICE_MAKE_MODEL" ); $deleteDeviceTargetingRequest->setAssignedTargetingOptionIds( delete-device-make-model-assigned-targeting-ids ); $deleteRequests[] = $deleteDeviceTargetingRequest; // Create create request list. $createRequests = array(); // Create and populate list of browser assigned targetion options to create. $createBrowserAssignedTargetingOptions = array(); foreach (create-browser-assigned-targeting-ids as $optionId) { $option = new Google_Service_DisplayVideo_AssignedTargetingOption(); $details = new Google_Service_DisplayVideo_BrowserAssignedTargetingOptionDetails(); $details->setTargetingOptionId($optionId); $option->setBrowserDetails($details); $createBrowserAssignedTargetingOptions[] = $option; } // Create and add browser assigned targeting option create request to create // request list. $createBrowserTargetingRequest = new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest(); $createBrowserTargetingRequest->setTargetingType( "TARGETING_TYPE_BROWSER" ); $createBrowserTargetingRequest->setAssignedTargetingOptions( $createBrowserAssignedTargetingOptions ); $createRequests[] = $createBrowserTargetingRequest; // Create a bulk edit request and assign create and delete request lists. $body = new Google_Service_DisplayVideo_BulkEditAssignedTargetingOptionsRequest(); $body->setLineItemIds(line-item-ids); $body->setCreateRequests($createRequests); $body->setDeleteRequests($deleteRequests); // Call the API, editing the assigned targeting options for the identified // line item. $response = $service ->advertisers_lineItems ->bulkEditAssignedTargetingOptions( advertiser-id, $body ); // Print successfully updated line items. if (!empty($response->getUpdatedLineItemIds())) { printf('Targeting configurations for the following line item IDs were updated:\n'); foreach ($response->getUpdatedLineItemIds() as $id) { printf('%s\n', $id); } } else { print('No line items were updated successfully.\n'); } // Print line items that failed to update. if (!empty($response->getFailedLineItemIds())) { print('Targeting configurations for the following line item IDs failed to update:\n'); foreach ($response->getFailedLineItemIds() as $id) { printf('%s\n', $id); } print('The failed updates were caused by the following errors:\n'); foreach ($response->getErrors() as $error) { printf('Error Code: %s, Message: %s\n', $error->getCode(), $error->getMessage()); } } else { print('No line items failed to update.\n'); }