هدف‌گذاری را تعیین کنید

ارائه تبلیغات Demand Gen با استفاده از هدف‌گذاری اختصاص داده شده به شریک اصلی، تبلیغ‌کننده، ردیف آگهی و گروه‌های تبلیغاتی کنترل می‌شود.

از هدف‌گذاری اختصاص داده شده به یک آیتم و گروه تبلیغاتی Demand Gen برای رسیدن به مشتریان ایده‌آل خود و بهبود عملکرد کمپین استفاده کنید.

تصمیم بگیرید که هدف‌گیری خود را به کجا اختصاص دهید

هدف‌گیری را می‌توان هم به آیتم‌های خط تولید تقاضا و هم به گروه‌های تبلیغاتی اختصاص داد.

اگر می‌خواهید هدف‌گیری روی تمام تبلیغاتی که تحت یک ردیف آیتم‌های Demand Gen ارائه می‌شوند اعمال شود، آن را به یک ردیف آیتم اختصاص دهید. در غیر این صورت، هدف‌گیری را به گروه‌های تبلیغاتی مجزا اختصاص دهید.

هدف‌گذاری پشتیبانی بر اساس نوع منبع تولید تقاضا

هر نوع منبع از انواع خاصی از هدف‌گیری پشتیبانی می‌کند.

در زیر لیستی از انواع هدف‌گیری پشتیبانی‌شده توسط موارد خط تولید تقاضا آمده است:

  • 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

در زیر لیستی از انواع هدف‌گیری پشتیبانی‌شده توسط گروه‌های تبلیغاتی Demand Gen آمده است:

  • 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_REGION ، TARGETING_TYPE_POI و TARGETING_TYPE_LANGUAGE به تنظیم فیلد demandGenSettings.geoLanguageTargetingEnabled در منبع LineItem والد بستگی دارد. اگر این فیلد برابر با true باشد، هدف‌گیری موقعیت مکانی و زبانی فقط می‌تواند به آیتم خطی والد اختصاص داده شود. اگر این فیلد برابر با false باشد، این هدف‌گیری فقط می‌تواند به گروه‌های تبلیغاتی مجزا اختصاص داده شود.

گزینه‌های هدف‌گیری موجود را پیدا کنید

هدف‌گذاری بر اساس نوع آن مشخص می‌شود. گزینه‌های هدف‌گذاری را با استفاده از یکی از روش‌های زیر شناسایی کنید:

بازیابی هدف‌گذاری‌های موجود

هدف‌گیری موجود، نوع هدف‌گیری قابل اضافه شدن به یک آیتم یا گروه تبلیغاتی را محدود می‌کند.

فقط آیتم‌های خطی و گروه‌های تبلیغاتی Demand Gen هدف‌گذاری ارثی TARGETING_TYPE_KEYWORD را نشان می‌دهند. این بدان معناست که شما باید هدف‌گذاری را برای تبلیغ‌کننده، آیتم خطی و گروه تبلیغاتی بازیابی کنید تا بتوانید حسابداری کاملی از تمام هدف‌گذاری‌هایی که بر ارائه تبلیغات تأثیر می‌گذارند، داشته باشید.

با استفاده از درخواست‌های لیست انبوه، هدف‌گیری موجود را در بین انواع هدف‌گیری بازیابی کنید.

بازیابی هدف‌گیری شرکا و تبلیغ‌کنندگان فعلی

در اینجا نحوه‌ی دستیابی به هدف‌گیری موجود برای یک تبلیغ‌کننده، از جمله هدف‌گیری شریک ارثی، آورده شده است:

جاوا

// Provide the ID of the advertiser.
long advertiserId = advertiser-id;

// Configure the list request.
Advertisers.ListAssignedTargetingOptions request =
    service.advertisers().listAssignedTargetingOptions(advertiserId);

// Create the response and nextPageToken variables.
BulkListAdvertiserAssignedTargetingOptionsResponse 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 advertiser ID '%s'",
        advertiserId);
    break;
  }

  // Iterate over retrieved assigned targeting options.
  for (AssignedTargetingOption assignedTargetingOption :
      response.getAssignedTargetingOptions()) {
    System.out.printf(
        "Assigned Targeting Option %s found.%n", assignedTargetingOption.getName());
  }

  // Update the next page token.
  nextPageToken = response.getNextPageToken();
} while (!Strings.isNullOrEmpty(nextPageToken));

