ใช้การเสนอราคาที่กําหนดเอง

API ของ Display & Video 360 ช่วยให้คุณจัดการการใช้งานการเสนอราคาที่กำหนดเองได้อย่างเต็มรูปแบบ โดยคุณจะสร้างอัลกอริทึมการเสนอราคาที่กำหนดเอง อัปโหลดและยืนยันสคริปต์แต่ละรายการ และกำหนดอัลกอริทึมที่เจาะจงให้กับทรัพยากรเป็นกลยุทธ์การเสนอราคาได้

หน้านี้จะอธิบายวิธีสร้าง อัปเดต และกำหนดอัลกอริทึมการเสนอราคาที่กำหนดเองด้วย API ของ Display & Video 360 แต่ละส่วนจะมีตัวอย่างโค้ด

สร้างอัลกอริทึมการเสนอราคาที่กําหนดเอง

ออบเจ็กต์ CustomBiddingAlgorithm แสดงถึงอัลกอริทึมแต่ละรายการที่คุณกําหนดให้กับรายการโฆษณาเพื่อใช้ในกลยุทธ์การเสนอราคาได้ ออบเจ็กต์นี้มีรายละเอียดเกี่ยวกับอัลกอริทึม เช่น customBiddingAlgorithmType และ entityStatus รวมถึง readinessState และ suspensionState สำหรับโมเดลที่สร้างโดยผู้ลงโฆษณาที่เกี่ยวข้องแต่ละราย คุณสร้างออบเจ็กต์ CustomBiddingScript และ CustomBiddingAlgorithmRules เป็นทรัพยากรย่อยเพื่อให้อัลกอริทึมใช้ได้

ต่อไปนี้คือตัวอย่างวิธีสร้างอัลกอริทึมการเสนอราคาที่กำหนดเองตามสคริปต์

Java

// Create the custom bidding algorithm structure.
CustomBiddingAlgorithm customBiddingAlgorithm =
    new CustomBiddingAlgorithm()
        .setAdvertiserId(advertiser-id)
        .setDisplayName(display-name)
        .setEntityStatus("ENTITY_STATUS_ACTIVE")
        .setCustomBiddingAlgorithmType("SCRIPT_BASED");

// Configure the create request.
CustomBiddingAlgorithms.Create request =
    service.customBiddingAlgorithms().create(customBiddingAlgorithm);

// Create the custom bidding algorithm.
CustomBiddingAlgorithm response = request.execute();

// Display the new custom bidding algorithm name.
System.out.printf(
    "Custom bidding algorithm %s was created.%n",
    response.getName()
);

Python

# Create a custom bidding algorithm object.
custom_bidding_algorithm_obj = {
    'advertiserId': advertiser-id,
    'displayName': display-name,
    'entityStatus': 'ENTITY_STATUS_ACTIVE',
    'customBiddingAlgorithmType': 'SCRIPT_BASED'
}

# Create the custom bidding algorithm.
response = service.customBiddingAlgorithms().create(
    body=custom_bidding_algorithm_obj
).execute()

# Display the new custom bidding algorithm.
print(f'The following Custom Bidding Algorithm was created: {response}')

PHP

// Create a custom bidding algorithm object.
$customBiddingAlgorithm =
    new Google_Service_DisplayVideo_CustomBiddingAlgorithm();
$customBiddingAlgorithm->setAdvertiserId(advertiser-id);
$customBiddingAlgorithm->setDisplayName(display-name);
$customBiddingAlgorithm->setEntityStatus('ENTITY_STATUS_ACTIVE');
$customBiddingAlgorithm->setCustomBiddingAlgorithmType('SCRIPT_BASED');

// Create the custom bidding algorithm.
$result =
    $this->service->customBiddingAlgorithms->create($customBiddingAlgorithm);

// Display the new custom bidding algorithm name.
printf('Custom Bidding Algorithm %s was created.\n', $result['name']);

