MINDSWAN
  • Home
  • Podcast
  • Blog
  • Contact

​Pause AdGroups With No Active ADs

/*********************************************
* Pause AdGroups With No Active ADs
* 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 ad copies that are enabled
   var adIter = ag.ads()
     .withCondition("Status = ENABLED")
     .get();
    
   //If .hasNext() is true, there is at least 1 ad copy in the AdGroup
   var hasAd = adIter.hasNext();
   if(!hasAd) {
     toPause.push(ag);
   }
 }
  
 // Now we process them all at once to take advantage of batch processing
 for(var i in toPause) {
   toPause[i].pause();
 }

}


Monthly Budget Cut off

function main() {
  //update the value of monthlyBudget based on your requirement
  var monthlyBudget = ####;
  var totalCost = 0;
  var campaignsList = [];
 
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name IN ["INSERT_CAMPAIGN_NAME_HERE", "INSERT_CAMPAIGN_NAME_HERE", "INSERT_CAMPAIGN_NAME_HERE", "INSERT_CAMPAIGN_NAME_HERE"]') //add 1 or more campaigns that are needed to be included the check
      .get();
 
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
     //save in campaignsList the list of campaigns object.
    campaignsList.push(campaign);
    //use THIS_MONTH to get data for all days in the current month
    var stats = campaign.getStatsFor('THIS_MONTH');
    var campaignCost = stats.getCost();
    totalCost += campaignCost;
  }
 
  //if totalCost of combined campaigns is equal to defined monthlyBudget, pause the listed campaigns
  if (totalCost > monthlyBudget){
    for (var i = 0; i < campaignsList.length; i++) {
      var campaign = campaignsList[i];
      Logger.log(campaign.getName())
      campaign.pause();
    }
  }
}

Recent Blog Post

What Client Need From a Relationshop
The Cookie-less world of digital marketing - Be part of the solution
Breakfast at The Ivy
5 Money Saving AdWords Scripts
5 Tips on Account Execs Properly
5 Important Factors for an Effective Paid Search Account
The 5 AdWords Script to Start You On Managing a New Account
The Jargon Busting Way To Comment On Your Paid Search Performance

​

Subscribe To Get  PPC Automation Tips, Podcast release and other updates!

    [object Object]
Subscribe Now

Follow Anu

Picture

​





​@themarketinganu
LinkedIn 

 HOME | #PPCCHAT ROUNDUP | BLOG | CONTACT US

By using this site you consent to the use of cookies. Cookies can be managed in your browser or device setting
Copyright © 2021 MINDSWAN ​
  • Home
  • Podcast
  • Blog
  • Contact