External Software
— What can you do?  — Everything!
  1. Main
  2. /
  3. Google Ads Scripts
  4.   2 min

Script for stopping ad groups without active keywords

  •   Mikhail Krotov
  •   July 18th, 2021
  •   664

If you have scripts in your account that delete ineffective keywords, or move them between ad groups, then you may have a situation when the ad group is empty.

You can use a script to stop these groups

function main() {
    // select active campaigns
    var campaignSelector = AdsApp
        .campaigns()
        .withCondition('Status = ENABLED'); 
    var campaignIterator = campaignSelector.get();
    while (campaignIterator.hasNext()) {
        var campaign = campaignIterator.next();
        // select active ad groups
        var adGroupSelector = campaign
            .adGroups()
            .withCondition('Status = ENABLED'); 
        var adGroupIterator = adGroupSelector.get();
        while (adGroupIterator.hasNext()) {
            var adGroup = adGroupIterator.next();
            var keywordSelector = adGroup
                .keywords()
                .withCondition('Status = ENABLED');
            var keywordIterator = keywordSelector.get();
            // If there are no active phrases, stop the ad group.
            if (!keywordIterator.hasNext()) { 
                adGroup.pause();
            }
        }
    }
}

Tags
  • account
  • ad groups
  • ads
  • function
  • google ads
  • Keywords
  • script
  • scripts
←Checklist for launching a website in another country’s marketPrevious article
→Script for deleting rejected adsNext article

Related

Use Google Calendar to update ad status based on seasonal or promotional events
If you're running Google Ads campaigns, you know how important it is to keep your ads up-to-date and relevant.
  •   24
  •   2023
Competitor keywords for Google Ads using the Bukvarix API
Modified version of getting competitor keywords for the script from the original article — "Google Ads campaign based on competitor keywords".
  •   727
  •   2021
Script for n-gram analysis in Google Ads
Script for n-gram analysis in Google Ads
  •   935
  •   2021
Google Ads campaign based on competitors’ keywords
How to create a huge campaign based on competitors' keywords without manual labor and collect huge amounts of data? For example, I will take the database of competitors collected according to the method described in my other article — "How to spy on competitors in Google Ads".
  •   782
  •   2021

Popular

How to execute third-party code in Google Ads?
How to use ChatGPT for website accessibility design?
Google Ads Conversion Tracking Tags: Why You Need Them and How to Set Them Up?
Why Are Target CPA Bidding Campaigns Limited by Budget Frequently in Google Ads?
Understanding the Role of Document Features in SEO
How to Add Rule-Based Audiences to Google Ads Campaigns for Effective Targeting?
How to Create Amazing SEO Dashboards to Impress Your Clients
Sitelinks in Yandex.Direct and Google Ads

Tools

  • Phrase processing
  • Phrase Generator/Combinator
  • WP TagGen

Other

  • Word lists
  • World country codes
  • Charity

Categories

  • AI & ML
  • Analytics
  • Contextual advertising
  • Development
  • Google Ads
  • Google Ads Scripts
  • Google Analytics
  • Google Apps Script
  • SEO
  • Yandex.Direct

Archive

  • May 2023
  • April 2023
  • March 2023
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • May 2016
  • January 2016
  • November 2015
  • August 2015
  • July 2015
  • May 2015
  • March 2015
  • February 2015
  • December 2014
  • November 2014
  • September 2014
  • May 2014
  • April 2014

Search

  •   RSS
  •   GitHub
  •   Telegram
  •   Фибулист
  •   Limitation of liability
  •   Privacy policy