Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alquanna/ccef62eadb3489cf7a0eb3ebdb25a74d to your computer and use it in GitHub Desktop.
Save alquanna/ccef62eadb3489cf7a0eb3ebdb25a74d to your computer and use it in GitHub Desktop.
A quick variation on Frederick Vallaeys' Google Ads script that uses a dynamic field in the DURING clause for the date today
/**
> Export YTD data dynamically using AWQL
> Based on the AWQL to Spreadsheet script by Frederick Vallaeys of Optimyzr.com
> Original post: https://www.optmyzr.com/blog/a-script-to-put-any-adwords-data-in-a-spreadsheet/
> The start date is static, the end date is equal to the date today
IMPORTANT:
> Make sure that you fill in the spreadsheet URL and tab name in lines 24 and 25 for the export
**/
function main() {
var d = new Date();
var ISOdate = d.toISOString();
var fulldate = ISOdate.replace(/T(.*)/i, "");
var nodashdate = fulldate.replace(/-/g, "");
Logger.log(nodashdate);
var QUERIES = [ {'query' : 'SELECT Date, AccountDescriptiveName, CampaignName, Impressions, SearchImpressionShare ' +
'FROM CAMPAIGN_PERFORMANCE_REPORT '+
'WHERE Impressions > 0 '+
'DURING 20200101,' + nodashdate,
'spreadsheetUrl' : '[INSERT SPREADSHEET URL HERE]',
'tabName' : '[INSERT TAB NAME HERE]',
'reportVersion' : 'v201809'
}
];
for(var i in QUERIES) {
var queryObject = QUERIES[i];
var query = queryObject.query;
var spreadsheetUrl = queryObject.spreadsheetUrl;
var tabName = queryObject.tabName;
var reportVersion = queryObject.reportVersion;
Logger.log(spreadsheetUrl + " " + query);
var spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl);
var sheet = spreadsheet.getSheetByName(tabName);
var report = AdWordsApp.report(query, {apiVersion: reportVersion});
report.exportToSheet(sheet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment