Scripts and Automation for Negative Keyword Management

Alon TAlon T·

January 13, 2026

For small accounts, manual search term reviews work fine. But as accounts grow, manual processes break down. You need automation to keep up with the volume of search queries and maintain consistent negative keyword management.

If you're still building foundational knowledge, start with building negative keyword lists and mining search terms reports first.

Why Automate?

Scale

A $100K/month account might generate thousands of unique search terms weekly. No one has time to review them all manually.

Consistency

Automated rules run every time. Humans forget, get busy, go on vacation.

Speed

Automation catches wasteful queries faster, reducing wasted spend.

Pattern Detection

Scripts can perform analysis (like n-gram analysis) that would take hours manually.

Google Ads Scripts are JavaScript code that runs within your Google Ads account. They're free, powerful, and Google-supported.

Getting Started with Scripts

  1. Navigate to Tools & Settings → Bulk Actions → Scripts
  2. Click the + button to create a new script
  3. Paste your code
  4. Authorize access
  5. Run manually or schedule

Useful Scripts for Negative Keywords

Search Query Alert Script

Alerts you when a search term exceeds a spend threshold without converting:

function main() {
  var SPEND_THRESHOLD = 50; // Alert if search term spends more than $50
  var EMAIL = "your@email.com";

  var report = AdsApp.report(
    "SELECT Query, Cost, Conversions " +
    "FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
    "WHERE Cost > " + (SPEND_THRESHOLD * 1000000) + " " +
    "AND Conversions = 0 " +
    "DURING LAST_7_DAYS"
  );

  var rows = report.rows();
  var alerts = [];

  while (rows.hasNext()) {
    var row = rows.next();
    alerts.push(row['Query'] + ' - $' + (row['Cost'] / 1000000).toFixed(2));
  }

  if (alerts.length > 0) {
    MailApp.sendEmail(EMAIL,
      "High Spend Zero Conversion Queries",
      "Review these search terms:\n\n" + alerts.join("\n")
    );
  }
}

Schedule this daily to catch wasteful queries quickly.

Automatic Negative Keyword Addition

Automatically add negatives for queries matching certain patterns:

function main() {
  var NEGATIVE_PATTERNS = ['jobs', 'salary', 'careers', 'free download'];
  var campaignIterator = AdsApp.campaigns().get();

  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var report = campaign.getSearchQueries()
      .withCondition("Impressions > 0")
      .forDateRange("LAST_30_DAYS")
      .get();

    while (report.hasNext()) {
      var query = report.next();
      var searchTerm = query.getSearchTerm().toLowerCase();

      for (var i = 0; i < NEGATIVE_PATTERNS.length; i++) {
        if (searchTerm.indexOf(NEGATIVE_PATTERNS[i]) !== -1) {
          campaign.createNegativeKeyword('[' + searchTerm + ']');
          Logger.log('Added negative: ' + searchTerm + ' to ' + campaign.getName());
        }
      }
    }
  }
}

Caution: Always run in preview mode first. Automatic negatives can block good traffic if patterns are too broad.

N-Gram Analysis Script

Identify high-frequency words in your search terms:

function main() {
  var report = AdsApp.report(
    "SELECT Query, Cost, Conversions " +
    "FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
    "DURING LAST_30_DAYS"
  );

  var wordCounts = {};
  var wordCosts = {};
  var rows = report.rows();

  while (rows.hasNext()) {
    var row = rows.next();
    var words = row['Query'].toLowerCase().split(' ');
    var cost = row['Cost'] / 1000000;
    var conversions = row['Conversions'];

    for (var i = 0; i < words.length; i++) {
      var word = words[i];
      if (word.length > 2) { // Skip short words
        wordCounts[word] = (wordCounts[word] || 0) + 1;
        if (conversions == 0) {
          wordCosts[word] = (wordCosts[word] || 0) + cost;
        }
      }
    }
  }

  // Log words with high cost and no conversions
  for (var word in wordCosts) {
    if (wordCosts[word] > 100) { // $100+ spent with no conversions
      Logger.log(word + ': $' + wordCosts[word].toFixed(2) +
                 ' (' + wordCounts[word] + ' occurrences)');
    }
  }
}

