[Adwords script] Flag High Keyword Ad groups Watchdog

For any serious PPC marketer, Single Keyword ad groups are the holy grail when it comes to increasing PPC performance.

However, when you are managing accounts that contain thousands of different keywords and ad groups that are constantly being expanded then it can be hard to ensure you adhere to this structure.

So we built a script that automatically builds you a report showing you which ad groups contain more than a certain number of keywords, so you can go in a break the ad groups out into single keyword ad groups.

Here we programmed the script to output all ad groups that contain more than one keyword in an account that we were reviewing. As you can see below the script shows to the number of keywords within the ad group as well as the URL of that ad group so you can link directly to it.

How to use the script

There are four variables to set in the user area at the top of the script:

  • The number of keywords: Here you can set the maximum number of keywords that an ad group should have, otherwise it will be flagged and the number of keywords that the ad group contains and the URL of that ad group will be written into the Google Sheet. We would suggest setting this to 1.
  • Campaigns to include: This is where you define which campaigns you want to be included, which are specified in a list. E.g. [“campaign1”,”campaign2”]. If you want all campaigns to be included, leave the brackets empty, i.e. []
  • Campaigns to exclude: This is where you define the list of campaigns you want to be excluded, e.g. [“campaign3”,”campaign4”]. If you don’t want any campaigns to be excluded, leave the brackets empty, i.e. []
  • Spreadsheet URL: This is the URL of the spreadsheet that you would like the report being outputted to. This can be generated by going to Google Sheets and creating a new sheet and then copying the URL.
* Ad group keyword number checker script
* Version: 1.0
* maintained by Clicteq


//Specify the number of active keywords

//Specify what word the campaigns should include, use '' to include all campaigns. Use double quotation marks for words with spaces, for example '"x y"'


//Specify what word the campaigns should not include, use '' to include all campaigns. Use double quotation marks for words with spaces.


//Specify sheet url, for example example https://docs.google.com/spreadsheets/d/1V6DsB7kuNKumZPsycNo9z5lPZcuZGlCfbSVCTwHV50U/edit#gid=0

URL = 'https://docs.google.com/spreadsheets/d/11WDxR5Yt1Oh48kUInUv4J-AMPkL5efsiwOH9HmGGlpg/edit#gid=0'


function getCampaigns()
  var campaigns = AdWordsApp.campaigns().withCondition('Status = ENABLED').get()
  else   if(INCLUDEDCAMPAIGNS != '')
  var campaigns = AdWordsApp.campaigns().withCondition('Status = ENABLED AND CampaignName CONTAINS ' + INCLUDEDCAMPAIGNS).get()
  else   if(EXCLUDEDCAMPAIGNS != '')
  var campaigns = AdWordsApp.campaigns().withCondition('Status = ENABLED AND CampaignName DOES_NOT_CONTAIN ' + EXCLUDEDCAMPAIGNS).get()
  return campaigns}

function writeToSheet(rows)
  var sheet = SpreadsheetApp.openByUrl(URL)
  var range = sheet.getRange('A1:B' + rows.length)

function main()

  var accId = AdWordsApp.currentAccount().getCustomerId().replace('-','').replace('-','')
  var campaigns = getCampaigns()
  var rows = [['number of keywords','Ad groups Url']]
  var urlPattern = 'https://adwords.google.com/aw/keywords?__e={accid}&campaignId={cid}&adGroupId={agid}'.replace('{accid}', accId)
  var urlPattern0 = urlPattern
    var campaign = campaigns.next()
    var cid = campaign.getId()
    var urlPattern1 = urlPattern.replace('{cid}', cid)
    var adgroups = campaign.adGroups().withCondition('Status = ENABLED').get()
      var adgroup = adgroups.next()
      var numOfKeywords = adgroup.keywords().withCondition('Status = ENABLED').get().totalNumEntities()
      if(numOfKeywords > NUMBEROFKEYWORDS)
        urlPattern = urlPattern1
        var agname = adgroup.getName()
        var agid = adgroup.getId()
        urlPattern = urlPattern.replace('{agid}', agid)
    urlPattern = urlPattern0    


wesley parker
About wesley parker

Wesley is Founder and CEO at Clicteq. He currently manages a £6 Mil Adwords portfolio across a range of different sectors. He regulally features in leading search publications such as Econsultancy, Campaign Magazine and Search Engine Land. You can follow him on Twitter or connect with him on Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *