Shared Budget Management Script

1,177 views
Skip to first unread message

Sergio Bustos

unread,
Oct 10, 2016, 6:10:42 PM10/10/16
to AdWords Scripts Forum
Hi everyone.

I have 160 accounts inside my MCC, each account has its own Shared Budget and it takes me a lot of time to change the Shared Budget for the 160 accounts every day.

Is there a way to massively change the Shared Budgets of all accounts through a script or a spreadsheet?


Trevor

unread,
Oct 10, 2016, 6:31:42 PM10/10/16
to AdWords Scripts Forum
Yes, you can read a little about Budget Selectors and Iterators here: https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_budget as well as the API article that discusses shared budgets: https://developers.google.com/adwords/api/docs/guides/budgets

Do you have a list of every account and the number it should be? Why are you changing it every day? If you're trying to spend a certain amount per month, you could also look into Google's flexible budgets script: https://developers.google.com/adwords/scripts/docs/solutions/mccapp-flexible-budgets

Thank you!

Sergio Bustos

unread,
Oct 10, 2016, 6:38:27 PM10/10/16
to AdWords Scripts Forum
Hi Trevor. Thanks for your quick response.

I do have a list of the Accounts and the number it should have on it's Shared Budget. I'm not really a coding expert, just looking for something that someone might have already developed.

Tyler Sidell (AdWords Scripts Team)

unread,
Oct 11, 2016, 10:29:23 AM10/11/16
to AdWords Scripts Forum
Hi Trevor,

Thanks for providing those solutions for Sergio.  In addition, even though you can't change account budgets through Bulk Uploads, if you want you could use it on the Campaign level.

Regards,
Tyler Sidell
AdWords Scripts Team

Sergio Bustos

unread,
Oct 11, 2016, 1:00:07 PM10/11/16
to AdWords Scripts Forum
Hi All.

I took Flexible Budget Script as an example and made some changes in order for the script to let me change Shared Budgets. Since a change in daily budget for a Campaign with a Shared Budget changes all campaigns' Daily Budgets under it, I was able to create a script to do so.

Here it is (Just make a copy of the Spreadsheet I'm using and change the Account ID's and Campaign Names you want to change):


function main() {
  

var COLUMN = {
  accountId: 2,
  campaignName: 3,
  dailyBudget: 4
};


var CONFIG_START_ROW = 5;


// Core logic for calculating and setting campaign daily budget

  var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getSheets()[0];
  var endRow = sheet.getLastRow();

  var mccAccount = AdWordsApp.currentAccount();
  sheet.getRange('D2').setValue(mccAccount.getCustomerId());
 
  Logger.log(mccAccount.getCustomerId())

  for (var i = CONFIG_START_ROW; i <= endRow; i++) {
    Logger.log('Processing row %s', i);

    var accountId = sheet.getRange(i, COLUMN.accountId).getValue();
    var campaignName = sheet.getRange(i, COLUMN.campaignName).getValue();
    var dailyBudget = sheet.getRange(i, COLUMN.dailyBudget).getValue();


    var accountIter = MccApp.accounts().withIds([accountId]).get();
    if (!accountIter.hasNext()) {
      resultCell.setValue('Unknown account');
      continue;
    }
    var account = accountIter.next();
    MccApp.select(account);

    var campaignIter = AdWordsApp.campaigns()
        .withCondition('CampaignName = "' + campaignName + '"')
        .get();
    if (!campaignIter.hasNext()) {
      resultCell.setValue('Unknown campaign');
      continue;
    }
    var campaign = campaignIter.next();
    var newBudget = (dailyBudget);
    campaign.getBudget().setAmount(newBudget);

Tyler Sidell (AdWords Scripts Team)

unread,
Oct 11, 2016, 2:58:53 PM10/11/16
to AdWords Scripts Forum
Thank you Sergio for providing that solution.

Regards,
Tyler Sidell
AdWords Scripts Team

Jake

unread,
Jul 30, 2018, 1:43:04 PM7/30/18
to AdWords Scripts Forum
This solution does indeed work. Thanks!

* What code is needed to get the Execution Result column to work on Sergio's version of Google's Flexible Budgets Manager Script?

Example results:
Budget already finished Budget not started yet Set today's budget to 12.510000000000002 Set today's budget to 30 Unknown account Unknown campaign Unknown campaign

Anthony Madrigal

unread,
Jul 30, 2018, 3:54:01 PM7/30/18
to AdWords Scripts Forum
Hi Jake,

Since is an old thread, can you please create a new one and provide all the details to your issues?

Regards,
Anthony
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages