A script to improve the low quality score of Google Adwords

With on page as well as off page equally placed at a digital marketing campaign, the role of Google Adwords is of the optimum value and importance in paid campaigns. Among varying factors responsible for the successful accomplishment of the paid campaigns as employed by the digital marketing agencies, the low quality score is most of the time is responsible for the low performance of the adwords campaign or any another paid digital marketing campaign. 
However, to ease the woes of digital marketers, a new script has been arrived on Digital marketing agency surface in order to counter the problems posed by the lower quality score. In quality score Google measures an ad relevance based upon a keyword-level metric on a scale from 1 to 10 that showcases how important an ad is to an individual campaigner. 
Generally, on the following criteria an ad server quantifies quality score of a campaign and efforts of a digital marketing agency. The areas of determination of low quality score includes historical click-through-rate (CTR), the relevance of the keyword and ad to the search query and landing page quality.    
The importance of the quality score could be estimated from the factor that it helps in estimating the AD rank that helps in deciding where your ad appears in the search engine result page is also a factor in determining how it influences over the cost-per-click. As higher is your ad’s quality score as much better they will perform on the adwords. According to an estimation an adword could save approximately the cost of a campaign from 50 percent to 400 percent. Finding low quality score keywords has become quite easy with the several scripts easily available on the internet.   
With the script below, it becomes much easier to fix low Quality Score keywords. It’ll also save you time you can spend on more interesting activities. All you need to do is set a Quality Score threshold, and the script will email you where the keywords with a score equal or lower to that value are, so you can immediately address the problem.

/**
 *
 * Low Quality Score Alert
 *
 * This script finds the low QS keywords (determined by a user defined threshold)
 * and sends an email listing them. Optionally it also labels and/or pauses the
 * keywords.
 *
 * Version: 1.0
 * Google AdWords Script maintained on brainlabsdigital.com
 *
 **/

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//Options

var EMAIL_ADDRESSES = [“alice@example.com”, “bob@example.co.uk”];
// The address or addresses that will be emailed a list of low QS keywords
// eg [“alice@example.com”, “bob@example.co.uk”] or [“eve@example.org”]

var QS_THRESHOLD = 3;
// Keywords with quality score less than or equal to this number are
// considered ‘low QS’

var LABEL_KEYWORDS = true;
// If this is true, low QS keywords will be automatically labelled

var LOW_QS_LABEL_NAME = “Low QS Keyword”;
// The name of the label applied to low QS keywords

var PAUSE_KEYWORDS = false;
// If this is true, low QS keywords will be automatically paused
// Set to false if you want them to stay active.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Functions

function main() {
  Logger.log(“Pause Keywords: ” + PAUSE_KEYWORDS);
  Logger.log(“Label Keywords: ” + LABEL_KEYWORDS);

  var keywords = findKeywordsWithQSBelow(QS_THRESHOLD);
  Logger.log(“Found ” + keywords.length + ” keywords with low quality score”);

  if (!labelExists(LOW_QS_LABEL_NAME)) {
    Logger.log(Utilities.formatString(‘Creating label: “%s”‘, LOW_QS_LABEL_NAME));
    AdWordsApp.createLabel(LOW_QS_LABEL_NAME, ‘Automatically created by QS Alert’, ‘red’);
  }

  var mutations = [
    {
      enabled: PAUSE_KEYWORDS,
      callback: function (keyword) {
        keyword.pause();
      }
    },
    {
      enabled: LABEL_KEYWORDS,
      callback: function (keyword, currentLabels) {
        if (currentLabels.indexOf(LOW_QS_LABEL_NAME) === -1) {
          keyword.applyLabel(LOW_QS_LABEL_NAME);
        }
      }
    }
  ];

  var chunkSize = 10000;
  var chunkedKeywords = chunkList(keywords, chunkSize);

  Logger.log(“Making changes to keywords..”);
  chunkedKeywords.forEach(function (keywordChunk) {
    mutateKeywords(keywordChunk, mutations);
  });

  if (keywords.length > 0) {
    sendEmail(keywords);
    Logger.log(“Email sent.”);
  } else {
    Logger.log(“No email to send.”);
  }
}

