업로드 규칙

규칙 기반 알고리즘은 AlgorithmRules JSON 객체로 정의됩니다. JSON 파일을 통해 Display & Video 360에 규칙을 업로드합니다.

스크립트 기반 알고리즘을 사용하는 경우 스크립트 업로드 페이지로 이동합니다.

규칙 객체 빌드

규칙 기반 맞춤 입찰 알고리즘은 규칙을 사용하여 응답 신호의 가치를 평가합니다.

AlgorithmRules 객체는 하나 이상의 규칙 세트로 구성됩니다. 각 규칙 세트는 노출과 같은 다양한 유형의 응답 신호를 평가합니다. 각 규칙 세트에는 규칙 목록이 있습니다. 각 규칙은 설정된 조건에 대해 신호를 평가하고 값을 반환합니다. 신호는 세트의 모든 규칙에 의해 평가됩니다. 그런 다음 각 규칙에서 반환된 값이 결합됩니다. 이렇게 하면 신호의 평가 값이 생성됩니다.

AlgorithmRules 객체를 JSON 파일로 로컬에 저장합니다.

규칙 참조 객체 생성

참조 객체는 업로드된 파일을 rules 리소스와 연결하는 데 사용됩니다. uploadRules 요청을 사용하여 algorithm 아래에 참조 객체를 생성합니다.

규칙 참조 객체를 생성하는 방법은 다음과 같습니다.

자바

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

// Provide the ID of the algorithm.
long customBiddingAlgorithmId = algorithm-id;

// Generate an AlgorithmRules reference object under the algorithm.
CustomBiddingAlgorithmRulesRef response =
    service
        .customBiddingAlgorithms()
        .uploadRules(customBiddingAlgorithmId)
        .setAdvertiserId(advertiserId)
        .execute();

// Display the generated resource path.
System.out.printf(
    "The generated AlgorithmRules reference object provided the following resource path: %s.",
    response.getResourceName());

Python

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

# Provide the ID of the algorithm.
algorithm_id = algorithm-id

# Generate an AlgorithmRules reference object under the algorithm.
custom_bidding_algorithm_rules_ref = (
    service.customBiddingAlgorithms()
    .uploadRules(
        customBiddingAlgorithmId=algorithm_id,
        advertiserId=advertiser_id
    )
    .execute()
)

# Print the resource path provided in the generated rules reference object.
print(
    "The generated rules reference object provided the following resource"
    f' path: {custom_bidding_algorithm_rules_ref["resourceName"]}.'
)

PHP

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

// Provide the ID of the algorithm.
$algorithmId = algorithm-id;

$uploadRulesOptParams = array(
    'advertiserId' => $advertiserId
);

try {
  // Generate an AlgorithmRules reference object under the algorithm.
    $rulesRefResponse =
        $this->service->customBiddingAlgorithms->uploadRules(
            $customBiddingAlgorithmId,
            $uploadRulesOptParams
        );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Print the retrieved resource path.
printf(
    '<p>The generated AlgorithmRules reference object provided the '
        . 'following resource path: %s</p>',
    $rulesRefResponse->getResourceName()
);

AlgorithmRules 파일 업로드

미디어 upload 요청을 사용하여 참조 객체의 리소스 경로에 규칙 파일을 업로드합니다. 쿼리 매개변수 uploadType=media를 사용하여 간단한 업로드를 사용합니다.

규칙 파일을 업로드하는 방법은 다음과 같습니다.

자바

// Provide the local path to the AlgorithmRules file to upload.
String rulesPath = rules-path;

// Provide the resource path to upload the AlgorithmRules file to.
String resourcePath = resource-path;

// Create media object.
GoogleBytestreamMedia media = new GoogleBytestreamMedia();
media.setResourceName(resourcePath);

// Create input stream for the Algorithm file.
InputStreamContent rulesFileStream =
    new InputStreamContent(null, new FileInputStream(rulesPath));

// Create media.upload request.
Media.Upload uploadRequest = service.media().upload(resourcePath, media, rulesFileStream);

// Retrieve uploader from the request and set it to us a simple upload
// request.
MediaHttpUploader uploader = uploadRequest.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);

// Execute the upload using an Upload URL with the destination resource
// name.
uploader.upload(
    new GenericUrl("https://displayvideo.googleapis.com/upload/media/" + resourcePath));

