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

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

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

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

ออบเจ็กต์ 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

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

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

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

อัลกอริทึมการเสนอราคาที่กำหนดเองตามสคริปต์จะใช้สคริปต์ที่ผู้ใช้ระบุเพื่อประเมินมูลค่าของการแสดงผล ดูตัวอย่างสคริปต์แบบง่ายและรายการช่องขั้นสูงได้ที่ศูนย์ช่วยเหลือของ 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 ซึ่งจะเชื่อมโยงไฟล์ AlgorithmRules JSON ที่อัปโหลดกับแหล่งข้อมูลกฎใหม่

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

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