function findKeywordsWithQSBelow(threshold) {
  var query = ‘SELECT Id, AdGroupId, CampaignName, AdGroupName, Criteria, QualityScore, Labels’
    + ‘ FROM KEYWORDS_PERFORMANCE_REPORT WHERE Status = “ENABLED” AND CampaignStatus = “ENABLED” AND AdGroupStatus = “ENABLED”‘
    + ‘ AND HasQualityScore = “TRUE” AND QualityScore <= ‘ + threshold;
  var report = AdWordsApp.report(query);     
  var rows = report.rows();   

  var lowQSKeywords = [];
  while (rows.hasNext()) {
    var row = rows.next();
    var lowQSKeyword = {
      campaignName: row[‘CampaignName’],
      adGroupName: row[‘AdGroupName’],
      keywordText: row[‘Criteria’],
      labels: (row[‘Labels’].trim() === ‘–‘) ? [] : JSON.parse(row[‘Labels’]),
      uniqueId: [row[‘AdGroupId’], row[‘Id’]],
      qualityScore: row[‘QualityScore’]
    };
    lowQSKeywords.push(lowQSKeyword);
  }
  return lowQSKeywords;
}

function labelExists(labelName) {
  var condition = Utilities.formatString(‘LabelName = “%s”‘, labelName);
  return AdWordsApp.labels().withCondition(condition).get().hasNext();
}

function chunkList(list, chunkSize) {
  var chunks = [];
  for (var i = 0; i < list.length; i += chunkSize) {
    chunks.push(list.slice(i, i + chunkSize));
  }
  return chunks;
}

function mutateKeywords(keywords, mutations) {
  var keywordIds = keywords.map(function (keyword) {
    return keyword[‘uniqueId’];
  });

  var mutationsToApply = getMutationsToApply(mutations);
  var adwordsKeywords = AdWordsApp.keywords().withIds(keywordIds).get();

  var i = 0;
  while (adwordsKeywords.hasNext()) {
    var currentKeywordLabels = keywords[i][‘labels’];
    var adwordsKeyword = adwordsKeywords.next();

    mutationsToApply.forEach(function(mutate) {
      mutate(adwordsKeyword, currentKeywordLabels);
    });
    i++;
  }
}

function getMutationsToApply(mutations) {
  var enabledMutations = mutations.filter(function (mutation) {
    return mutation[‘enabled’];
  }); 

  return enabledMutations.map(function (condition) {
      return condition[‘callback’];
  });
}

function sendEmail(keywords) {
  var subject = “Low Quality Keywords Paused”;
  var htmlBody =
      “Keywords with a quality score of less than ” + QS_THRESHOLD + “found.”
      + “Actions Taken:”
      + ”


          + ”

  • Paused: ” + PAUSE_KEYWORDS + “

  •       + ”

  • Labelled with " + LOW_QS_LABEL_NAME + ": ” + LABEL_KEYWORDS + “

  •       + “


      + renderTable(keywords);

  MailApp.sendEmail({
    to: EMAIL_ADDRESSES.join(“,”),
    subject: subject,
    htmlBody: htmlBody
  });
}

function renderTable(keywords) {
  var header = ‘

  + ”
  + ”
  + ”
  + ”
  + ”
  + ”;

  var rows = keywords.reduce(function(accumulator, keyword) {
    return accumulator
      + ‘ ‘;
  }, “”);

  var footer = ‘

Campaign Name Ad Group Name Keyword Text Quality Score
‘ + [
      keyword[‘campaignName’],
      keyword[‘adGroupName’],
      keyword[‘keywordText’],
      keyword[‘qualityScore’]
    ].join(‘
‘)
      + ‘

‘;

  var table = header + rows + footer;
  return table;
}

Previous post How Digital Marketing Agencies Use Web Personalization Techniques for Lead Generation?
Next post How to Pick the Best Exhibition Stall Designer in Mumbai?