پایتون

# 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

پی اچ پی

// Provide the ID of the advertiser.
$advertiserId = advertiser-id;

$retrievedTargeting = array();

$response = null;
$nextPageToken = null;

do {
    $optParams = array(
        'pageToken' => $nextPageToken
    );

    // Call the API, getting all the assigned targeting options for the
    // identified advertiser.
    try {
        $response = $this
            ->service
            ->advertisers
            ->listAssignedTargetingOptions(
                $advertiserId,
                $optParams
            );
    } catch (\Exception $e) {
        $this->renderError($e);
        return;
    }

    if (!empty($response->getAssignedTargetingOptions())) {
        $retrievedTargeting = array_merge(
            $retrievedTargeting,
            $response->getAssignedTargetingOptions()
        );
    }

    // Update the next page token.
    $nextPageToken = $response->getNextPageToken();
} while (
    !empty($response->getAssignedTargetingOptions())
    && !empty($nextPageToken)
);

// Print information returned by the bulk list request.
if (!empty($retrievedTargeting)) {
    printf(
        "<p>The following targeting was retrieved for advertiser ID %s:</p><ul>",
        $advertiserId);
    foreach ($retrievedTargeting as $assignedTargetingOption) {
        printf(
            "<li>Assigned Targeting Option %s found.</li>",
            $assignedTargetingOption->getName());
    }
    print("</ul>");
} else {
    printf(
        "<p>No targeting is currently assigned to advertiser ID %s.</p>",
        $advertiserId);
}

بازیابی هدف‌گذاری آیتم‌های خطی موجود

در اینجا نحوه اختصاص مستقیم هدف‌گذاری موجود به یک آیتم خطی آورده شده است:

جاوا

// Provide the ID of the 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));

پایتون

# 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

پی اچ پی

// Provide the ID of the 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 line item ID %s.</p>",
        $lineItemId);
}

بازیابی هدف‌گذاری گروه‌های تبلیغاتی موجود

در اینجا نحوه اختصاص مستقیم هدف‌گیری موجود به یک گروه تبلیغاتی آورده شده است:

جاوا

// Provide the ID of the parent advertiser.
long advertiserId = advertiser-id;

// Provide the ID of the ad group.
long adGroupId = ad-group-id;

// Configure the list request.
AdGroups.BulkListAssignedTargetingOptions request =
    service
        .advertisers()
        .adGroups()
        .bulkListAssignedTargetingOptions(advertiserId)
        .setAdGroupIds(Arrays.asList(adGroupId));

// Create the response and nextPageToken variables.
BulkListAdGroupAssignedTargetingOptionsResponse 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'",
        adGroupId);
    break;
  }

  // Iterate over retrieved assigned targeting options.
  for (AdGroupAssignedTargetingOption adGroupAssignedOption :
      response.getAdGroupAssignedTargetingOptions()) {
    System.out.printf(
        "Assigned Targeting Option %s found.%n",
        adGroupAssignedOption.getAssignedTargetingOption().getName());
  }

  // Update the next page token.
  nextPageToken = response.getNextPageToken();
} while (!Strings.isNullOrEmpty(nextPageToken));

پایتون

# 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

پی اچ پی

// Provide the ID of the parent advertiser.
$advertiserId = advertiser-id;

// Provide the ID of the ad group.
$adGroupId = line-item-id;

$retrievedAdGroupTargeting = array();

$response = null;
$nextPageToken = null;

