This might not be a core Script-specific question but any guidance is still appreciated. I manage a massive managed account and wanted to build a script that sends out a daily notification when there's a change in campaign status from yesterday to today. I managed to build out a script that records Campaign Status for "DURING TODAY" and "DURING YESTERDAY" in 2 separate GSheet tabs (code for TODAY is pasted below). Eventually I can write a script within the sheet to vlookup both tabs and send out a notification for only those campaigns with changes between the two statuses.
I realized much later that this only works if Campaign Status is static in Google Ads reporting. Meaning, if Campaign A was 'Paused' on 01-31-2019 and was 'Enabled' on 02-01-2019, when I run the report on 02-01-2019, it needs to show me 'Campaign Status = Paused' for 01-31-2019 and Campaign Status = Enabled' for 02-01-2019. Can somebody validate that this is how it works? Or does it pull real-time campaign status?
Again, any help would be deeply appreciated. A few hours work of code is on the line (PS. I'm not very skilled at JS, so as you can imagine this was a pretty stressful few hours worth of work!)
Also happy if somebody can suggest a simpler (code-wise) and more reliable way of achieving the same end.
var spreadsheet = SpreadsheetApp.openByUrl('INSERT_URL_HERE');
function main(){
spreadsheet.setSpreadsheetLocale('en');
var sheetSettings = createOrGetSheet(spreadsheet, 'Settings', 0);
var settingRange = sheetSettings.getRange(1,1,1,2);
var sheet = createOrGetSheet(spreadsheet, 'Today', 1);
var report = AdsApp.report(
" SELECT CampaignName, CampaignId, CampaignStatus, Date" +
" FROM CAMPAIGN_PERFORMANCE_REPORT"+
" WHERE CampaignStatus != REMOVED"+
" DURING TODAY");
report.exportToSheet(sheet);
Logger.log("Report available at " + spreadsheet.getUrl());
}
//Creating or returning selected sheet
function createOrGetSheet(reportSpreadsheet, name, position) {
var sheet = reportSpreadsheet.getSheetByName(name);
if(sheet == null) {
return reportSpreadsheet.insertSheet(name,position);
} else {
return sheet;
}
}