मैन्युअल तरीके से बोली लगाना

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 फ़ील्ड का ऐक्सेस दें.

एल्गोरिदम लॉजिक अपलोड करें

कस्टम बिडिंग वाले एल्गोरिदम के हिसाब से, अब आपको एक स्क्रिप्ट या नियम ऑब्जेक्ट बनाना होगा, जहां एल्गोरिदम को इस्तेमाल करने के लिए लॉजिक दिया जा सके.

स्क्रिप्ट अपलोड करें

स्क्रिप्ट पर आधारित कस्टम बिडिंग एल्गोरिदम, इंप्रेशन की वैल्यू का आकलन करने के लिए उपयोगकर्ता से मिली स्क्रिप्ट का इस्तेमाल करते हैं. आसान स्क्रिप्ट के नमूने और बेहतर फ़ील्ड की सूची 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()
);

स्क्रिप्ट फ़ाइल अपलोड करें

उपलब्ध संसाधन की जगह की जानकारी का ऐक्सेस पाने के बाद, media.upload तरीके का इस्तेमाल करके, अपनी स्क्रिप्ट फ़ाइल को Display & Video 360 सिस्टम में उस जगह पर अपलोड करें. इस तरीके से, आसान तरीके से अपलोड किया जा सकता है. इसके लिए, क्वेरी पैरामीटर 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 ऑब्जेक्ट में, script फ़ील्ड की असाइन की गई वैल्यू के तौर पर सिर्फ़ CustomBiddingScriptRef ऑब्जेक्ट शामिल होना चाहिए. इससे अपलोड की गई स्क्रिप्ट फ़ाइल, नए स्क्रिप्ट संसाधन से जुड़ जाती है.

यहां स्क्रिप्ट संसाधन बनाने के तरीके का एक उदाहरण दिया गया है:

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 फ़ाइल अपलोड करें

उपलब्ध संसाधन की जगह की जानकारी का ऐक्सेस पाने के बाद, media.upload तरीके का इस्तेमाल करके, Display & Video 360 सिस्टम में अपने नियमों वाली फ़ाइल को उस जगह पर अपलोड करें. इस तरीके से, आसान तरीके से अपलोड किया जा सकता है. इसके लिए, क्वेरी पैरामीटर 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

नियमों से जुड़ा ऑब्जेक्ट बनाना

AlgorithmRules JSON फ़ाइल अपलोड होने के बाद, customBiddingAlgorithms.rules.create तरीके की मदद से, कस्टम बिडिंग एल्गोरिदम के नियमों वाला रिसॉर्स बनाएं. अनुरोध में पास किए गए CustomBiddingAlgorithmRules ऑब्जेक्ट में, rules फ़ील्ड की असाइन की गई वैल्यू के तौर पर सिर्फ़ CustomBiddingAlgorithmRulesRef ऑब्जेक्ट शामिल होना चाहिए. इससे अपलोड की गई 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']
);