function main() {
// This is useful when you need to identify accounts that were performing
// well (or poorly) in a given time frame.
var accountIterator = AdsManagerApp.accounts()
.withCondition('Cost > 0')
.forDateRange('LAST_MONTH')
.orderBy('Cost DESC')
.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
var stats = account.getStatsFor('LAST_MONTH');
Logger.log('%s,%s', account.getCustomerId(),
stats.getCost().toFixed(2));
}
}
function main() {
// This is useful when you need to identify accounts that were performing
// well (or poorly) in a given time frame.
var totalCostAccounts = 0;
var accountIterator = AdsManagerApp.accounts()
.withCondition('Cost > 0')
.forDateRange('LAST_MONTH')
.orderBy('Cost DESC')
.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
var stats = account.getStatsFor('LAST_MONTH');
Logger.log('%s,%s', account.getCustomerId(),
stats.getCost().toFixed(2));
totalCostAccounts = parseFloat(totalCostAccounts) + parseFloat(stats.getCost());
}
Logger.log("Total cost of all accounts: " + totalCostAccounts.toFixed(2));
}
// URL of the default spreadsheet template. This should be a copy of
// https://goo.gl/21FW5i
var SPREADSHEET_URL = 'https://docs.google.com/spreadsheets/d/1XgfvsmpsY-uWrc7Od0bgkSaEXKAehYc90r1PMa3i-v4/edit#gid=0';
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getActiveSheet();
function main() {
// This is useful when you need to identify accounts that were performing
// well (or poorly) in a given time frame.
sheet.getRange("A:C").clearContent();
sheet.getRange("c1").setValue("Spend");
sheet.getRange("a1").setValue("Account ID");
sheet.getRange("b1").setValue("Account Name");
var SPREADSHEET_URL = 'INSERT_SPREADSHEET_URL';
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getActiveSheet();
function main() {
sheet.getRange("A:C").clearContent();
sheet.getRange("a1").setValue("Account ID");
sheet.getRange("b1").setValue("Account Name");
sheet.getRange("c1").setValue("Spend");
var totalCostAccounts = 0;
var accountIterator = AdsManagerApp.accounts()
.withCondition('Cost > 0')
.forDateRange('LAST_MONTH')
.orderBy('Cost DESC')
.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
var stats = account.getStatsFor('LAST_MONTH');
Logger.log('%s,%s,%s', account.getCustomerId(), account.getName(),
stats.getCost().toFixed(2));
sheet.appendRow([account.getCustomerId(), account.getName(), stats.getCost().toFixed(2)]);
totalCostAccounts = parseFloat(totalCostAccounts) + parseFloat(stats.getCost());
}
Logger.log("Total cost of all accounts: " + totalCostAccounts.toFixed(2));
}