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

Leave a Reply

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