Как создать алгоритм специальных ставок

Алгоритм специальных ставок создается на основе логики назначения ставок, заданной пользователем. Назначить ее позиции в настройках стратегии назначения ставок. При назначении ставок на рекламный инвентарь позиция будет использовать эту специальную логику.

Сначала выберите тип алгоритма и создайте ресурс алгоритма.

Выберите тип алгоритма специальных ставок

Тип алгоритма определяет, как в нем задается логика назначения ставок.

Выберите один из следующих типов, которые можно создать с помощью Display & Video 360 API:

  • SCRIPT_BASED – логика, заданная загруженным скриптом. Скрипт представляет собой текстовый файл, в котором используется базовый синтаксис Python.
  • RULE_BASED – логика, заданная загруженным набором правил. Набор правил – это загруженный JSON-файл AlgorithmRules.

Создать ресурс CustomBiddingAlgorithm

Чтобы создать алгоритм специальных ставок, используйте запрос create.

owner алгоритма может быть как рекламодатель, так и партнер. Если он принадлежит рекламодателю, то может использоваться только в рекламных кампаниях этого рекламодателя. Если же он принадлежит партнеру, то использовать его могут только рекламодатели, которым предоставлен доступ.

Чтобы создать алгоритм специальных ставок, выполните следующие действия:

Java

// Provide the ID of the advertiser that will own the algorithm.
long advertiserId = advertiser-id;

// Provide the display name of the algorithm.
String displayName = display-name;

// Provide the type of custom bidding algorithm.
String customBiddingAlgorithmType = custom-bidding-algorithm-type;

// Create the custom bidding algorithm structure.
CustomBiddingAlgorithm algorithm =
    new CustomBiddingAlgorithm()
        .setAdvertiserId(advertiserId)
        .setDisplayName(displayName)
        .setEntityStatus("ENTITY_STATUS_ACTIVE")
        .setCustomBiddingAlgorithmType(customBiddingAlgorithmType);

// Create the algorithm.
CustomBiddingAlgorithm response = service.customBiddingAlgorithms().create(algorithm).execute();

// Display the new custom bidding algorithm ID.
System.out.printf(
    "Custom Bidding Algorithm was created with the ID %s.",
    response.getCustomBiddingAlgorithmId());

Python

# Provide the ID of the advertiser that will own the algorithm.
advertiser_id = advertiser-id

# Provide the display name of the algorithm.
display_name = display-name

# Provide the type of custom bidding algorithm.
custom_bidding_algo_type = custom-bidding-algorithm-type

# Build CustomBiddingAlgorithm object.
custom_bidding_algorithm_obj = {
    "advertiserId": advertiser_id,
    "displayName": display_name,
    "entityStatus": "ENTITY_STATUS_ACTIVE",
    "customBiddingAlgorithmType": custom_bidding_algo_type,
}

# Build and execute request.
algorithm_response = (
    service.customBiddingAlgorithms()
    .create(body=custom_bidding_algorithm_obj)
    .execute()
)

# Print ID of new custom bidding algorithm.
print(
    "Custom bidding algorithm was created with ID "
    f'{algorithm_response["customBiddingAlgorithmId"]}.'
)

PHP

// Provide the ID of the advertiser that will own the algorithm.
$advertiserId = advertiser-id;

// Provide the display name of the algorithm.
$displayName = display-name;

// Provide the type of custom bidding algorithm.
$customBiddingAlgorithmType = custom-bidding-algorithm-type;

// Create the custom bidding algorithm structure.
$algorithm = new Google_Service_DisplayVideo_CustomBiddingAlgorithm();
$algorithm->setAdvertiserId($advertiserId);
$algorithm->setDisplayName($displayName);
$algorithm->setEntityStatus('ENTITY_STATUS_ACTIVE');
$algorithm->setCustomBiddingAlgorithmType($customBiddingAlgorithmType);

// Call the API, creating the advertiser.
try {
    $result = $this->service->customBiddingAlgorithms->create($algorithm);
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Print ID of new custom bidding algorithm.
printf('<p>Custom Bidding Algorithm was created with the ID %s.</p>', $result['customBiddingAlgorithmId']);