do {
    $optParams = array(
        'adGroupIds' => array($adGroupId),
        'pageToken' => $nextPageToken
    );

    // Call the API, getting all the assigned targeting options for the
    // identified ad group.
    try {
        $response = $this
            ->service
            ->advertisers_adGroups
            ->bulkListAssignedTargetingOptions(
                $advertiserId,
                $optParams
            );
    } catch (\Exception $e) {
        $this->renderError($e);
        return;
    }

    if (!empty($response->getAdGroupAssignedTargetingOptions())) {
        $retrievedAdGroupTargeting = array_merge(
            $retrievedAdGroupTargeting,
            $response->getAdGroupAssignedTargetingOptions()
        );
    }

    // Update the next page token.
    $nextPageToken = $response->getNextPageToken();
} while (
    !empty($response->getAdGroupAssignedTargetingOptions())
    && !empty($nextPageToken)
);

// Print information returned by the bulk list request.
if (!empty($retrievedAdGroupTargeting)) {
    printf(
        "<p>The following targeting was retrieved for ad group ID %s:</p><ul>",
        $adGroupId);
    foreach ($retrievedAdGroupTargeting as $assignedTargetingOption) {
        printf(
            "<li>Assigned Targeting Option %s found.</li>",
            $assignedTargetingOption->getAssignedTargetingOption()->getName());
    }
    print("");
} else {
    printf(
        "<p>No targeting is currently assigned to ad group ID %s.</p>",
        $adGroupId);
}

اختصاص هدف‌گذاری به منابع

شما باید درخواست‌های جداگانه‌ای برای به‌روزرسانی هدف‌گذاری آیتم‌های خطی و گروه‌های تبلیغاتی ارسال کنید.

هدف‌گذاری برای آیتم‌های خطی را اختصاص دهید

در اینجا نحوه اضافه کردن منطق هدف‌گیری زیر به یک آیتم خطی آورده شده است:

  • فقط تبلیغات روی کامپیوترها نمایش داده می‌شود.
  • برای موجودی که در کنار محتوایی که با کلمه کلیدی "بستنی" مطابقت دارد، پیشنهاد قیمت ندهید.

جاوا

// Provide the ID of the parent advertiser.
long advertiserId = advertiser-id;

// Provide the ID of the line item.
long lineItemId = line-item-id;

// Build list of targeting delete requests.
List<DeleteAssignedTargetingOptionsRequest> deleteRequests =
    new ArrayList<>();

// Build delete targeting request for device types to remove from targeting
// in order to only target computer devices.
List<String> deviceTypesToDelete =
    Arrays.asList(
        "DEVICE_TYPE_CONNECTED_TV",
        "DEVICE_TYPE_SMART_PHONE",
        "DEVICE_TYPE_TABLET");
DeleteAssignedTargetingOptionsRequest deleteDeviceTypeRequest =
    new DeleteAssignedTargetingOptionsRequest()
        .setTargetingType("TARGETING_TYPE_DEVICE_TYPE")
        .setAssignedTargetingOptionIds(deviceTypesToDelete);
deleteRequests.add(deleteDeviceTypeRequest);

// Build list of targeting create requests.
List<CreateAssignedTargetingOptionsRequest> createRequests =
    new ArrayList<>();

// Build the "ice cream" negative keyword assigned targeting option.
AssignedTargetingOption keywordAssignedTargetingOption =
    new AssignedTargetingOption()
        .setKeywordDetails(
            new KeywordAssignedTargetingOptionDetails()
                .setKeyword("ice cream")
                .setNegative(true));
createRequests.add(
    new CreateAssignedTargetingOptionsRequest()
        .setTargetingType("TARGETING_TYPE_KEYWORD")
        .setAssignedTargetingOptions(
            Arrays.asList(keywordAssignedTargetingOption)));

// Build the bulk edit targeting request.
BulkEditAssignedTargetingOptionsRequest bulkEditTargetingRequest =
    new BulkEditAssignedTargetingOptionsRequest()
        .setLineItemIds(Arrays.asList(lineItemId))
        .setCreateRequests(createRequests)
        .setDeleteRequests(deleteRequests);

// Execute the bulk edit targeting request.
BulkEditAssignedTargetingOptionsResponse response =
    service
        .advertisers()
        .adGroups()
        .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.");
}

پایتون

# 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.")

پی اچ پی

// Provide the ID of the parent advertiser.
$advertiserId = advertiser-id;

// Provide the ID of the line item.
$lineItemId = line-item-id;

$deleteRequests = array();