Python

# Import HTTP objects used for file upload.
from apiclient.http import HttpRequest
from apiclient.http import MediaFileUpload

# Provide the local path to the AlgorithmRules file to upload.
rules_path = rules-path

# Provide the resource path to upload the AlgorithmRules file to.
resource_path = resource-path

# Create a media upload object.
media = MediaFileUpload(rules_path)

# Create upload request.
upload_request = service.media().upload(
    resourceName=resource_path, media_body=media
)

# Override response handler to expect null response.
upload_request.postproc = HttpRequest.null_postproc

# Upload AlgorithmRules to given resource path.
upload_request.execute()

PHP

// Provide the local path to the AlgorithmRules file to upload.
$rulesPath = rules-path;

// Provide the resource path to upload the AlgorithmRules file to.
$resourcePath = resource-path;

// Create the media body.
$mediaBody = new Google_Service_DisplayVideo_GoogleBytestreamMedia();
$mediaBody->setResourceName($resourceName);

// Build params array for the upload request.
$mediaUploadOptParams = array(
    'data' => file_get_contents($rulesPath),
    'uploadType' => 'media',
    'resourceName' => $resourceName
);

try {
    // Call the API, uploading the rules file to Display & Video 360.
    $this->service->media->upload(
        $resourceName,
        $mediaBody,
        $mediaUploadOptParams
    );
} catch (\Exception $e) {
    $this->renderError($e);
}

규칙 객체 만들기

create 요청을 사용하여 algorithm 아래에 rules 객체를 만듭니다.

규칙 객체를 만드는 방법은 다음과 같습니다.

자바

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

// Provide the ID of the parent algorithm.
long algorithmId = algorithm-id;

// Provide the resource path the AlgorithmRules file was uploaded to.
String resourcePath = resource-path;

// Create the custom bidding algorithm rules structure.
CustomBiddingAlgorithmRules customBiddingAlgorithmRules =
    new CustomBiddingAlgorithmRules()
        .setRules(new CustomBiddingAlgorithmRulesRef().setResourceName(resourcePath));

// Create the custom bidding algorithm rules.
CustomBiddingAlgorithmRules response =
    service
        .customBiddingAlgorithms()
        .rules()
        .create(algorithmId, customBiddingAlgorithmRules)
        .setAdvertiserId(advertiserId)
        .execute();

// Print ID of new custom bidding algorithm rules.
System.out.printf("Rules were created with ID %s.", response.getCustomBiddingAlgorithmRulesId());

Python

# Provide the ID of the advertiser that owns the parent algorithm.
advertiser_id = advertiser-id

# Provide the ID of the parent algorithm.
algorithm_id = algorithm-id

# Provide the resource path the AlgorithmRules file was uploaded to.
resource_path = resource-path

# Build algorithm rules object.
rules_obj = {"rules": {"resourceName": resource_path}}

# Build and execute request.
rules_response = (
    service.customBiddingAlgorithms()
    .rules()
    .create(
        customBiddingAlgorithmId=algorithm_id,
        advertiserId=advertiser_id,
        body=rules_obj,
    )
    .execute()
)

# Print ID of new custom bidding algorithm rules.
print(
    f'Rules were created with ID {rules_response["customBiddingAlgorithmRulesId"]}.'
)

PHP

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

// Provide the ID of the parent algorithm.
$algorithmId = algorithm-id;

// Provide the resource path the AlgorithmRules file was uploaded to.
$resourcePath = resource-path;

// Build algorithm rules object.
$customBiddingRules = new Google_Service_DisplayVideo_CustomBiddingAlgorithmRules();
$rulesRef = new Google_Service_DisplayVideo_CustomBiddingAlgorithmRulesRef();
$rulesRef->setResourceName($resourcePath);
$customBiddingRules->setRules($rulesRef);

$createRulesOptParams = array(
    'advertiserId' => $advertiserId
);

// Call the API, creating the custom bidding algorithm rules using the
// rules file and under the custom bidding algorithm given.
try {
    $result = $this->service->customBiddingAlgorithms_rules->create(
        $customBiddingAlgorithmId,
        $algorithmId,
        $createRulesOptParams
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Print ID of new custom bidding algorithm rules.
printf('<p>Rules was created with ID %s.</p>', $result['customBiddingAlgorithmRulesId']);