AdWords Script for tracking Quality Scores of SEM Keywords

Quality Score along with bid value determines the order of Ads on search results

Why is Quality Score Important?

Search Engines like Google are keen to ensure that their users enjoy a high quality experience. Even when it comes to delivering Ads on top of search results – it’s important to ensure that the Ads are relevant for the users and are of high quality. Quality Score is a measure of the ad quality on a scale of 1 to 10 .

Google ranks Ads for a particular search result based on a parameter called Ad-Rank. Ad-Rank is the product of a Search- Ads, CPC bid & Quality Score. A high Quality Score thus ensures that you can get a high Ad-rank by paying less.

Let’s consider a keyword for which our average CPC is $5 & the Quality Score is 4. Thus in this case our Ad-rank would be ($5*4) 20.

What would our CPC be if we had to maintain the above Ad-rank but had a Quality Score of 10 ? It’s simple : $5*4/10 = $2. In other words our CPC would be 60% ($3) lower! In we received 1000 clicks in a month – this quality score improvement would lead us to savings of $3,000. Wow! Bad Ads can really prove to be expensive!

What this AdWords Script Does :

Quality Score optimization, is extremely important if you are spending heavily on search engine marketing. However, when you are running SEM at Scale and bidding on thousands of keywords – the task of tracking Quality Scores and prioritizing improvement initiatives, becomes daunting.

The purpose of this script is to understand how much ad-spent on Search we could save monthly by hitting a Quality Score of 10 on all Keywords.

The Script analyses the CPC & Quality Scores for all keywords for which we received clicks in the previous month & calculates the overall savings potential.

The Script also sends the data to a Google sheet for further analysis & triggers a mail to your mailing list summarizing the data.

AdWords Script for analyzing spend savings by Quality Score Improvement:

function main() {
  var SPREADSHEET_URL = "ENTER YOUR SPREADSHEET URL";  
  var columns = ['Keyword','Total clicks','QS', 'CPC','Total Cost','CPC lowering Opportunity', 'Savings Opportunity'] 
  var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL).getActiveSheet();
  sheet.clear();
  sheet.appendRow(columns);
  var costsum=0;
  var savesum=0;
  
  var keywords = AdsApp.keywords().forDateRange("LAST_MONTH").withCondition("Clicks >0").orderBy("Clicks DESC").get()

  while (keywords.hasNext()){
    var keyword = keywords.next();
    //Logger.log(campaign)
    if (keyword.isEnabled()){
      var Keytext=" "+keyword.getText().toString();
      var QS=keyword.getQualityScore();
      var CPC=keyword.getStatsFor("LAST_MONTH").getAverageCpc().toFixed(2);
      var cost=keyword.getStatsFor("LAST_MONTH").getCost().toFixed(2);
      costsum=costsum+Math.floor(cost);
      var clicks=keyword.getStatsFor("LAST_MONTH").getClicks();
      var CTR=keyword.getStatsFor("LAST_MONTH").getCtr();
      var low_CPC=(CPC*QS/10).toFixed(2);
      var low_Cost=low_CPC*clicks;
      var opportunity=cost-low_Cost;
      var k1= [Keytext,clicks,QS,CPC,cost,low_CPC,opportunity.toFixed(2)];
      savesum=savesum+opportunity;
      sheet.appendRow(k1);
    }

    
  }  
  msg1=["Total Cost: ",costsum];
  msg2=["Savings Opportunity: ",savesum.toFixed(2)];
  msg3=["% Savings possible: ",savesum/costsum*100+"%"];
  sheet.appendRow(msg1);
  sheet.appendRow(msg2);
  sheet.appendRow(msg3);
  msg = "Savings Opportunity : "+savesum.toFixed(2)+"<br/>" + "Total Cost: "+costsum + "<br/>"+ "Savings Opportunity %: "+savesum/costsum*100+"%" + "<br/>"+"Please check the following link for Details: "+SPREADSHEET_URL;
  
  var recipients = "ENTER_ID1"+","+"ENTER_ID2"+","+"ENTER_ID3";
  var CC="ENTER_CC_ID1"+","+"ENTER_CC_ID2";
  Logger.log(msg)
  MailApp.sendEmail({
    to: recipients,
    cc: CC,
    subject: "QS Report for Last Month: "+(savesum/costsum*100).toFixed(2)+ "% savings opportunity" ,
    htmlBody: msg,
  });
 


}

The Script Outputs :

The Google Sheet (linked) gets populated as shown below:

Snapshot of Generated Spreadsheet

The mail Generated looks somewhat like this:

Snapshot of the mailer triggered

Further Reading

To learn more about the code, check this documentation by Google

You can check this article of mine to understand how to get started with using AdWords Scripts.