// Build request to delete all other existing device type targeting
// options to only target computer devices.
$deleteDeviceTypeAssignedTargetingOption =
    new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest();
$deleteDeviceTypeAssignedTargetingOption->setTargetingType(
    'TARGETING_TYPE_DEVICE_TYPE'
);
$deleteDeviceTypeAssignedTargetingOption->setAssignedTargetingOptionIds(
    array(
        'DEVICE_TYPE_CONNECTED_TV',
        'DEVICE_TYPE_SMART_PHONE',
        'DEVICE_TYPE_TABLET'
    )
);
$deleteRequests[] = $deleteDeviceTypeAssignedTargetingOption;

$createRequests = array();

// Build the "ice cream" negative keyword assigned targeting option.
$keywordDetails =
    new Google_Service_DisplayVideo_KeywordAssignedTargetingOptionDetails();
$keywordDetails->setKeyword('ice cream');
$keywordDetails->setNegative(true);
$keywordAssignedTargetingOption =
    new Google_Service_DisplayVideo_AssignedTargetingOption();
$keywordAssignedTargetingOption->setKeywordDetails($keywordDetails);
$createKeywordAssignedTargetingOption =
    new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest();
$createKeywordAssignedTargetingOption->setTargetingType(
    'TARGETING_TYPE_KEYWORD'
);
$createKeywordAssignedTargetingOption->setAssignedTargetingOptions(
    array($keywordAssignedTargetingOption)
);
$createRequests[] = $createKeywordAssignedTargetingOption;

$body =
    new Google_Service_DisplayVideo_BulkEditAssignedTargetingOptionsRequest();

$body->setLineItemIds(array($lineItemId));
$body->setCreateRequests($createRequests);
$body->setDeleteRequests($deleteRequests);

// 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 '

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>'; }

هدف‌گیری گروه‌های تبلیغاتی را تعیین کنید

در اینجا نحوه اضافه کردن منطق هدف‌گیری زیر به یک گروه تبلیغاتی آورده شده است:

  • فقط به والدین خدمت کنید.
  • علیه کانال یوتیوب ارائه شده سرویس ندهید.

جاوا

// Provide the ID of the parent advertiser.
long advertiserId = advertiser-id;

// Provide the ID of the ad group.
long adGroupId = ad-group-id;

// Provide the YouTube channel ID to negatively target.
String youtubeChannelId = youtube-channel-id;

// Build list of targeting create requests.
List<CreateAssignedTargetingOptionsRequest> createRequests =
    new ArrayList<>();

// Build YouTube channel assigned targeting option.
AssignedTargetingOption youtubeChannelAssignedTargetingOption =
    new AssignedTargetingOption()
        .setYoutubeChannelDetails(
            new YoutubeChannelAssignedTargetingOptionDetails()
                .setChannelId(youtubeChannelId)
                .setNegative(true));
createRequests.add(
    new CreateAssignedTargetingOptionsRequest()
        .setTargetingType("TARGETING_TYPE_YOUTUBE_CHANNEL")
        .setAssignedTargetingOptions(
            Arrays.asList(youtubeChannelAssignedTargetingOption)));

// Build parental status assigned targeting option.
AssignedTargetingOption parentalStatusAssignedTargetingOption =
    new AssignedTargetingOption()
        .setParentalStatusDetails(
            new ParentalStatusAssignedTargetingOptionDetails()
                .setParentalStatus("PARENTAL_STATUS_PARENT"));
createRequests.add(
    new CreateAssignedTargetingOptionsRequest()
        .setTargetingType("TARGETING_TYPE_PARENTAL_STATUS")
        .setAssignedTargetingOptions(
            Arrays.asList(parentalStatusAssignedTargetingOption)));

// Create a bulk edit request.
BulkEditAdGroupAssignedTargetingOptionsRequest bulkEditTargetingRequest =
    new BulkEditAdGroupAssignedTargetingOptionsRequest()
        .setAdGroupIds(Arrays.asList(adGroupId))
        .setCreateRequests(createRequests);

// Configure the list request.
BulkEditAdGroupAssignedTargetingOptionsResponse response =
    service
        .advertisers()
        .adGroups()
        .bulkEditAssignedTargetingOptions(
            advertiserId,
            bulkEditTargetingRequest
        )
        .execute();

