Google Ads Script for Exporting Year-to-Date Data to Sheets

Forum White Hat SEO PPC Google Ads Script for Exporting Year-to-Date Data to Sheets

Viewing 1 post (of 1 total)
  • Author
  • #8053

    Hi everyone — I’m back again with another nifty variation on [the Google Ads script]( for exporting data into Sheets, from [](

    If you’re using this, you may have noticed that while there are a variety of options to export data, there’s really no one option to export data for the year to date (ex. January 1, 2020 to today). You’ll need to have to type in manually the start date and the end date, which isn’t really practical if you have to update the script everyday for those dates.

    So what I did was to create a little JavaScript variable to pull the date today inside the query automatically. The updated code is below:

    > Export YTD data dynamically using AWQL
    > Based on the AWQL to Spreadsheet script by Frederick Vallaeys of
    > Original post:
    > The start date is static, the end date is equal to the date today

    > 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, “”);

    var QUERIES = [ {‘query’ : ‘SELECT Date, AccountDescriptiveName, CampaignName, Impressions, SearchImpressionShare ‘ +
    ‘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 =, {apiVersion: reportVersion});


    Hope this helps! You can also use the script for specific time periods–you’ll just need to modify either the start or end dates. Feel free to play around with the date variable as well to pull dates other than today–maybe you want yesterday? Or if your client has some specific way to determine the week–let’s say their week starts on Friday; Google Ads doesn’t have a default setting for that.

    [Obligatory link to my blog post about this as well, which has more detail about the script.](

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Scroll to Top