Hi Katrin,
The script defines an account iterator, but the account iterator is never iterated over, nor is AdsManagerApp.select used. Please see this guide on working AdsManager scripts.
Since you are running this at the account level, presumably you'll want to output this report to different sheets. If the script only points to one sheet, it will overwrite the sheet with a new report for each account.
Lastly, I would recommend writing data with the AdsApp exportToSheet method instead of using the SpreadsheetApp setValues method. The exportToSheet method will include headers.
Regards,
Matt
Google Ads Scripts Team
var spreadsheet = SpreadsheetApp.create("Report output");
function main() {
var accountSelector = AdsManagerApp.accounts()
.withCondition("Impressions > 0")
.forDateRange("20200101", "20201231");
accountSelector.executeInParallel("generateReports");
}
function generateReports() {
var accountId = AdsApp.currentAccount().getCustomerId();
spreadsheet.insertSheet(accountId);
var report = AdsApp.report(
'SELECT AccountDescriptiveName, CampaignName, Conversions, Date, Impressions, Clicks, Cost, Labels ' +
'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
' WHERE Cost > 0 ' +
'DURING 20200101, 20201231 '
);
report.exportToSheet(spreadsheet.getActiveSheet());
Logger.log("Report available at " + spreadsheet.getUrl());
}
Hi Matt,
Hi Ejay,