จัดการการเข้าถึงอัลกอริทึม

พาร์ทเนอร์หรือผู้ลงโฆษณาอาจเป็นเจ้าของอัลกอริทึมการเสนอราคาที่กําหนดเองก็ได้ พาร์ทเนอร์ดังกล่าวและผู้ลงโฆษณาย่อยที่มีรายชื่ออยู่ในช่อง sharedAdvertiserIds สามารถเข้าถึงและแก้ไขอัลกอริทึมที่พาร์ทเนอร์เป็นเจ้าของได้ อัลกอริทึมที่เป็นของผู้ลงโฆษณาสามารถเข้าถึงและแก้ไขได้โดยผู้ลงโฆษณาและพาร์ทเนอร์หลัก แต่ไม่สามารถแชร์กับผู้อื่นได้

หากใช้อัลกอริทึมสำหรับผู้ลงโฆษณารายเดียวเท่านั้น ให้กำหนดผู้ลงโฆษณาเป็นเจ้าของด้วยช่อง advertiserId หรือให้สิทธิ์พาร์ทเนอร์ระดับบนสุดของผู้ลงโฆษณาเป็นเจ้าของช่อง partnerId และให้สิทธิ์ผู้ลงโฆษณาเข้าถึงช่อง sharedAdvertiserIds

อัปโหลดตรรกะอัลกอริทึม

ถัดไปคุณจะต้องสร้างสคริปต์หรือออบเจ็กต์กฎที่ระบุตรรกะให้อัลกอริทึมใช้ ทั้งนี้ขึ้นอยู่กับประเภทอัลกอริทึมการเสนอราคาที่กำหนดเอง

อัปโหลดสคริปต์

อัลกอริทึมการเสนอราคาที่กําหนดเองตามสคริปต์จะใช้สคริปต์ที่ผู้ใช้ให้ไว้ในการประเมินมูลค่าของการแสดงผล ดูตัวอย่างสคริปต์แบบง่ายและรายการช่องขั้นสูงได้ในศูนย์ช่วยเหลือของ Display & Video 360

ส่วนต่อไปนี้จะสอนวิธีเพิ่มสคริปต์ใหม่หรือสคริปต์ที่อัปเดตลงในอัลกอริทึมการเสนอราคาที่กำหนดเอง

เรียกข้อมูลตำแหน่งทรัพยากรสคริปต์

ก่อนอื่น ให้ดึงข้อมูลตำแหน่งของทรัพยากรที่พร้อมใช้งานภายใต้ทรัพยากรอัลกอริทึมการเสนอราคาที่กำหนดเองโดยใช้เมธอด customBiddingAlgorithms.uploadScript คำขอนี้จะแสดงผลออบเจ็กต์ CustomBiddingScriptRef ที่มีชื่อทรัพยากร คุณอัปโหลดไฟล์สคริปต์ไปยังตำแหน่งที่ชื่อทรัพยากรกำหนดได้ จากนั้นใช้ออบเจ็กต์อ้างอิงสคริปต์การเสนอราคาที่กำหนดเองเพื่อสร้างทรัพยากรสคริปต์

ตัวอย่างวิธีเรียกข้อมูลตำแหน่งทรัพยากรที่ใช้ได้มีดังนี้

Java

// Retrieve a usable custom bidding script
// reference.
CustomBiddingScriptRef scriptRef =
    service
        .customBiddingAlgorithms()
        .uploadScript(custom-bidding-algorithm-id)
        .setAdvertiserId(advertiser-id)
        .execute();

// Display the custom bidding script reference resource path.
System.out.printf(
    "The script can be uploaded to the following resource path: %s%n",
    scriptRef.getResourceName()
);

Python

# Retrieve a usable custom bidding script reference
# object.
custom_bidding_script_ref = service.customBiddingAlgorithms().uploadScript(
    customBiddingAlgorithmId=custom-bidding-algorithm-id,
    advertiserId=advertiser-id
).execute()

