Search Lost IS (budget) optimizatons

100 views
Skip to first unread message

Adam Guttadauro

unread,
May 16, 2024, 4:28:50 PM5/16/24
to Google Ads Scripts Forum
Hi!

Trying to create a script that increases budgets 50% if the Search Lost IS due to budget passes 50%

Here is what I have so far

function main() {
  // Get all campaigns in the account
  var campaigns = AdsApp.campaigns().get();
 
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();
   
    // Get the statistics for the campaign
    var stats = campaign.getStatsFor('LAST_7_DAYS');
   
    // Retrieve the lost impression share due to budget
    var lostImpressionShareDueToBudget = stats.getSearchBudgetLostImpressionShare();
   
    // Calculate the current budget of the campaign
    var currentBudget = campaign.getBudget().getAmount();
   
    // Calculate the proposed budget increase (50% increase)
    var proposedBudgetIncrease = currentBudget * 0.5;
   
    // If the impression share lost due to budget is more than 50%
    if (lostImpressionShareDueToBudget > 50) {
      // Increase the budget by 50%
      var newBudget = currentBudget + proposedBudgetIncrease;
     
      // Set the new budget for the campaign
      campaign.getBudget().setAmount(newBudget);
     
      // Log the changes
      Logger.log('Campaign ' + campaign.getName() + ' budget increased by 50% to ' + newBudget);
    } else {
      Logger.log('No budget increase needed for campaign ' + campaign.getName());
    }
  }
}
Error: TypeError: stats.getSearchBudgetLostImpressionShare is not a function
at main (Code:12:48) at Object.<anonymous> (adsapp_compiled:20513:54)


any advice?

Google Ads Scripts Forum

unread,
May 21, 2024, 5:40:58 AM5/21/24
to Google Ads Scripts Forum

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

I would like to inform you that the function “stats.getSearchBudgetLostImpressionShare()” is not valid in the Google Ads Script. You can get the metrics by using the "SELECT metrics.search_budget_lost_impression_share FROM campaign" code.

I hope this helps. Kindly reach out to us with the below details if you still face any issue.

  • Google Ads account ID/CID
  • Name of the affected script

You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,

Google Ads Scripts team

Nils Rooijmans

unread,
May 30, 2024, 2:10:00 AM5/30/24
to Google Ads Scripts Forum
here's your problem: getSearchBudgetLostImpressionShare() isn't a standard function/method that can be applied to a stats object.

to fix your issue you need another way to get the campaigns that have 'Search Lost IS due to budget > 50%'.

Here's some code to help you get started:

you can use the campaign selector to get the campaigns that  have 'Search Lost IS due to budget > 50%' , ie: 

var TARGET = 0.5; // 50%
var campaignSelector = AdsApp.campaigns().withCondition(`metrics.search_budget_lost_top_impression_share > ${TARGET}`).withCondition(`campaign.status = ENABLED`).forDateRange(`LAST_7_DAYS`).get();


this will select these campaigns for you, next you can use a campaign iterator to go over them and adjust the budgets.

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/
Reply all
Reply to author
Forward
0 new messages