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,
|
||||||