# Display the new custom bidding script reference object.
print('The following custom bidding script reference object was retrieved:'
      f'{custom_bidding_script_ref}')

PHP

// Set parent advertiser ID of custom bidding
// algorithm in optional parameters array for request.
$optParams = array('advertiserId' => advertiser-id);

// Retrieve a usable custom bidding script reference.
$scriptRefResponse = $this->service->customBiddingAlgorithms->uploadScript(
    custom-bidding-algorithm-id,
    $optParams
);

// Display the new custom bidding script reference object.
printf(
    'The script can be uploaded to the following resource path: %s\n',
    $scriptRefResponse->getResourceName()
);

อัปโหลดไฟล์สคริปต์

หลังจากเรียกข้อมูลตำแหน่งทรัพยากรที่พร้อมใช้งานแล้ว ให้อัปโหลดไฟล์สคริปต์ไปยังตำแหน่งดังกล่าวในระบบ Display & Video 360 โดยใช้เมธอด media.upload วิธีนี้รองรับการอัปโหลดแบบง่ายที่ต้องใช้พารามิเตอร์การค้นหา uploadType=media

ตัวอย่างวิธีอัปโหลดไฟล์สคริปต์จากออบเจ็กต์อ้างอิงสคริปต์การเสนอราคาที่กำหนดเองซึ่งดึงมามีดังนี้

Java

// Create media object.
GoogleBytestreamMedia media = new GoogleBytestreamMedia();
media.setResourceName(resource-name);

// Create input stream for the script file.
InputStreamContent scriptFileStream =
    new InputStreamContent(
        null, new FileInputStream(script-path));

// Create media.upload request.
Media.Upload uploadRequest =
        service
            .media()
            .upload(
                resource-name,
                media,
                scriptFileStream);

// 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/"
                + resource-name));

Python

# Create a media upload object.
media = MediaFileUpload(script-path)

# Create upload request.
upload_request = service.media().upload(
    resourceName=resource-name, media_body=media)

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

# Upload script to resource location given in retrieved custom bidding
# script reference object.
upload_request.execute()

PHP

// Create a media object.
$mediaBody = new Google_Service_DisplayVideo_GoogleBytestreamMedia();
$mediaBody->setResourceName(resource-name);

// Set parameters for upload request.
$optParams = array(
    'data' => file_get_contents(script-path),
    'uploadType' => 'media',
    'resourceName' => resource-name
);

// Upload script file to given resource location.
$this->service->media->upload(
    resource-name,
    $mediaBody,
    $optParams
);

cURL

curl --request POST 'https://displayvideo.googleapis.com/upload/media/resource-name?uploadType=media' 
  -H 'authorization: Bearer access-token'
  -H 'Content-Type: text/plain'
  --data-binary @script-path

สร้างออบเจ็กต์ของสคริปต์

เมื่ออัปโหลดไฟล์สคริปต์แล้ว ให้สร้างทรัพยากรสคริปต์การเสนอราคาที่กำหนดเองด้วยเมธอด customBiddingAlgorithms.scripts.create ออบเจ็กต์ CustomBiddingScript ที่ส่งผ่านในคำขอควรมีเฉพาะออบเจ็กต์ CustomBiddingScriptRef เป็นค่าที่กำหนดไว้ของช่อง script ซึ่งจะเชื่อมโยงไฟล์สคริปต์ที่อัปโหลด กับทรัพยากรสคริปต์ใหม่

ต่อไปนี้เป็นตัวอย่างวิธีสร้างทรัพยากรสคริปต์

Java

// Create the custom bidding script structure.
CustomBiddingScript customBiddingScript =
    new CustomBiddingScript()
        .setScript(custom-bidding-script-ref);

// Create the custom bidding script.
CustomBiddingScript response =
    service
        .customBiddingAlgorithms()
        .scripts()
        .create(custom-bidding-algorithm-id, customBiddingScript)
        .setAdvertiserId(advertiser-id)
        .execute();

