1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /********************************************** Pause AdGroups With No Active Keywords* Version 1.1* Changelog v1.1* - Updated for speed and added comments * Created By: Russ Savage* FreeAdWordsScripts.com**********************************************/function main() { // Let's start by getting all of the active AdGroups var agIter = AdWordsApp.adGroups() .withCondition('CampaignStatus = ENABLED') .withCondition('Status = ENABLED') .get(); // 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 = agIter.next(); //get all the keywords that are enabled var kwIter = ag.keywords() .withCondition("Status = ENABLED") .get(); //If .hasNext() is true, there is at least 1 kw in the AdGroup var hasKw = kwIter.hasNext(); if(!hasKw) { toPause.push(ag); } } // Now we process them all at once to take advantage of batch processing for(var i in toPause) { toPause[i].pause(); }} |
function main() {
// Let's start by getting all of the active AdGroups
var agIter = AdWordsApp.adGroups()
.withCondition('CampaignStatus = ENABLED')
.withCondition('Status = ENABLED')
.get();
// It is faster to store them and process them all at once later
var adGroupsWithNoActiveAds = [];
// Then we will go through each one
while(agIter.hasNext()) {
var ag = agIter.next();
//get all the ads that are enabled
var adIter = ag.ads()
.withCondition("Status = ENABLED")
.get();
//If .hasNext() is true, there is at least 1 ad in the AdGroup
var hasEnabledAd = adIter.hasNext();
if(!hasEnabledAd) {
adGroupsWithNoActiveAds.push(ag);
}
}
// Now we will get all the ad groups and concatenate them into one message body
var body = '';
for(var i in adGroupsWithNoActiveAds) {
body = body + adGroupsWithNoActiveAds[i].getId() +' ' + adGroupsWithNoActiveAds[i].getName() +'\n';
}
if (adGroupsWithNoActiveAds.length > 0) {
MailApp.sendEmail('INSERT_EMAIL_ADDRESS_HERE',
'List of ad group ids with no active ads',
body);
Logger.log("Sending complete!");
}
}