Category Archives: Google Ads Scripts

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();
        }
    }
}

Remove Unused Labels in Shared Library

/* 
 * Remove Unused Labels in Shared Library
 * 
 * Source: https://groups.google.com/d/msg/adwords-scripts/pD8MXs1FZFM/uzrBr0iQCQAJ
 */

function main() {
    var labelIterator = AdWordsApp.labels()
        .withCondition("CampaignsCount = '0'")
        .withCondition("AdGroupsCount = '0'")
        .withCondition("KeywordsCount = '0'")
        .withCondition("AdsCount = '0'")
        .get();
    while (labelIterator.hasNext()) {
        var label = labelIterator.next();
        var labelName = label.getName();
        label.remove();
        Logger.log("Label " + labelName + " removed");
    }
}