How to Use Google Ads Scripts to Turn Campaigns On and Off Based on Weather Conditions

Running ads that adapt to the weather isn’t just a clever trick—it’s a proven way to boost relevance, clicks, and ROI. Imagine switching on a campaign for umbrellas the moment rain is forecast, or pausing ice-cream ads when the temperature drops below 10°C. With Google Ads scripts, you can do exactly that.

In this post, we’ll show you how advertisers can connect live weather data to Google Ads so campaigns automatically turn on or off depending on the conditions.

Why Weather Matters in Digital Advertising

Weather has a direct influence on consumer behaviour:

  • Rain increases demand for umbrellas, food delivery, and rideshares.
  • Heatwaves boost sales of air conditioners, cold drinks, and sunscreen.
  • Windy days drive interest in windproof jackets or even certain sports gear.
  • Cold snaps lift demand for heating services, winter fashion, and comfort food.

By syncing campaigns with weather conditions, you only spend when customers are most receptive—maximising ad efficiency.

What Are Google Ads Scripts?

Google Ads scripts are snippets of JavaScript that run inside your Google Ads account. They let you automate tasks like:

  • Adjusting bids
  • Generating custom reports
  • Pausing or enabling campaigns

Most importantly for us, they can fetch external data (like weather) via APIs and use that data to make campaign changes.

Step 1: Label Your Weather-Sensitive Campaigns

The easiest way to target specific campaigns is by giving them a label. For example:

  • WT:Rain for campaigns that should only run when rain is forecast.
  • WT:Hot for campaigns you want active when the temperature passes a set threshold.

Labels make it simple for a script to know which campaigns to control.

Step 2: Connect to a Weather API

You’ll need live weather data. Two popular providers are:

  • OpenWeatherMap – Offers hourly forecasts, temperature, precipitation probability (pop), and more.
  • Tomorrow.io – Provides detailed data including wind speed, UV index, and precipitation intensity.

Both allow API calls directly from Google Ads scripts using UrlFetchApp.

Step 3: Full Working Google Ads Script (OpenWeatherMap)

What it does:

  • Looks for campaign labels (e.g., WT:Rain, WT:Hot).
  • Fetches current + next-hour forecast from OpenWeatherMap (One Call 3.0).
  • Turns ON campaigns if the condition is met; otherwise pauses them.
  • Designed to run hourly.
/**
 * Weather-triggered campaign toggler for Google Ads Scripts.
 * Data source: OpenWeatherMap One Call (Current + Hourly).
 *
 * Setup:
 * 1) Create labels on campaigns you want controlled, e.g. WT:Rain, WT:Hot
 * 2) Add your OpenWeatherMap API key and coordinates below
 * 3) Schedule hourly in Google Ads
 */

const CONFIG = {
  OPENWEATHER_API_KEY: 'YOUR_OWM_API_KEY',
  // Coordinates for the target location (Melbourne CBD example):
  LAT: -37.8136,
  LON: 144.9631,
  UNITS: 'metric', // 'metric' (°C), 'imperial' (°F)
  RAIN_PROB_THRESHOLD: 0.6, // 60% chance
  HOT_TEMP_C_THRESHOLD: 30,  // 30°C
  // Labels to look for on campaigns:
  LABELS: {
    RAIN: 'WT:Rain',
    HOT: 'WT:Hot'
  }
};

function main() {
  const weather = fetchWeather();
  const now = weather.current;
  const nextHour = weather.hourly && weather.hourly.length ? weather.hourly[0] : null;

  // Compute simple triggers
  // Use next-hour precipitation probability if available; fallback to 0.
  const pop = nextHour ? (nextHour.pop || 0) : 0; // probability of precip (0..1)
  const tempC = (now && typeof now.temp === 'number') ? now.temp : null;

  // RAIN logic
  toggleByLabel(
    CONFIG.LABELS.RAIN,
    (pop >= CONFIG.RAIN_PROB_THRESHOLD),
    'Rain (pop=' + Math.round(pop * 100) + '%)'
  );

  // HOT logic
  toggleByLabel(
    CONFIG.LABELS.HOT,
    (tempC !== null && tempC >= CONFIG.HOT_TEMP_C_THRESHOLD),
    'Hot (temp=' + tempC + '°C)'
  );
}

