Kích hoạt mục hàng

Ban đầu, tất cả các mục hàng tạo bằng API Display & Video 360 đều được tạo ở trạng thái nháp. Ở trạng thái bản nháp này, các mục hàng không phân phát quảng cáo. Vì vậy, bạn có thể điều chỉnh chế độ cài đặt và tiêu chí nhắm mục tiêu mà không ảnh hưởng đến bất kỳ hoạt động phân phát quảng cáo hiện tại nào. Trang này mô tả các bước bạn cần thực hiện để xác nhận rằng mục hàng đã sẵn sàng phân phát quảng cáo và cách cập nhật trạng thái của mục hàng thành đang hoạt động.

Việc cần làm trước khi kích hoạt

Do mục hàng là cách chi tiêu doanh thu quảng cáo của bạn thông qua việc mua và phân phát quảng cáo, bạn phải đảm bảo rằng mục hàng sẽ phân phát quảng cáo như dự kiến khi được kích hoạt. Dưới đây là một vài điều cần xem xét trước khi kích hoạt mục hàng của bạn:

  • Đảm bảo chế độ cài đặt giai đoạn hiển thị là chính xác: Kiểm tra trường flight của mục hàng để đảm bảo rằng bạn đã đặt khung thời gian hiển thị cho mục hàng một cách chính xác. Thời lượng hiển thị của một mục hàng có thể tuỳ chỉnh với mục hàng hoặc được kế thừa theo đơn đặt hàng quảng cáo gốc.
  • Xác minh rằng không có cảnh báo nào chặn việc phân phát mục hàng: Sử dụng advertisers.lineItems.get để truy xuất tài nguyên mục hàng và kiểm tra trường warningMessages để xác minh rằng mục hàng không có cảnh báo nào có thể cản trở việc phân phát mục hàng. Enum LineItemWarningMessage ghi chú tác động của từng cảnh báo.
  • Xác nhận rằng tất cả các tài nguyên gốc cũng đang hoạt động: Một mục hàng đang hoạt động sẽ không bắt đầu phân phát quảng cáo nếu nhà quảng cáo, chiến dịch hoặc đơn đặt hàng quảng cáo gốc không hoạt động. Truy xuất các tài nguyên này bằng cách sử dụng phương thức GET trong các dịch vụ Nhà quảng cáo, Chiến dịchĐơn đặt hàng quảng cáo.

Kích hoạt mục hàng

Kích hoạt một mục hàng bằng cách cập nhật trường entityStatus của mục hàng đó thành ENTITY_STATUS_ACTIVE. Bạn có thể cập nhật trường này cho một mục hàng riêng lẻ bằng phương thức advertisers.lineItems.patch và cho nhiều mục hàng trong một nhà quảng cáo nhất định bằng cách sử dụng advertisers.lineItems.bulkUpdate.

Dưới đây là ví dụ về cách sử dụng bulkUpdate để kích hoạt nhiều mục hàng:

Java

// Create the line item structure.
LineItem targetLineItem = new LineItem();
targetLineItem.setEntityStatus("ENTITY_STATUS_ACTIVE");

// Create the bulk update request body.
BulkUpdateLineItemsRequest requestBody = new BulkUpdateLineItemsRequest();
requestBody.setLineItemIds(line-item-ids);
requestBody.setTargetLineItem(targetLineItem);
requestBody.setUpdateMask("entityStatus");

// Configure the bulk update request.
LineItems.BulkUpdate request = service.advertisers().lineItems()
    .bulkUpdate(advertiser-id, requestBody);

// Update the line items.
BulkUpdateLineItemsResponse response = request.execute();

// Display the line items that were updated, failed, and skipped.
if (response.getUpdatedLineItemIds() != null) {
  System.out.printf(
      "The following line item IDs were successfully updated: %s.\n",
      Arrays.toString(response.getUpdatedLineItemIds().toArray()));
}
if (response.getFailedLineItemIds() != null) {
  System.out.printf("The following line item IDs failed to update: %s.\n",
      Arrays.toString(response.getFailedLineItemIds().toArray()));
  if (response.getErrors() != null) {
    System.out.printf(
        "The failed updates were caused by the following errors: %s.\n",
        Arrays.toString(response.getErrors().toArray()));
  }
}
if (response.getSkippedLineItemIds() != null) {
  System.out.printf(
      "The following line items IDs were skipped in the update: %s.\n",
      Arrays.toString(response.getSkippedLineItemIds().toArray()));
}

Python

# Create a line item object with only updated entity status.
line_item_obj = {
    'entityStatus': 'ENTITY_STATUS_ACTIVE'
}

# Build the bulk update request.
bulk_update_request = {
    'lineItemIds': line-item-ids,
    'targetLineItem': line_item_obj,
    'updateMask': "entityStatus"
}

# Update the line items.
response = service.advertisers().lineItems().bulkUpdate(
    advertiserId=advertiser-id,
    body=bulk_update_request
).execute()

# Display the line items that were updated, failed, and skipped.
if 'updatedLineItemIds' in response:
  print("The following line item IDs were updated: %s"
        % response['updatedLineItemIds'])
if 'failedLineItemIds' in response:
  print("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"]))
if 'skippedLineItemIds' in response:
  print("The following line items IDs were skipped in the update:: %s"
        % response['skippedLineItemIds'])

1.199

// Create request body.
$body = new Google_Service_DisplayVideo_BulkUpdateLineItemsRequest();
$body->setLineItemIds(line-item-ids);

// Create target line item with updated fields.
$lineItem = new Google_Service_DisplayVideo_LineItem();
$lineItem->setEntityStatus('ENTITY_STATUS_ACTIVE');
$body->setTargetLineItem($lineItem);

// Set update mask in request body.
$body->setUpdateMask("entityStatus");

// Call the API, updating the entity status for the identified line item.
$response = $service->advertisers_lineItems->bulkUpdate(
    advertiser-id,
    $body
);

// Display the line items that were updated, failed, and skipped.
if (!empty($response->getUpdatedLineItemIds())) {
    printf('The following line item IDs were updated:\n');
    foreach ($response->getUpdatedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
}
if (!empty($response->getFailedLineItemIds())) {
    print('The following line item IDs failed to update:\n');
    foreach ($response->getFailedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
    if (!empty($response->getErrors())) {
        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()
            );
        }
    }
}
if (!empty($response->getSkippedLineItemIds())) {
    print('The following line item IDs were skipped in the update:\n');
    foreach ($response->getSkippedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
}