Một mục hàng sẽ kế thừa tiêu chí nhắm mục tiêu được chỉ định cho đối tác và nhà quảng cáo gốc của mục hàng đó.
Chỉ định tiêu chí nhắm mục tiêu khác cho một mục hàng để tập trung vào việc mua những lượt hiển thị hữu ích.
Tìm các tiêu chí nhắm mục tiêu có thể sử dụng
Tiêu chí nhắm mục tiêu được xác định dựa trên loại tiêu chí. Xác định các lựa chọn nhắm mục tiêu bằng một trong những cách sau:
- Sử dụng một giá trị enum có liên quan, chẳng hạn như với các loại enum
AgeRangehoặcExchange. - Truy xuất các thực thể có thể nhắm mục tiêu, chẳng hạn như kênh hoặc danh sách vị trí, bằng cách sử dụng dịch vụ có liên quan.
- Truy xuất mã lựa chọn nhắm mục tiêu cho một loại nhắm mục tiêu bằng cách sử dụng các phương thức
listvàsearch.
Cách truy xuất tiêu chí nhắm mục tiêu hiện có
Tiêu chí nhắm mục tiêu hiện có hạn chế những tiêu chí nhắm mục tiêu có thể được thêm vào một mục hàng. Truy xuất tiêu chí nhắm mục tiêu hiện có cho một mục hàng trên các loại tiêu chí nhắm mục tiêu bằng cách sử dụng yêu cầu danh sách hàng loạt.
Sau đây là cách lấy tiêu chí nhắm mục tiêu hiện có cho một mục hàng:
Java
// Provide the ID of the parent advertiser. long advertiserId = advertiser-id; // Provide the ID of the line item. long lineItemId = line-item-id; // Configure the list request. LineItems.BulkListAssignedTargetingOptions request = service .advertisers() .lineItems() .bulkListAssignedTargetingOptions(advertiserId) .setLineItemIds(Arrays.asList(lineItemId)); // Create the response and nextPageToken variables. BulkListAssignedTargetingOptionsResponse response; String nextPageToken = null; do { // Create and execute the list request. response = request.setPageToken(nextPageToken).execute(); // Check if response is empty. if (response.isEmpty()) { System.out.printf("No targeting is currently assigned to '%s'", lineItemId); break; } // Iterate over retrieved assigned targeting options. for (LineItemAssignedTargetingOption liAssignedOption : response.getLineItemAssignedTargetingOptions()) { System.out.printf( "Assigned Targeting Option %s found.%n", liAssignedOption.getAssignedTargetingOption().getName()); } // Update the next page token. nextPageToken = response.getNextPageToken(); } while (!Strings.isNullOrEmpty(nextPageToken));
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the line item. line_item_id = line-item-id # 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_id], pageToken=next_page_token, ) .execute() ) # If response is not empty, display the retrieved assigned targeting # options line items. if response: for assigned_option in response.get( "lineItemAssignedTargetingOptions", [] ): ato_name = assigned_option.get("assignedTargetingOption", {}).get( "name", None ) if ato_name: print(f"Assigned Targeting Option {ato_name} found.") else: print(f"No targeting is currently assigned to {line_item_id}.") sys.exit(1) # Update the next page token. # Break out of loop if there is no next page. if "nextPageToken" in response: next_page_token = response["nextPageToken"] else: break
PHP
// Provide the ID of the parent advertiser. $advertiserId = advertiser-id; // Provide the ID of the line item. $lineItemId = line-item-id; $retrievedLineItemTargeting = array(); $response = null; $nextPageToken = null; do { $optParams = array( 'lineItemIds' => array($lineItemId), 'filter' => $filter, 'pageToken' => $nextPageToken ); // Call the API, getting all the assigned targeting options for the // identified line item. try { $response = $this ->service ->advertisers_lineItems ->bulkListAssignedTargetingOptions( $advertiserId, $optParams ); } catch (\Exception $e) { $this->renderError($e); return; } if (!empty($response->getLineItemAssignedTargetingOptions())) { $retrievedLineItemTargeting = array_merge($retrievedLineItemTargeting,$response->getLineItemAssignedTargetingOptions()); } // Update the next page token. $nextPageToken = $response->getNextPageToken(); } while ( !empty($response->getLineItemAssignedTargetingOptions()) && !empty($nextPageToken) ); // Print information returned by the bulk list request. if (!empty($retrievedLineItemTargeting)) { printf("<p>The following targeting was retrieved for line item ID %s:</p><ul>", $lineItemId); foreach ($retrievedLineItemTargeting as $assignedTargetingOption) { printf( "<li>Assigned Targeting Option %s found.</li>", $assignedTargetingOption->getAssignedTargetingOption()->getName()); } print("</ul>"); } else { printf("<p>No targeting is currently assigned to '%s'</p>", $lineItemId); }
Cách chỉ định tiêu chí nhắm mục tiêu
Cập nhật tiêu chí nhắm mục tiêu cho các mục hàng trên nhiều loại tiêu chí nhắm mục tiêu bằng yêu cầu chỉnh sửa hàng loạt.
Dưới đây là cách thêm logic nhắm mục tiêu sau đây vào một mục hàng mới:
- Chỉ đặt giá thầu cho khoảng không quảng cáo được tối ưu hoá và trong trình duyệt.
- Không phân phát trên bất kỳ trang web hoặc ứng dụng nào trong các kênh được cung cấp.
Chỉ phân phát quảng cáo cho các thiết bị ở những khu vực địa lý được cung cấp.
Java
// Provide the ID of the parent advertiser. long advertiserId = advertiser-id; // Provide the ID of the line item. long lineItemId = line-item-id; // Provide the list of Channel resource IDs to negatively target. // These can be retrieved using advertisers.channels.list. List<String> negativeChannelIds = negative-channel-ids; // Provide the list of Targeting Option IDs of the geographic regions to // target. // These can be retrieved using targetingTypes.targetingOptions.search. List<String> regionIds = region-ids; // Create list of assigned targeting options to create. List<CreateAssignedTargetingOptionsRequest> createRequests = new ArrayList<>(); // Build and add the web-optimized environment assigned targeting option. AssignedTargetingOption environmentAssignedTargetingOption = new AssignedTargetingOption() .setEnvironmentDetails( new EnvironmentAssignedTargetingOptionDetails() .setEnvironment("ENVIRONMENT_WEB_OPTIMIZED")); createRequests.add( new CreateAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_ENVIRONMENT") .setAssignedTargetingOptions(Arrays.asList(environmentAssignedTargetingOption))); // Build and add list of negative channel assigned targeting options. List<AssignedTargetingOption> negativeChannelAssignedTargetingOptions = new ArrayList<>(); for (String negativeChannelId : negativeChannelIds) { negativeChannelAssignedTargetingOptions.add( new AssignedTargetingOption() .setChannelDetails( new ChannelAssignedTargetingOptionDetails() .setNegative(true) .setChannelId(Long.parseLong(negativeChannelId)))); } createRequests.add( new CreateAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_CHANNEL") .setAssignedTargetingOptions(negativeChannelAssignedTargetingOptions)); // Build and add list of geographic assigned targeting options. List<AssignedTargetingOption> geoRegionAssignedTargetingOptions = new ArrayList<>(); for (String regionId : regionIds) { geoRegionAssignedTargetingOptions.add( new AssignedTargetingOption() .setGeoRegionDetails( new GeoRegionAssignedTargetingOptionDetails().setTargetingOptionId(regionId))); } createRequests.add( new CreateAssignedTargetingOptionsRequest() .setTargetingType("TARGETING_TYPE_GEO_REGION") .setAssignedTargetingOptions(geoRegionAssignedTargetingOptions)); // Create a bulk edit request. BulkEditAssignedTargetingOptionsRequest bulkEditTargetingRequest = new BulkEditAssignedTargetingOptionsRequest() .setLineItemIds(Arrays.asList(lineItemId)) .setCreateRequests(createRequests); // Configure the bulk edit request. BulkEditAssignedTargetingOptionsResponse response = service .advertisers() .lineItems() .bulkEditAssignedTargetingOptions(advertiserId, bulkEditTargetingRequest) .execute(); // Display API response information. if (response.getUpdatedLineItemIds() != null && !response.getUpdatedLineItemIds().isEmpty()) { System.out.printf( "Targeting configurations for %s were successfully updated.%n", response.getUpdatedLineItemIds().get(0)); } if (response.getFailedLineItemIds() != null && !response.getFailedLineItemIds().isEmpty()) { System.out.printf( "Targeting configurations for %s failed to update.%n", response.getFailedLineItemIds().get(0)); } if (response.getErrors() != null && !response.getErrors().isEmpty()) { System.out.println("The failed updates were caused by the following errors:"); for (Status error : response.getErrors()) { System.out.printf("Code %s: %s%n", error.getCode(), error.getMessage()); } } else { System.out.println("No successful or failed updates were reported."); }
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the line item. line_item_id = line-item-id # Provide the list of Channel resource IDs to negatively target. # These can be retrieved using advertisers.channels.list. negative_channel_ids = negative-channel-ids # Provide the list of Targeting Option IDs of the geographic regions to target. # These can be retrieved using targetingTypes.targetingOptions.search. region_ids = region-ids # Build the web-optimized environment assigned targeting option. environment_assigned_targeting_option = { "environmentDetails": {"environment": "ENVIRONMENT_WEB_OPTIMIZED"} } # Build the negative Channel assigned targeting options. negative_channel_assigned_targeting_options = [] for id in negative_channel_ids: negative_channel_assigned_targeting_options.append( {"channelDetails": {"channelId": id, "negative": True}} ) # Build the geographic region assigned targeting options. geographic_assigned_targeting_options = [] for id in region_ids: geographic_assigned_targeting_options.append( {"geoRegionDetails": {"targetingOptionId": id}} ) # Create a bulk edit request. bulk_edit_targeting_request = { "lineItemIds": [line_item_id], "createRequests": [ { "targetingType": "TARGETING_TYPE_ENVIRONMENT", "assignedTargetingOptions": [ environment_assigned_targeting_option ], }, { "targetingType": "TARGETING_TYPE_CHANNEL", "assignedTargetingOptions": ( negative_channel_assigned_targeting_options ), }, { "targetingType": "TARGETING_TYPE_GEO_REGION", "assignedTargetingOptions": geographic_assigned_targeting_options, }, ], } # Build and execute request. response = ( service.advertisers() .lineItems() .bulkEditAssignedTargetingOptions( advertiserId=advertiser_id, body=bulk_edit_targeting_request ) .execute() ) # Print the request results. if ( "updatedLineItemIds" in response and len(response["updatedLineItemIds"]) != 0 ): print( f'Targeting configurations for {response["updatedLineItemIds"][0]} ' "were successfully updated." ) elif ( "failedLineItemIds" in response and len(response["failedLineItemIds"]) != 0 ): print( f'Targeting configurations for {response["failedLineItemIds"][0]} ' "failed to update." ) if "errors" in response and len(response["errors"]) != 0: print("The failed updates were caused by the following errors:") for error in response["errors"]: print(f'Code {error["code"]}: {error["message"]}') else: print("No successful or failed updates were reported.")
PHP
// Provide the ID of the parent advertiser. $advertiserId = advertiser-id; // Provide the ID of the line item. $lineItemId = line-item-id; // Provide the list of Channel resource IDs to negatively target. // These can be retrieved using advertisers.channels.list. $negativeChannelIds = negative-channel-ids; // Provide the list of Targeting Option IDs of the geographic regions to // target. // These can be retrieved using targetingTypes.targetingOptions.search. $regionIds = region-ids; // Create list of assigned targeting options to create. $createRequests = array(); // Build environment assigned targeting option and add to create // requests. $environmentDetails = new Google_Service_DisplayVideo_EnvironmentAssignedTargetingOptionDetails(); $environmentDetails->setEnvironment('ENVIRONMENT_WEB_OPTIMIZED'); $environmentAssignedTargetingOption = new Google_Service_DisplayVideo_AssignedTargetingOption(); $environmentAssignedTargetingOption->setEnvironmentDetails($environmentDetails); $createEnvironmentAssignedTargetingOption = new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest(); $createEnvironmentAssignedTargetingOption->setTargetingType('TARGETING_TYPE_ENVIRONMENT'); $createEnvironmentAssignedTargetingOption->setAssignedTargetingOptions(array($environmentAssignedTargetingOption)); $createRequests[] = $createEnvironmentAssignedTargetingOption; // Build negative channel assigned targeting options and add to create // requests. $channelAssignedTargetingOptions = array(); foreach ($negativeChannelIds as $channelId) { $channelDetails = new Google_Service_DisplayVideo_ChannelAssignedTargetingOptionDetails(); $channelDetails->setChannelId($channelId); $channelDetails->setNegative(true); $channelAssignedTargetingOption = new Google_Service_DisplayVideo_AssignedTargetingOption(); $channelAssignedTargetingOption->setChannelDetails($channelDetails); $channelAssignedTargetingOptions[] = $channelAssignedTargetingOption; } $createChannelAssignedTargetingOption = new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest(); $createChannelAssignedTargetingOption->setTargetingType('TARGETING_TYPE_CHANNEL'); $createChannelAssignedTargetingOption->setAssignedTargetingOptions($channelAssignedTargetingOptions); $createRequests[] = $createChannelAssignedTargetingOption; // Build region assigned targeting options and add to create requests. $regionAssignedTargetingOptions = array(); foreach ($regionIds as $regionId) { $regionDetails = new Google_Service_DisplayVideo_GeoRegionAssignedTargetingOptionDetails(); $regionDetails->setTargetingOptionId($regionId); $regionAssignedTargetingOption = new Google_Service_DisplayVideo_AssignedTargetingOption(); $regionAssignedTargetingOption->setGeoRegionDetails($regionDetails); $regionAssignedTargetingOptions[] = $regionAssignedTargetingOption; } $createRegionAssignedTargetingOption = new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest(); $createRegionAssignedTargetingOption->setTargetingType('TARGETING_TYPE_GEO_REGION'); $createRegionAssignedTargetingOption->setAssignedTargetingOptions($regionAssignedTargetingOptions); $createRequests[] = $createRegionAssignedTargetingOption; $body = new Google_Service_DisplayVideo_BulkEditAssignedTargetingOptionsRequest(); $body->setLineItemIds(array($lineItemId)); $body->setCreateRequests($createRequests); // Call the API, editing the assigned targeting options for the // identified line item. try { $response = $this ->service ->advertisers_lineItems ->bulkEditAssignedTargetingOptions( $advertiserId, $body ); } catch (\Exception $e) { $this->renderError($e); return; } // Print information returned by the bulk edit request. // List updated line item IDs. if (empty($response->getUpdatedLineItemIds())) { print '<p>No line items were successfully updated.</p>'; } else { print '<p>The targeting of the following line item IDs were ' . 'updated:</p><ul>'; foreach ($response->getUpdatedLineItemIds() as $id) { printf('<li>%s</li>',$id); } print '</ul>'; } // List line item IDs that failed to update. if (empty($response->getFailedLineItemIds())) { print '<p>No line items failed to update.</p>'; } else { print '<p>The targeting of the following line item IDs failed to ' . 'update:</p><ul>'; foreach ($response->getFailedLineItemIds() as $id) { printf('<li>%s</li>',$id); } print '</ul>'; } // List the errors thrown when the targeting was updated. if (empty($response->getErrors())) { print '<p>No errors were thrown.</p>'; } else { print '<p>The following errors were thrown when attempting to ' . 'update the targeting:</p><ul>'; foreach ($response->getErrors() as $error) { printf( '<li>%s: %s</li>', $error->getCode(), $error->getMessage() ); } print '</ul>'; }