Autobidding

Get bidding strategies
Set campaign bidding strategy
Add bidding strategies

Get bidding strategies


function getBiddingStrategy(){
  const accountId = AdsUtilities.getCurrentAccountId();
  const biddingStrategies = Search.BiddingStrategyService.get({
    accountId: accountId,
  }).rval;
  if (biddingStrategies.totalNumEntries == 0) {
    Logger.log('Target ID does not exist.');
    return;
  }
  for (let i = 0; i < biddingStrategies.values.length; i++){
    let biddingStrategy = biddingStrategies.values[i].biddingStrategy;
    let type = biddingStrategy.biddingScheme.type;
    Logger.log('portfolioBiddingId-> ' + biddingStrategy.portfolioBiddingId
      + ', portfolioBiddingName-> ' + biddingStrategy.portfolioBiddingName + ', type-> ' + type);
  }  
}

Set campaign bidding strategy


function setCampaignBiddingStrategy() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const campaignIds = [1111111, 2222222];//Empty when not specified
  const portfolioBiddingId = 33333;
  const biddingStrategies = Search.BiddingStrategyService.get({
    accountId: accountId,
    portfolioBiddingIds: [portfolioBiddingId],
  }).rval;
  if (biddingStrategies.totalNumEntries == 0) {
    Logger.log('Target ID of bidding strategy does not exist.');
    return;
  }
  const type = biddingStrategies.values[0].biddingStrategy.biddingScheme.type;
  let campaignArray = [];
  for (let i = 0; i < campaignIds.length; i++) {
    //Create new operand to set
    let setCampaign = {
      accountId: accountId,
      campaignId: campaignIds[i],
      biddingStrategyConfiguration:{
        portfolioBiddingId: portfolioBiddingId
      }
    };
    campaignArray.push(setCampaign);
  }
  const campaignsSet = Search.CampaignService.set({
    accountId: accountId,
    operand: campaignArray,
  }).rval;
  for (let i = 0; i < campaignsSet.values.length; i++) {
    if (campaignsSet.values[i].operationSucceeded) {
      let campaign = campaignsSet.values[i].campaign;
      let biddingStrategy = campaign.biddingStrategyConfiguration;
      Logger.log('campaignId-> ' + campaign.campaignId + ', campaignName-> ' + campaign.campaignName
        + ' has been changed to portfolioBiddingId-> ' + biddingStrategy.portfolioBiddingId
        + ', biddingStrategyName-> ' + biddingStrategy.portfolioBiddingName + ', type-> ' + type);
    } else {
      let campaign = campaignsGet.values[i].campaign;
      Logger.log('campaignId-> ' + campaign.campaignId + ', campaignName-> ' + campaign.campaignName + ' could not be changed.');
    }
  }
}

Add bidding strategies


function addCampaignBiddingStrategy() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const biddingStrategyArray = [
    {
      accountId: accountId,
      biddingScheme: {
        targetRoasBiddingScheme: {
          targetRoas: 0.5,//0.01 ~1000.00(1%~100000%)
        },
        type: 'TARGET_ROAS',
      },
      portfolioBiddingName: 'portfolioBiddingNameAAA',
    },
    {
      accountId: accountId,
      biddingScheme: {
        maximizeClicksBiddingScheme: {
          bidCeiling: 1000,
        },
        type: 'MAXIMIZE_CLICKS',
      },
      portfolioBiddingName: 'portfolioBiddingNameBBB',
    },
    {
      accountId: accountId,
      biddingScheme: {
        targetCpaBiddingScheme: {
          targetCpa: 200,
        },
        type: 'TARGET_CPA',
      },
      portfolioBiddingName: 'portfolioBiddingNameCCC',
    },
    {
      accountId: accountId,
      biddingScheme: {
        targetImpressionShareScheme: {
          location: 'ANYWHERE_ON_PAGE',
          bidCeiling: 100,
          targetImpressionShare: 100,
        },
        type: 'TARGET_IMPRESSION_SHARE',
      },
      portfolioBiddingName: 'portfolioBiddingNameDDD',
    }
  ];//Multiple selections are possible
  const biddingStrategies = Search.BiddingStrategyService.add({
    accountId: accountId,
    operand: biddingStrategyArray,
  }).rval;
  for (let i = 0; i < biddingStrategies.values.length; i++) {
    if (biddingStrategies.values[i].operationSucceeded) {
      let biddingStrategy = biddingStrategies.values[i].biddingStrategy;
      Logger.log('portfolioBiddingId-> ' + biddingStrategy.portfolioBiddingId 
        + ', portfolioBiddingName-> ' + biddingStrategy.portfolioBiddingName
        + ', type-> ' + biddingStrategy.biddingScheme.type + ' has been added.');
    } else {
      Logger.log('portfolioBiddingName-> ' + biddingStrategyArray[i].portfolioBiddingName + ' could not be added.');
    }
  }
}