/**
 * Enable campaigns with label if condition true; otherwise pause them.
 */
function toggleByLabel(labelName, shouldEnable, reason) {
  const it = AdsApp.campaigns()
    .withCondition('LabelNames CONTAINS_ANY ["' + labelName + '"]')
    .withCondition("Status != REMOVED")
    .get();

  const actions = { enabled: 0, paused: 0 };

  while (it.hasNext()) {
    const c = it.next();
    const name = c.getName();

    if (shouldEnable) {
      if (!c.isEnabled()) {
        c.enable();
        Logger.log('ENABLED: ' + name + ' | ' + reason);
        actions.enabled++;
      }
    } else {
      if (!c.isPaused()) {
        c.pause();
        Logger.log('PAUSED: ' + name + ' | ' + reason);
        actions.paused++;
      }
    }
  }
  Logger.log('Label "' + labelName + '": enabled ' + actions.enabled + ', paused ' + actions.paused);
}

/**
 * Calls OpenWeatherMap One Call API (current + hourly).
 * Returns JSON with fields: current, hourly, etc.
 */
function fetchWeather() {
  const url = [
    'https://api.openweathermap.org/data/3.0/onecall',
    '?lat=', encodeURIComponent(CONFIG.LAT),
    '&lon=', encodeURIComponent(CONFIG.LON),
    '&units=', encodeURIComponent(CONFIG.UNITS),
    '&exclude=minutely,daily,alerts',
    '&appid=', encodeURIComponent(CONFIG.OPENWEATHER_API_KEY)
  ].join('');

  const res = UrlFetchApp.fetch(url, { 'muteHttpExceptions': true, 'method': 'get' });
  const code = res.getResponseCode();
  if (code < 200 || code >= 300) {
    throw new Error('OpenWeather error HTTP ' + code + ': ' + res.getContentText());
  }
  return JSON.parse(res.getContentText());
}

How to customise quickly:

  • Change LAT/LON to your target city (or duplicate the logic for multiple cities + labels).
  • Adjust RAIN_PROB_THRESHOLD and HOT_TEMP_C_THRESHOLD for your brand.
  • Swap UNITS to “imperial” if you prefer °F.
  • Replace the fetchWeather() call with a Tomorrow.io version if you need wind/UV/snow depth triggers.

Step 4: Schedule the Script

In Google Ads:

  1. Tools & Settings → Bulk Actions → Scripts
  2. New script → paste → Authorize
  3. Preview to confirm logs
  4. Schedule: Hourly

Hourly scheduling keeps you responsive to changing conditions.

Example Use Cases

  • E-commerce: Activate “Rainwear” ads when precipitation probability exceeds 60%.
  • Hospitality: Push “Cold Drinks” or “Beer Garden” campaigns only on days above 28°C.
  • Home Services: Trigger “Air Conditioner Repair” ads when the forecast spikes above 35°C.
  • Retail: Pause “Winter Clearance” ads once warm weather sets in.

Benefits of Weather-Triggered Ads with Google Ads Scripts

  • Relevance: Ads match the customer’s environment in real time.
  • Efficiency: Avoid wasted spend when products aren’t in demand.
  • Automation: No manual campaign toggling.
  • Scalability: Run weather triggers across multiple cities or product lines.

Common Gotchas (and Fixes)

  • API limits: Free tiers cap requests. Use a paid tier for reliability.
  • Time zones: If you serve multiple cities, use per-city coordinates and labels.
  • Flip-flopping: Weather can change quickly. Add hysteresis (e.g., require two consecutive “true” checks before enabling and two “false” checks before pausing). You can store the last state in Script Properties.
  • Permissions: Ensure your user has rights to edit campaigns and labels.

Prefer No-Code? Use WeatherTrigger.

DIY scripts are powerful, but they require setup, monitoring, and maintenance. WeatherTrigger gives you a plug-and-play way to run weather-based ad automation across Google Ads and Meta—no code, no cron-style scheduling headaches.

Ready to try it the easy way?

Join the WeatherTrigger waiting list and we’ll notify you as soon as we open access.

Related Reading