// Display the new script resource name
System.out.printf(
    "The following script was created: %s%n",
    response.getName());

Python

# Create a custom bidding script object.
script_obj = {
    'script': custom-bidding-script-ref
}

# Create the custom bidding script.
response = service.customBiddingAlgorithms().scripts().create(
    customBiddingAlgorithmId=custom-bidding-algorithm-id,
    advertiserId=advertiser-id,
    body=script_obj).execute()

# Display the new custom bidding script object.
print(f'The following custom bidding script was created: {response}')

PHP

// Create the custom bidding script object.
$customBiddingScript =
    new Google_Service_DisplayVideo_CustomBiddingScript();
$customBiddingScript->setScript(custom-bidding-script-ref);

// Set parameters for create script request.
$optParams = array(
    'advertiserId' => advertiser-id
);

// Create the custom bidding script.
$result = $this->service->customBiddingAlgorithms_scripts->create(
    custom-bidding-algorithm-id,
    $customBiddingScript,
    $optParams
);

// Display the new script resource name.
printf('The following script was created: %s.\n', $result->getName());

เมื่อสร้างทรัพยากรสคริปต์การเสนอราคาที่กำหนดเองแล้ว Display & Video 360 จะประมวลผลสคริปต์ดังกล่าวเพื่อให้แน่ใจว่าจะใช้สคริปต์ดังกล่าวในการให้คะแนนการแสดงผลได้สำเร็จ เรียกดูสถานะของการประมวลผลนี้ผ่านช่อง state ของออบเจ็กต์สคริปต์ เมื่อยอมรับสคริปต์ใหม่แล้ว อัลกอริทึมการเสนอราคาที่กำหนดเองจะเริ่มใช้สคริปต์ในการให้คะแนนค่าการแสดงผล ซึ่งจะเกิดขึ้นทันที คุณจึงควรอัปเดตอัลกอริทึมก่อนที่จะสร้างทรัพยากรสคริปต์ใหม่

กฎการอัปโหลด

อัลกอริทึมการเสนอราคาที่กําหนดเองที่อิงตามกฎจะใช้ตรรกะที่ให้ไว้ในออบเจ็กต์ AlgorithmRules เพื่อประเมินมูลค่าของการแสดงผล

ระบบจะอัปโหลดออบเจ็กต์ AlgorithmRules ไว้ในไฟล์ JSON จากนั้นเชื่อมโยงกับอัลกอริทึมการเสนอราคาที่กำหนดเองผ่านออบเจ็กต์ CustomBiddingAlgorithmRules

เรียกข้อมูลตำแหน่งทรัพยากรกฎ

ก่อนอื่น ให้ดึงข้อมูลตำแหน่งของทรัพยากรที่พร้อมใช้งานภายใต้ทรัพยากรอัลกอริทึมการเสนอราคาที่กำหนดเองโดยใช้เมธอด customBiddingAlgorithms.uploadRules คำขอนี้จะแสดงผลออบเจ็กต์ CustomBiddingAlgorithmsRulesRef ที่มีชื่อทรัพยากร คุณอัปโหลดไฟล์กฎไปยังตำแหน่งที่ชื่อทรัพยากรกำหนดได้ จากนั้นใช้ออบเจ็กต์อ้างอิงของกฎอัลกอริทึมการเสนอราคาที่กำหนดเองเพื่อสร้างทรัพยากรกฎ

ตัวอย่างวิธีเรียกข้อมูลตำแหน่งทรัพยากรที่ใช้ได้มีดังนี้

Java

// Create the custom bidding algorithm structure.
CustomBiddingAlgorithmRulesRef rulesRef =
    service
        .customBiddingAlgorithms()
        .uploadRules(custom-bidding-algorithm-id)
        .setAdvertiserId(advertiser-id)
        .execute();

