Attiva elemento pubblicitario

Tutti gli elementi pubblicitari creati utilizzando l'API Display & Video 360 vengono inizialmente creati in stato di bozza. In questo stato di bozza, gli elementi pubblicitari non pubblicano annunci, quindi puoi modificare le impostazioni e il targeting senza che queste modifiche influiscano sulla pubblicazione degli annunci in corso. In questa pagina vengono descritti i passaggi da seguire per verificare che l'elemento pubblicitario sia pronto per la pubblicazione di annunci e come aggiornarne lo stato impostandolo su attivo.

Cosa fare prima dell'attivazione

Dato che gli elementi pubblicitari sono il modo in cui le entrate pubblicitarie vengono spese attraverso l'acquisto e la pubblicazione di annunci, è importante assicurarsi che l'elemento pubblicitario pubblichi gli annunci come previsto quando viene attivato. Di seguito sono riportati alcuni aspetti da considerare prima di attivare l'elemento pubblicitario:

  • Assicurati che le impostazioni del periodo di pubblicazione siano corrette: controlla il campo flight dell'elemento pubblicitario per assicurarti che la finestra del periodo di pubblicazione per l'elemento pubblicitario sia impostata correttamente. Il periodo di pubblicazione di un elemento pubblicitario può essere personalizzato per l'elemento pubblicitario o ereditato dall'ordine di inserzione principale.
  • Verifica che non siano presenti avvisi che bloccano la pubblicazione dell'elemento pubblicitario. Utilizza advertisers.lineItems.get per recuperare una risorsa dell'elemento pubblicitario e controlla il campo warningMessages per verificare che l'elemento pubblicitario non presenti avvisi che potrebbero ostacolare la pubblicazione dell'elemento pubblicitario. L'enumerazione LineItemWarningMessage indica l'impatto di ogni avviso.
  • Verifica che siano attive anche tutte le risorse principali: un elemento pubblicitario attivo non inizierà a pubblicare annunci se l'inserzionista, la campagna o l'ordine di inserzione principale non sono attivi. Recupera queste risorse utilizzando i metodi GET nei servizi Inserzionisti, Campagne e Ordini di inserzione.

Attivare un elemento pubblicitario

Attiva un elemento pubblicitario aggiornando il relativo campo entityStatus in ENTITY_STATUS_ACTIVE. Puoi aggiornare questo campo per un singolo elemento pubblicitario con il metodo advertisers.lineItems.patch e per più elementi pubblicitari di un determinato inserzionista utilizzando advertisers.lineItems.bulkUpdate.

Di seguito è riportato un esempio di come utilizzare bulkUpdate per attivare più elementi pubblicitari:

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'])

PHP

// 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);
    }
}