// Display API response information.
if (response.getUpdatedAdGroupIds() != null && !response.getUpdatedAdGroupIds().isEmpty()) {
  System.out.printf(
      "Targeting configurations for %s were successfully updated.%n",
      response.getUpdatedAdGroupIds().get(0));
}
if (response.getFailedAdGroupIds() != null && !response.getFailedAdGroupIds().isEmpty()) {
  System.out.printf(
      "Targeting configurations for %s failed to update.%n",
      response.getFailedAdGroupIds().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.");
}

پایتون

# 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.")

پی اچ پی

// Provide the ID of the parent advertiser.
$advertiserId = advertiser-id;

// Provide the ID of the ad group.
$adGroupId = ad-group-id;

// Provide the YouTube channel ID to negatively target.
$youtubeChannelId = youtube-channel-id;

$createRequests = array();

// Build YouTube channel assigned targeting option and add to create
// requests.
$youtubeChannelDetails =
    new Google_Service_DisplayVideo_YoutubeChannelAssignedTargetingOptionDetails();
$youtubeChannelDetails->setChannelId($youtubeChannelId);
$youtubeChannelDetails->setNegative(true);
$youtubeChannelAssignedTargetingOption =
    new Google_Service_DisplayVideo_AssignedTargetingOption();
$youtubeChannelAssignedTargetingOption->setYoutubeChannelDetails(
    $youtubeChannelDetails
);
$createYoutubeChannelAssignedTargetingOption =
    new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest();
$createYoutubeChannelAssignedTargetingOption->setTargetingType(
    'TARGETING_TYPE_YOUTUBE_CHANNEL'
);
$createYoutubeChannelAssignedTargetingOption
    ->setAssignedTargetingOptions(
        array($youtubeChannelAssignedTargetingOption)
    );
$createRequests[] = $createYoutubeChannelAssignedTargetingOption;

// Build parental status assigned targeting option and add to create
// requests.
$parentalStatusDetails =
    new Google_Service_DisplayVideo_ParentalStatusAssignedTargetingOptionDetails();
$parentalStatusDetails->setParentalStatus('PARENTAL_STATUS_PARENT');
$parentalStatusAssignedTargetingOption =
    new Google_Service_DisplayVideo_AssignedTargetingOption();
$parentalStatusAssignedTargetingOption->setParentalStatusDetails(
    $parentalStatusDetails
);
$createParentalStatusAssignedTargetingOption =
    new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest();
$createParentalStatusAssignedTargetingOption->setTargetingType(
    'TARGETING_TYPE_PARENTAL_STATUS'
);
$createParentalStatusAssignedTargetingOption
    ->setAssignedTargetingOptions(
        array($parentalStatusAssignedTargetingOption)
    );
$createRequests[] = $createParentalStatusAssignedTargetingOption;

$body =
    new Google_Service_DisplayVideo_BulkEditAdGroupAssignedTargetingOptionsRequest();

$body->setAdGroupIds(array($adGroupId));
$body->setCreateRequests($createRequests);

// Call the API, editing the assigned targeting options for the
// identified ad group.
try {
    $response = $this
        ->service
        ->advertisers_adGroups
        ->bulkEditAssignedTargetingOptions(
            $advertiserId,
            $body
        );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Print information returned by the bulk edit request.
// List updated ad group IDs.
if (empty($response->getUpdatedAdGroupIds())) {
    print '<p>No ad groups were successfully updated.</p>';
} else {
    print '<p>The targeting of the following ad group IDs were '
        . 'updated:</p><ul>';
    foreach ($response->getUpdatedAdGroupIds() as $id) {
        printf('<li>%s</li>',$id);
    }
    print '</ul>';
}

// List ad group IDs that failed to update.
if (empty($response->getFailedAdGroupIds())) {
    print '<p>No ad groups failed to update.</p>';
} else {
    print '<p>The targeting of the following ad group IDs failed to '
        . 'update:</p><ul>';
    foreach ($response->getFailedAdGroupIds() 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>';
}