分配定位

需求开发广告系列广告的投放由分配给父级合作伙伴、广告客户、订单项和广告组的定位条件控制。

使用分配给需求开发广告系列订单项和广告组的定位条件,以便触达理想客户并提升广告系列效果。

确定定位条件的分配位置

定位条件可以分配给需求开发广告系列订单项和广告组。

如果您希望定位条件应用于该订单项下投放的所有广告,请将定位条件分配给需求开发广告系列订单项。否则,请将定位条件分配给各个广告组。

需求开发广告系列资源类型支持的定位条件

每种资源类型都支持特定类型的定位条件。

以下是需求开发广告系列订单项支持的定位类型列表:

  • TARGETING_TYPE_CARRIER_AND_ISP
  • TARGETING_TYPE_DAY_AND_TIME
  • TARGETING_TYPE_DEVICE_MAKE_MODEL
  • TARGETING_TYPE_DEVICE_TYPE
  • TARGETING_TYPE_GEO_REGION
  • TARGETING_TYPE_KEYWORD
  • TARGETING_TYPE_LANGUAGE
  • TARGETING_TYPE_NEGATIVE_KEYWORD_LIST
  • TARGETING_TYPE_OPERATING_SYSTEM
  • TARGETING_TYPE_POI

以下是需求开发广告系列广告组支持的定位类型列表:

  • TARGETING_TYPE_AGE_RANGE
  • TARGETING_TYPE_APP
  • TARGETING_TYPE_APP_CATEGORY
  • TARGETING_TYPE_AUDIENCE_GROUP
  • TARGETING_TYPE_CATEGORY
  • TARGETING_TYPE_GENDER
  • TARGETING_TYPE_GEO_REGION
  • TARGETING_TYPE_HOUSEHOLD_INCOME
  • TARGETING_TYPE_KEYWORD
  • TARGETING_TYPE_LANGUAGE
  • TARGETING_TYPE_PARENTAL_STATUS
  • TARGETING_TYPE_URL
  • TARGETING_TYPE_YOUTUBE_CHANNEL
  • TARGETING_TYPE_YOUTUBE_VIDEO

TARGETING_TYPE_GEO_REGIONTARGETING_TYPE_POITARGETING_TYPE_LANGUAGE 的支持取决于父级 LineItem 资源中 demandGenSettings.geoLanguageTargetingEnabled 字段的设置。如果该字段为 true,则地理位置和语言定位只能分配给父级订单项。如果该字段为 false,则此定位条件只能分配给各个广告组。

查找可用的定位选项

定位条件是根据其类型来标识的。您可以使用以下任一方式来标识定位选项:

检索现有定位条件

现有定位条件会限制可以添加到订单项或广告组的定位条件。

需求开发广告系列订单项和广告组只会显示继承的 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.")