Stop Empty AdGroups without Ads or Keywords

Easy Script for Stop AdGroups. Find empty active adgroups in active campaigns and stop them.

/* 
 * Stop Empty AdGroups without Ads or Keywords
 * Source: https://www.en.advertisercommunity.com/t5/Basics-for-New-Advertisers/How-to-Pause-Empty-Ad-Groups/td-p/452772        
 */

function main() {
    var adGroupIterator = AdWordsApp.adGroups()
        .withCondition("CampaignStatus = 'ENABLED'")
        .withCondition("Status = 'ENABLED'")
        .get();

    while (adGroupIterator.hasNext()) {
        var thisGroup = adGroupIterator.next();
        var numAds = thisGroup.ads()
            .withCondition("Status = 'ENABLED'")
            .get().totalNumEntities();
            
        var numKeywords = thisGroup.keywords()
            .withCondition("Status = 'ENABLED'")
            .get().totalNumEntities();
            
        if (numAds == 0 || numKeywords == 0) {
            thisGroup.pause();
        }
    }
}

One thought on “Stop Empty AdGroups without Ads or Keywords

Leave a Reply

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