An Improved AdWords Performance Reporting Script

An Updated AdWords Performance Reporting Script With Phone Impressions and Calls


Recently our SEM team wanted to automate some reports that we review weekly for each client's AdWords account. We found a great script at, however it was a little dated because there was no data reported for phone impressions or phone calls.

Additionally, the script generated more data than we needed, specifically the tabs for 'Campaign Performance Month to Date' and 'Daily Keyword Performance for the Past 7 Days'.

Our development team is always up for a challenge, so we tasked them with rewriting the script to meet our needs. Since they mostly work in PHP, we figured the Javascript code might help polish up some rusty skills.

The developers did a great job, and we've put this to use now for our client's accounts. We thought it might be nice to share with others who could benefit by saving some time with the automated reporting.

To use the script:

  1. Create a new Google Sheet in any desired location your Google drive. Name the sheet whatever you like (example "Weekly Summary Report- ACCOUNT NAME").
  2. In AdWords, go to Bulk Operations->Scripts.
  3. Click the '+ Script' button.
  4. Enter a name for the Script (example "Weekly Summary- Report Account Name".
  5. Copy the script code below, and paste in the editor area replacing the default 3 lines of code.
  6. Copy the URL of the sheet you created in step 1.
  7. Replace the 'var SPREADSHEET URL' value in the code with the URL of your sheet.
  8. Save the script.
  9. Authorize the script using the 'Authorize now' button.
  10. Click 'Run script now'. You can safely run without previewing.
  11. After several seconds, check your spreadsheet and see the data that was populated by the script. You will see a tab with Campaign Performance last month, Campaign Performance past 7 days, and Keyword Performance e past 7 days.
  12. Use the '+ Create schedule' link to the right of your script to set a weekly run at any desired time. You can also run at other frequencies if you like.
  13. Relax knowing that you will have a useful report to review your account performance automatically generated weekly!


  * Campaign and Keyword Summary Report
  * Version: 1.3
  * Changelog v1.3 - imrpoved reporting to add Phone Impressions and Phone Calls
  * Modified by BCS Website Services
  * Version: 1.2
  * Changelog v1.2 - Fixed INVALID_PREDICATE_ENUM_VALUE
  * ChangeLog v1.1 - Removed apiVersion from reporting call
  * Originally Created By: Russ Savage
  function main() {
    //These names are important. change them with caution
    var tabs = ['camp_perf_last_month','keyword_perf_7_days','camp_perf_7_days'];
    for(var i in tabs) {
    var results = runQuery(tabs[i]);
  //Helper function to get or create the spreadsheet
  function getSheet(tab) {
    var s_sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
    var sheet;
    try {
    sheet = s_sheet.getSheetByName(tab);
    if(!sheet) {
      sheet = s_sheet.insertSheet(tab, 0);
    } catch(e) {
    sheet = s_sheet.insertSheet(tab, 0);
    return sheet
  //Function to write the rows of the report to the sheet
  function writeToSpreadsheet(tab,rows) {
    var to_write = convertRowsToSpreadsheetRows(tab,rows);
    var s_sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
    var sheet = getSheet(tab);
    var numRows = sheet.getMaxRows();
    if(numRows < to_write.length) {
    var range = sheet.getRange(1,1,to_write.length,to_write[0].length);
    var headers = [];
    if(tab.indexOf('camp_perf_7') == 0) {
    headers.push('Campaign Name');
    headers.push('Campaign Status');
    if(tab.indexOf('keyword_') == 0) {
    headers = headers.concat(['Ad Group Name',
                    'Quality Score',
                    'Keyword Match Type']);
      if(tab.indexOf('camp_perf_') == 0) {
    headers = headers.concat(['Phone Impressions',
                    'Phone Calls']);
    headers = headers.concat(['Clicks',
                 'Average Cpc',
                 'Average Position',
                 'Cost per Conversion ',
                 'Conversion Rate',
                 'Conversion Value'
     if(tab.indexOf('camp_perf_last_') == 0) {
      headers = [headers];
  function getdateweeks(days,format){
  //var days; // Days you want to subtract
  var date = new Date();
  var last = new Date(date.getTime() - (days * 24 * 60 * 60 * 1000));
  var day =last.getDate();
  var month=last.getMonth()+1;
  var year=last.getFullYear();
      return year+""+month+""+day;
      return month+"/"+day+"/"+year;  

  //A generic function used to build and run the report query
  function runQuery(tab) {
    var API_VERSION = { includeZeroImpressions : false };
    var cols = getColumns(tab);
    var report = getReport(tab);
    var date_range = getDateRange(tab);
    var where = getWhereClause(tab);
    var query = ['select',cols.join(','),'from',report,where,'during',date_range].join(' ');
   var report_iter =, API_VERSION).rows();
    var nextnode="";
    var rows = [];
    while(report_iter.hasNext()) {;
        nextnode['CampaignId']=getdateweeks(7,2)+" - "+getdateweeks(1,2);
    return rows;
  //This function will convert row data into a format easily pushed into a spreadsheet
  function convertRowsToSpreadsheetRows(tab,rows) {
    var cols = getColumns(tab);
    var ret_val = [cols];
    for(var i in rows) {
    var r = rows[i];
    var ss_row = [];
    for(var x in cols) {
    return ret_val;
  //Based on the tab name, this returns the report type to use for the query
  function getReport(tab) {
    if(tab.indexOf('camp_') == 0) {
    if(tab.indexOf('keyword_') == 0) {
    throw new Exception('tab name not recognized: '+tab);
  //Based on the tab name, this returns the where clause for the query
  function getWhereClause(tab) {
    if(tab.indexOf('camp_') == 0) {
    return 'where CampaignStatus = ENABLED';
    if(tab.indexOf('keyword_') == 0) {
    return 'where CampaignStatus = ENABLED and AdGroupStatus = ENABLED and Status = ENABLED';
    throw new Exception('tab name not recognized: '+tab);
  //Based on the tab name, this returns the columns to add into the report
  function getColumns(tab) {
    var ret_array = [];
    if(tab.indexOf('camp_perf_7') == 0) {
    if(tab.indexOf('keyword_') == 0) {
    ret_array = ret_array.concat(['AdGroupName',
      if(tab.indexOf('camp_perf_') == 0) {
    ret_array = ret_array.concat(['NumOfflineImpressions',
     ret_array = ret_array.concat(['Clicks',
    if(tab.indexOf('camp_perf_last_') == 0) {
    return ret_array;
  //Based on the tab name, this returns the date range for the data.
  function getDateRange(tab) {
    if(tab.indexOf('keyword_perf_7_days') >= 0) {
    return 'LAST_7_DAYS';
     if(tab.indexOf('camp_perf_7_days') >= 0) {
    return getdateweeks(7,1)+","+getdateweeks(1,1);
    if(tab.indexOf('mtd') >= 0) {
    return 'THIS_MONTH';
    if(tab.indexOf('last_month') >= 0) {
    return 'LAST_MONTH';
    throw new Exception('tab name not recognized: '+tab);


sample reporting Improved AdWords Performance Reporting Script

Get started with everything you need to know about developing a website. Download My Free E-Book

Our Before & After Designs

Look at what a difference a website redesign makes!

aiava old Before
aiava new After

- Before and After-