System.out.printf(
    "The rules can be uploaded to the following resource path: %s%n",
    rulesRef.getResourceName()
);

Python

# Retrieve a usable custom bidding algorithm rules reference
# object.
custom_bidding_algorithm_rules_ref = service.customBiddingAlgorithms().uploadRules(
    customBiddingAlgorithmId=custom-bidding-algorithm-id,
    advertiserId=advertiser-id
).execute()

# Display the new custom bidding algorithm rules reference object.
print('The following custom bidding algorithm rules reference object was retrieved:'
      f' {custom_bidding_algorithm_rules_ref}')

PHP

// Set parent advertiser ID of custom bidding algorithm
// in optional parameters array for request.
$optParams = array('advertiserId' => advertiser-id);

// Retrieve a usable custom bidding algorithm rules reference.
$rulesRefResponse = $this->service->customBiddingAlgorithms->uploadRules(
    custom-bidding-algorithm-id,
    $optParams
);

// Display the new custom bidding algorithm rules reference object resource path.
printf(
    'The rules can be uploaded to the following resource path: %s\n',
    $rulesRefResponse->getResourceName()
);

อัปโหลดไฟล์ AlgorithmRules

หลังจากเรียกข้อมูลตำแหน่งทรัพยากรที่พร้อมใช้งานแล้ว ให้อัปโหลดไฟล์กฎไปยังตำแหน่งนั้นในระบบ Display & Video 360 ด้วยเมธอด media.upload วิธีนี้รองรับการอัปโหลดแบบง่ายที่ต้องใช้พารามิเตอร์การค้นหา uploadType=media

ตัวอย่างวิธีอัปโหลดไฟล์ AlgorithmRules จากออบเจ็กต์อ้างอิงกฎอัลกอริทึมการเสนอราคาที่กำหนดเองซึ่งดึงข้อมูลมามีดังนี้

Java

// Create media object.
GoogleBytestreamMedia media = new GoogleBytestreamMedia();
media.setResourceName(resource-name);

// Create input stream for the rules file.
InputStreamContent rulesFileStream =
    new InputStreamContent(
        null, new FileInputStream(rules-file-path));

// Create media.upload request.
 Media.Upload uploadRequest =
    service
        .media()
        .upload(
            resource-name,
            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/"
                + resource-name));

Python

# Create a media upload object.
media = MediaFileUpload(rules-file-path)

# Create upload request.
upload_request = service.media().upload(
    resourceName=resource-name, media_body=media)

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

# Upload rules file to resource location given in retrieved custom bidding
# algorithm rules reference object.
upload_request.execute()

PHP

// Create a media object.
$mediaBody = new Google_Service_DisplayVideo_GoogleBytestreamMedia();
$mediaBody->setResourceName(resource-name);

// Set parameters for upload request.
$optParams = array(
    'data' => file_get_contents(rules-file-path),
    'uploadType' => 'media',
    'resourceName' => resource-name
);

// Upload rules file to given resource location.
$this->service->media->upload(
    resource-name,
    $mediaBody,
    $optParams
);

cURL

curl --request POST 'https://displayvideo.googleapis.com/upload/media/resource-name?uploadType=media' 
  -H 'authorization: Bearer access-token'
  -H 'Content-Type: text/plain'
  --data-binary @rules-file-path

สร้างออบเจ็กต์กฎ

เมื่ออัปโหลดไฟล์ JSON ของ AlgorithmRules แล้ว ให้สร้างทรัพยากรกฎอัลกอริทึมการเสนอราคาที่กำหนดเองด้วยเมธอด customBiddingAlgorithms.rules.create ออบเจ็กต์ CustomBiddingAlgorithmRules ที่ส่งในคำขอควรมีเฉพาะออบเจ็กต์ CustomBiddingAlgorithmRulesRef เป็นค่าที่กำหนดไว้ของช่อง rules ซึ่งจะเชื่อมโยงไฟล์ JSON AlgorithmRules ที่อัปโหลดกับทรัพยากรกฎใหม่

