Mcc project data into single sheet

83 views
Skip to first unread message

Chetan Solanki

unread,
Oct 26, 2020, 11:52:43 PM10/26/20
to Google Ads Scripts Forum
Hey, 

I have a MCC account and want to pull monthly spend of individual account in a single sheet.

Help me

Google Ads Scripts Forum Advisor

unread,
Oct 27, 2020, 2:17:31 AM10/27/20
to adwords...@googlegroups.com

Hi there,

Thank you for reaching out to us.

In order to pull metrics (spend) of an account within the MCC, you would need to use the ManagedAccountSelector then iterate on the individual account using the select method. After selecting the account, you're now ready to pull the spend metric using Reports. Utilize the Account Performance Report, then get the Cost metric.

You may see to the sample code below for reference.

var SPREADSHEET_URL = "SPREADSHEET_URL_HERE";
 
function main(){
  
  var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = spreadsheet.getActiveSheet();
  sheet.appendRow(['Account ID', 'Account Name', 'Cost']);
  
  var accountIterator = AdsManagerApp.accounts().get();
  while(accountIterator.hasNext()){
    var account = accountIterator.next();
    AdsManagerApp.select(account);
    
    var report = AdsApp.report(
      'SELECT ExternalCustomerId, AccountDescriptiveName, Cost ' +
      'FROM ACCOUNT_PERFORMANCE_REPORT ' +
      'DURING THIS_MONTH');
 
    var rows = report.rows();
    while (rows.hasNext()) {
      var row = rows.next();
      var customerID = row['ExternalCustomerId'];
      var customerName = row['AccountDescriptiveName'];
      var cost = row['Cost'];
      
      sheet.appendRow([customerID, customerName, cost]);
    }
  }
}

Hope this helps.

Regards,

Google Logo
Mark Kevin Albios
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q274uP0:ref
Reply all
Reply to author
Forward
0 new messages