Wednesday, November 21, 2012

Pause AdGroups With No Active Keywords

This is a quick script to pause all the AdGroups with no active keywords in them. Not sure if this is super useful, but for large accounts, it might help identify AdGroups you can get rid of.


* Pause AdGroups With No Active Keywords
* Version 1.1
* Changelog v1.1
*   - Updated for speed and added comments 
* Created By: Russ Savage
function main() {
  // Let's start by getting all of the active AdGroups
  var agIter = AdWordsApp.adGroups()
    .withCondition('CampaignStatus = ENABLED')
    .withCondition('Status = ENABLED')
  // It is faster to store them and process them all at once later
  var toPause = [];
  // Then we will go through each one
  while(agIter.hasNext()) {
    var ag =;
    //get all the keywords that are enabled
    var kwIter = ag.keywords()
      .withCondition("Status = ENABLED")
    //If .hasNext() is true, there is at least 1 kw in the AdGroup
    var hasKw = kwIter.hasNext(); 
    if(!hasKw) {
  // Now we process them all at once to take advantage of batch processing
  for(var i in toPause) {


  1. This rule seems to time out every time? Any idea how I would manipulate this script to only search within ACTIVE campaigns? I believe it is timing out because I have a lot of deleted and paused campaigns.


    1. I'm assuming you have to add 'isEnabled()' in there somewhere.

  2. Yeah it's easy to update. Instead of the line:

    var ag_iter = AdWordsApp.adGroups().get();

    Just use the following:

    var ag_iter = AdWordsApp.adGroups().withCondition("Status = ENABLED").get();

    Let me know if that works for you.


  3. Hi! Is there a way to make sure that you keep DSA campaigns be excluded from this? I'm running into an issue where this script pauses all ad groups in my DSA campaign.