ตัวอย่างวิธีสร้างทรัพยากรกฎมีดังนี้

Java

// Create the custom bidding algorithm rules structure.
CustomBiddingAlgorithmRules customBiddingAlgorithmRules =
    new CustomBiddingAlgorithmRules()
        .setRules(custom-bidding-algorithm-rules-ref);

// Create the rules resource.
CustomBiddingAlgorithmRules response =
    service
        .customBiddingAlgorithms()
        .rules()
        .create(custom-bidding-algorithm-id, customBiddingAlgorithmRules)
        .setAdvertiserId(advertiser-id)
        .execute();

// Display the new rules resource name.
System.out.printf(
    "The following custom bidding algorithm rules object was created: %s%n",
    response.getName());

Python

# Create the custom bidding algorithm rules object.
rules_obj = {
    'rules': custom-bidding-algorithm-rules-ref
}

# Create the rules resource.
response = service.customBiddingAlgorithms().rules().create(
    customBiddingAlgorithmId=custom-bidding-algorithm-id,
    advertiserId=advertiser-id,
    body=rules_obj).execute()

# Display the new custom bidding algorithm rules object.
print(f'The following custom bidding algorithm rules resource was created: {response}')

PHP

// Create the custom bidding algorithm rules object.
$customBiddingAlgorithmRules =
    new Google_Service_DisplayVideo_CustomBiddingAlgorithmRules();
$customBiddingAlgorithmRules->setRules(custom-bidding-algorithm-rules-ref);

// Set parameters for create rules request.
$optParams = array(
    'advertiserId' => advertiser-id
);

// Create the custom bidding algorithm rules resource.
$result = $this->service->customBiddingAlgorithms_rules->create(
    custom-bidding-algorithm-id,
    $customBiddingAlgorithmRules,
    $optParams
);

// Display the new custom bidding algorithm rules resource name.
printf('The following rules resource was created: %s.\n', $result->getName());

เมื่อคุณสร้างทรัพยากรกฎแล้ว Display & Video 360 จะประมวลผลชุดกฎเพื่อให้แน่ใจว่าใช้ชุดกฎเพื่อให้คะแนนการแสดงผลได้สำเร็จ ดึงข้อมูลสถานะของการประมวลผลนี้ผ่านช่อง state ของออบเจ็กต์กฎ เมื่อยอมรับกฎใหม่ อัลกอริทึมการเสนอราคาที่กำหนดเองจะเริ่มใช้กฎนี้เพื่อให้คะแนนค่าการแสดงผลทันที

หากกฎถูกปฏิเสธ ให้ดึงสาเหตุของการปฏิเสธจาก error ของออบเจ็กต์กฎ ในกรณีที่ถูกปฏิเสธ ให้อัปเดตออบเจ็กต์ AlgorithmRules เพื่อแก้ไขข้อผิดพลาดและทำซ้ำกระบวนการอัปโหลดโดยเริ่มจากการดึงออบเจ็กต์อ้างอิงกฎ

กำหนดอัลกอริทึมการเสนอราคาที่กำหนดเอง

หลังจากสร้างอัลกอริทึมการเสนอราคาที่กําหนดเอง อัปโหลดตรรกะที่ยอมรับ และเป็นไปตามข้อกําหนดที่จําเป็นแล้ว คุณจะกําหนดอัลกอริทึมการเสนอราคาที่กําหนดเองให้กับกลยุทธ์การเสนอราคาของรายการโฆษณาหรือใบสั่งซื้อการใส่โฆษณาได้

คุณสามารถใช้อัลกอริทึมการเสนอราคาที่กำหนดเองในกลยุทธ์การเสนอราคาแบบเพิ่มการใช้จ่ายสูงสุดและเป้าหมายด้านประสิทธิภาพโดยการกำหนด BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_CUSTOM_ALGO และรหัสอัลกอริทึมการเสนอราคาที่กำหนดเองลงในช่อง performanceGoalType และ customBiddingAlgorithmId ตามลำดับ อาจมีหรือต้องใช้พารามิเตอร์การเสนอราคาอื่นๆ ทั้งนี้ขึ้นอยู่กับกลยุทธ์การเสนอราคา

ต่อไปนี้คือตัวอย่างวิธีอัปเดตรายการโฆษณาเพื่อใช้กลยุทธ์การเสนอราคาแบบการใช้จ่ายสูงสุดกับอัลกอริทึมการเสนอราคาที่กำหนดเอง

Java

// Create the line item structure.
LineItem lineItem = new LineItem();

// Create and set the bidding strategy structure.
BiddingStrategy biddingStrategy = new BiddingStrategy();
MaximizeSpendBidStrategy maxSpendBidStrategy =
    new MaximizeSpendBidStrategy()
        .setPerformanceGoalType(
            "BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_CUSTOM_ALGO")
        .setCustomBiddingAlgorithmId(custom-bidding-algorithm-id);
biddingStrategy.setMaximizeSpendAutoBid(maxSpendBidStrategy);
lineItem.setBidStrategy(biddingStrategy);

// Configure the patch request and set update mask to only update
// the bid strategy.
LineItems.Patch request =
    service
        .advertisers()
        .lineItems()
        .patch(advertiser-id, line-item-id, lineItem)
        .setUpdateMask("bidStrategy");

// Update the line item.
LineItem response = request.execute();

// Display the custom bidding algorithm ID used in the new
// bid strategy.
System.out.printf(
    "LineItem %s now has a bid strategy utilizing custom "
        + "bidding algorithm %s%n",
    response.getName(),
    response
        .getBidStrategy()
        .getMaximizeSpendAutoBid()
        .getCustomBiddingAlgorithmId());

Python

# Create the new bid strategy object.
bidding_strategy = {
    'maximizeSpendAutoBid': {
        'performanceGoalType':
            'BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_CUSTOM_ALGO',
        'customBiddingAlgorithmId': custom-bidding-algorithm-id
    }
}

# Create a line item object assigning the new bid strategy.
line_item_obj = {'bidStrategy': bidding_strategy}

# Update the line item with a new bid strategy.
response = service.advertisers().lineItems().patch(
    advertiserId=advertiser-id,
    lineItemId=line-item-id,
    updateMask='bidStrategy',
    body=line_item_obj).execute()

# Display the line item's new bid strategy
print(f'Line Item {response["name"]} is now using the following bid'
     f' strategy: {response["bidStrategy"]}.')

PHP

// Create the line item structure.
$lineItem = new Google_Service_DisplayVideo_LineItem();

// Create and set the bidding strategy structure.
$biddingStrategy =  new Google_Service_DisplayVideo_BiddingStrategy();
$maximizeSpendBidStrategy =
    new Google_Service_DisplayVideo_MaximizeSpendBidStrategy();
$maximizeSpendBidStrategy->setPerformanceGoalType(
    'BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_CUSTOM_ALGO'
);
$maximizeSpendBidStrategy->setCustomBiddingAlgorithmId(
    custom-bidding-algorithm-id
);
$biddingStrategy->setMaximizeSpendAutoBid($maximizeSpendBidStrategy);
$lineItem->setBidStrategy($biddingStrategy);

// Set update mask.
$optParams = array('updateMask' => 'bidStrategy');

// Update the line item.
$result = $this->service->advertisers_lineItems->patch(
    advertiser-id,
    line-item-id,
    $lineItem,
    $optParams
);

// Display the custom bidding algorithm ID used in the new bid strategy.
printf(
    'Line Item %s now has a bid strategy utilizing custom bidding algorithm %s.\n',
    $result['name'],
    $result['bidStrategy']['maximizeSpendBidStrategy']['customBiddingAlgorithmId']
);