function main() {
var today = new Date(); //Store today's date
var timeZone = AdsApp.currentAccount().getTimeZone(); //Get timezone of current account
var formattedToday = parseInt(Utilities.formatDate(today, timeZone, 'yyyyMMdd')); //Format today's date to meet AWQL requirements
var formattedFirstDayOfMonth = parseInt(Utilities.formatDate(today, timeZone, 'yyyyMM01')) //Format first of the month to meet AWQL requirements
var query = AdsApp.report("SELECT CampaignName, Cost FROM CAMPAIGN_PERFORMANCE_REPORT DURING " + formattedFirstDayOfMonth + "," + formattedToday); //Sample query
var rows = query.rows()
//Logs campaign name and cost of the campaign for month to date
while(rows.hasNext()) {
var row = rows.next();
Logger.log("Campaign: " + row['CampaignName'] + " cost: " + row['Cost']);
}
}Hi everyone, I wondering if it was possible to code a MTD data pull from the previous year. My end goal is to compare this year's data to last year's data in the same MTD time frame. Any help or suggestions will be greatly appreciated. Thanks!
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/b496cfc6-2484-400a-b76e-570b4e9db1ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hello,Yes, this is possible. Google Ads reports uses AWQL to query reports. The DURING clause can accept two dates representing a date range, formatted as an 8 digit integer (YYYYMMDD). This guide provides information on working with dates and times in Ads scripts. Below is a sample script that pulls cost data at the campaign level from the campaign performance report. See comments in the code for details:function main() {
var today = new Date(); //Store today's date
var timeZone = AdsApp.currentAccount().getTimeZone(); //Get timezone of current account
var formattedToday = parseInt(Utilities.formatDate(today, timeZone, 'yyyyMMdd')); //Format today's date to meet AWQL requirements
var formattedFirstDayOfMonth = parseInt(Utilities.formatDate(today, timeZone, 'yyyyMM01')) //Format first of the month to meet AWQL requirements
var query = AdsApp.report("SELECT CampaignName, Cost FROM CAMPAIGN_PERFORMANCE_REPORT DURING " + formattedFirstDayOfMonth + "," + formattedToday); //Sample query
var rows = query.rows()
//Logs campaign name and cost of the campaign for month to date
while(rows.hasNext()) {
var row = rows.next();
Logger.log("Campaign: " + row['CampaignName'] + " cost: " + row['Cost']);
}
}Regards,MattGoogle Ads Scripts Team
var from = firstDay - minus;
var to = today - minus;
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/77ac1732-95c7-468b-bd5a-ad9c3436068c%40googlegroups.com.