系統會根據指派給父項合作夥伴、廣告主、委刊項和廣告群組的指定目標,控管需求開發廣告的放送。
使用指派給需求開發廣告活動廣告群組的指定目標,觸及理想顧客並提升廣告活動成效。
決定指定目標的指派位置
指定目標可同時指派給需求開發委刊項和廣告群組。
如要將指定目標套用至該委刊項放送的所有廣告,請為需求開發委刊項指派指定目標。否則,請為個別廣告群組指派指定目標。
依需求開發資源類型劃分的指定目標支援
每種資源類型都支援特定類型的指定目標。
以下是需求開發委刊項支援的指定類型:
TARGETING_TYPE_CARRIER_AND_ISPTARGETING_TYPE_DAY_AND_TIMETARGETING_TYPE_DEVICE_MAKE_MODELTARGETING_TYPE_DEVICE_TYPETARGETING_TYPE_GEO_REGIONTARGETING_TYPE_KEYWORDTARGETING_TYPE_LANGUAGETARGETING_TYPE_NEGATIVE_KEYWORD_LISTTARGETING_TYPE_OPERATING_SYSTEMTARGETING_TYPE_POI
以下是需求開發廣告群組支援的指定類型:
TARGETING_TYPE_AGE_RANGETARGETING_TYPE_APPTARGETING_TYPE_APP_CATEGORYTARGETING_TYPE_AUDIENCE_GROUPTARGETING_TYPE_CATEGORYTARGETING_TYPE_GENDERTARGETING_TYPE_GEO_REGIONTARGETING_TYPE_HOUSEHOLD_INCOMETARGETING_TYPE_KEYWORDTARGETING_TYPE_LANGUAGETARGETING_TYPE_PARENTAL_STATUSTARGETING_TYPE_URLTARGETING_TYPE_YOUTUBE_CHANNELTARGETING_TYPE_YOUTUBE_VIDEO
TARGETING_TYPE_GEO_REGION、TARGETING_TYPE_POI 和 TARGETING_TYPE_LANGUAGE 的支援取決於父項 LineItem 資源中 demandGenSettings.geoLanguageTargetingEnabled 欄位的設定。如果這個欄位為 true,指定地區和語言只能指派給上層委刊項。如果欄位為 false,這項指定目標只能指派給個別廣告群組。
尋找可用的指定目標選項
系統會根據類型識別指定目標。請使用下列其中一種方式找出指定目標選項:
- 請使用相關的列舉值,例如列舉型別
AgeRange或Exchange。 - 使用相關服務擷取可指定目標的實體,例如頻道或地點清單。
- 使用
list和search方法,為指定類型擷取指定選項 ID。
擷取現有指定目標
現有指定目標會限制可新增至委刊項或廣告群組的指定目標。
需求開發委刊項和廣告群組只會顯示沿用TARGETING_TYPE_KEYWORD的指定目標。也就是說,您必須擷取廣告主、目標和廣告群組的指定條件,才能完整掌握所有影響廣告放送的指定條件。
使用大量列出要求,擷取指定類型現有的指定目標。
擷取現有的合作夥伴和廣告主指定目標
如要取得廣告主現有的指定目標 (包括沿用的合作夥伴指定目標),請按照下列步驟操作:
Python
# Provide the ID of the advertiser. advertiser_id = advertiser-id # Create the page token variable. next_page_token = "" while True: # Execute the list request. response = ( service.advertisers() .listAssignedTargetingOptions( advertiserId=advertiser_id, pageToken=next_page_token, ) .execute() ) # If response is not empty, display the retrieved assigned targeting # options. if response: for assigned_targeting_option in response.get( "assignedTargetingOptions", [] ): ato_name = assigned_targeting_option.get( "name", None ) if ato_name: print(f"Assigned Targeting Option {ato_name}.") else: print(f"No targeting is currently assigned to {advertiser_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
擷取現有委刊項指定目標
如要將現有指定目標直接指派給委刊項,請按照下列步驟操作:
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the Demand Gen 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
擷取現有廣告群組指定目標
如要將現有的指定目標直接指派給廣告群組,請按照下列步驟操作:
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the ad group. ad_group_id = ad-group-id # Create the page token variable. next_page_token = "" while True: # Execute the list request. response = ( service.advertisers() .adGroups() .bulkListAssignedTargetingOptions( advertiserId=advertiser_id, adGroupIds=[ad_group_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( "adGroupAssignedTargetingOptions", [] ): 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 {ad_group_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
將指定目標指派給資源
您必須分別提出要求,才能更新委刊項和廣告群組指定目標。
指派委刊項指定目標
以下說明如何將下列指定目標邏輯新增至委刊項:
- 只在電腦上放送廣告。
不要針對與「冰淇淋」關鍵字相符的內容放送廣告。
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 # Build the "ice cream" negative keyword assigned targeting option. keyword_assigned_targeting_option = { "keywordDetails": {"keyword": "ice cream", "negative": True} } # Build the delete request for device type targeting to remove all device # types to only target computers. device_type_delete_request = { "targetingType": "TARGETING_TYPE_DEVICE_TYPE", "assignedTargetingOptionIds": [ "DEVICE_TYPE_SMART_PHONE", "DEVICE_TYPE_CONNECTED_TV", "DEVICE_TYPE_TABLET" ], } # Create a bulk edit request. bulk_edit_targeting_request = { "lineItemIds": [line_item_id], "createRequests": [ { "targetingType": "TARGETING_TYPE_KEYWORD", "assignedTargetingOptions": [ keyword_assigned_targeting_option ], } ], "deleteRequests": [ device_type_delete_request ] } # 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.")
指派廣告群組指定目標
如要在廣告群組中新增下列指定目標邏輯,請按照下列步驟操作:
- 僅向家長放送。
請勿針對提供的 YouTube 頻道放送廣告。
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the ad group. ad_group_id = ad-group-id # Provide the YouTube channel ID to negatively target. yt_channel_id = youtube-channel-id # Build the assigned targeting option to negatively target the given YouTube # channel. youtube_channel_assigned_targeting_options = [ { "youtubeChannelDetails": { "channelId": yt_channel_id, "negative": True } }, ] # Build the assigned targeting options to target only parents. parental_status_assigned_targeting_options = [ { "parentalStatusDetails": { "parentalStatus": "PARENTAL_STATUS_PARENT" } }, ] # Create a bulk edit request. bulk_edit_targeting_request = { "adGroupIds": [ad_group_id], "createRequests": [ { "targetingType": "TARGETING_TYPE_YOUTUBE_CHANNEL", "assignedTargetingOptions": ( youtube_channel_assigned_targeting_options ) }, { "targetingType": "TARGETING_TYPE_PARENTAL_STATUS", "assignedTargetingOptions": ( parental_status_assigned_targeting_options ), } ] } # Build and execute request. response = ( service.advertisers() .adGroups() .bulkEditAssignedTargetingOptions( advertiserId=advertiser_id, body=bulk_edit_targeting_request ) .execute() ) # Print the request results. if ( "updatedAdGroupIds" in response and len(response["updatedAdGroupIds"]) != 0 ): print( f'Targeting configurations for {response["updatedAdGroupIds"][0]} ' "were successfully updated." ) elif ( "failedAdGroupIds" in response and len(response["failedAdGroupIds"]) != 0 ): print( f'Targeting configurations for {response["failedAdGroupIds"][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.")