This helps identify negative keyword candidates at scale.

Script Best Practices

  1. Always preview first: Run in preview mode to see what would happen
  2. Start conservative: Begin with obvious patterns, expand gradually
  3. Log everything: Include logging so you know what changed
  4. Set appropriate schedules: Daily for alerts, weekly for analysis
  5. Monitor performance: Check that automation isn't blocking good traffic

Third-Party Tools

Several tools offer more sophisticated negative keyword management:

Optmyzr

  • Automated negative keyword suggestions
  • Rule-based negative addition
  • Cross-account management
  • Good for agencies managing multiple accounts

WordStream

  • Negative keyword recommendations
  • Weekly work queue for review
  • Integrates with their broader PPC management

SEMrush / SpyFu

  • Competitor negative keyword intelligence
  • Keyword research including negatives
  • Industry-specific negative lists

Custom Solutions

For large advertisers, custom-built solutions can:

  • Integrate with CRM data
  • Use machine learning for relevance scoring
  • Automate based on business rules

Building Your Automation Stack

Level 1: Basic Alerts (Start Here)

  • Search query spend alerts (script)
  • Weekly search terms email export
  • Calendar reminder for review

Level 2: Semi-Automated

  • Pattern-based negative suggestions (script)
  • N-gram analysis for candidates (script)
  • Human review and approval before adding

Level 3: Fully Automated (Careful!)

  • Automatic negative addition for clear patterns
  • Machine learning relevance scoring
  • Human oversight and exception handling

Most advertisers should stay at Level 2. Full automation risks blocking good traffic if rules are too aggressive.

Automation Pitfalls

Over-Automation

Scripts that add negatives too aggressively can block valuable traffic. Always include safeguards:

  • Spend or impression minimums
  • Human review for borderline cases
  • Easy reversal mechanisms

Set and Forget

Automation still needs oversight. Schedule regular audits of:

  • What negatives were added automatically
  • Whether blocked traffic was truly irrelevant
  • If patterns still make sense

Poor Pattern Matching

Broad patterns can have unintended consequences:

  • Pattern "free" might block "free shipping" queries
  • Pattern "cheap" might block "cheap alternative to competitor" queries
  • Test patterns thoroughly before deploying

Not Adapting

Search behavior changes. Patterns that worked six months ago might not work today. Update your rules periodically.

Measuring Automation Effectiveness

Track these metrics:

Time Saved

  • Hours previously spent on manual review
  • Hours now spent (should be less)

Negatives Added

  • Volume of negatives added automatically
  • False positives (good traffic blocked)

Budget Protected

Quality Metrics

  • Conversion rate trend (should improve)
  • Irrelevant search percentage (should decrease)

Getting Started

If you're new to automation:

  1. Start with alerts: Set up spend threshold alerts first
  2. Run analysis scripts: Use n-gram analysis to find patterns
  3. Build rules gradually: Add automation for obvious patterns only
  4. Review regularly: Check automated additions weekly
  5. Expand carefully: Add more automation as you gain confidence

The goal isn't to remove humans from the process—it's to make human time more efficient by automating the obvious and flagging the uncertain.

Conclusion

Automation is essential for negative keyword management at scale. Google Ads scripts offer a free, powerful starting point. Third-party tools add sophistication for larger accounts.

But automation is a tool, not a replacement for strategy. You still need to:

  • Understand what makes a good negative keyword
  • Set appropriate rules and thresholds
  • Monitor and adjust over time

Start small, validate your automation works correctly, and expand gradually. The combination of smart automation and human oversight produces the best results.

For the foundational knowledge to build effective automation rules, see building negative keyword lists and common negative keyword mistakes.