Keyword formatting when exporting to sheet

10 views
Skip to first unread message

Quinton Florence

unread,
Dec 19, 2018, 8:44:38 PM12/19/18
to Google Ads Scripts Forum
Currently running this script to export data from the keyword performance report to a google sheet. I was wondering if there was a way to get the script to export the keywords how they appear in the UI ( [keyword], "keyword", +keyword ). Secondly, is there an "Order By' selector for campaign names so the data would be sorted in ASC order? Thanks for the help.


function main() {
var row1 = 1;
    var SPREADSHEET_URL = "";
    var SHEET_NAME = '';
    var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
    var sheet = ss.getSheetByName(SHEET_NAME);
  
    sheet.clearContents();

    sheet.getRange("A1").setValue("CID").setFontWeight("bold");
    sheet.getRange("B1").setValue("Account Name").setFontWeight("bold");
    sheet.getRange("C1").setValue("Campaign Name").setFontWeight("bold");
    sheet.getRange("D1").setValue("Ad group Name").setFontWeight("bold");
    sheet.getRange("E1").setValue("Keyword ID").setFontWeight("bold");
    sheet.getRange("F1").setValue("Keyword").setFontWeight("bold");
    sheet.getRange("G1").setValue("Match type").setFontWeight("bold");
    sheet.getRange("H1").setValue("Impressions").setFontWeight("bold");
    sheet.getRange("I1").setValue("Avg Pos").setFontWeight("bold");
    sheet.getRange("J1").setValue("IS %").setFontWeight("bold");
    sheet.getRange("K1").setValue("IS LTR").setFontWeight("bold");
  
        var report = AdWordsApp.report(

            'SELECT ExternalCustomerId, CustomerDescriptiveName, CampaignName, AdGroupName, Id, Criteria, KeywordMatchType, Impressions, AveragePosition, SearchImpressionShare, SearchRankLostImpressionShare FROM KEYWORDS_PERFORMANCE_REPORT ' +
            'WHERE Impressions > 0 ' + 'DURING LAST_7_DAYS'); 
      
         
     var rows = report.rows();
        while (rows.hasNext()) {
            var row = rows.next();
          

          
           sheet.appendRow([formatExternalCustomerId(row['ExternalCustomerId']), 
                row['CustomerDescriptiveName'],
                row['CampaignName'],
                row['AdGroupName'],
                row['Id'],
                row['Criteria'],
                row['KeywordMatchType'],
                row['Impressions'],
                row['AveragePosition'],
                row['SearchImpressionShare'],
                row['SearchRankLostImpressionShare']]);

        }
    }

function formatExternalCustomerId(id) {

    var returnValue = id.substr(0, 3) + "-" + id.substr(3, 3) + "-" + id.substr(6, 4);
    return returnValue;

}


Reply all
Reply to author
Forward
0 new messages