Google Ads Script: Report campaigns without “impressions”

Google Ads Script: Report campaigns without "impressions" 1

Want to ensure all your campaigns stay active? This script automatically sends you an email if any campaign fails to generate impressions on the previous day.

Lets get started……..

Managing multiple accounts can make it challenging to monitor campaigns daily. Occasionally, campaigns may pause temporarily for various reasons. To help you stay on top of things, we’ve created a script that alerts you via email whenever a campaign hasn’t generated impressions the day before. Simply set your preferred email address, and let the script handle the rest.

Settings

In the config section of the script, you can adjust multiple values ​​as desired.

  • LOG: Change this to ‘true’ to see what exactly happened. Leave on ‘false’ when the script is really running, because that’s faster.
  • EMAIL: Enter the e-mail address where you want to receive the notification. You can enter multiple email addresses by separating them with a comma.
  • EMAIL_INTRO: This is the message at the top of the email. This can be adjusted as desired.
  • EMAIL_SUBJECT: The subject of the email that will be send.
  • DATE_RANGE: Set the daterange for the period you want to check for impressions. TODAY by default.
  • COMPARE: Set to true, if you want to check if the campaigns had impressions before
  • COMPARE_DATERANGE: If compare is set to true, define the daterange you want to compare with.
  • ACCOUNT_LABEL: Use this to select specific accounts.
  • SEND_MAIL: Set to true to always receive an email, even if there are no campaigns without impressions.

MCC level

The following script can be used at MCC level, so that you have an overview of campaigns that are silent in 1 email. In the accountSelector, I filter all accounts that are labeled ‘Active’ in your MCC. If you do not want this, you can delete line 30 from the script.

Scheduling: Run this script 1x per day, preferably at the end of the morning.

// Copyright 2024 
// Free to use or alter for everyone. A mention would be nice ;-)
//
// Report campaigns without "impressions"
// Google Ads Script
// 
// Created: 23-08-2018
// Last update: 02-01-2024 Fixed error, email only send when necessary
//
// ABOUT THE SCRIPT
// With this script you keep track of impressions in campaigns.
// When a campaign didn't receive any impressions yesterday,
// the script will send an email.
//
////////////////////////////////////////////////////////////////////

var config = {
  
    LOG : true,
    
    EMAIL : "your@emailaddress",
    EMAIL_INTRO : "The following campaigns have no impressions today!<br />",
    EMAIL_SUBJECT : "WARNING: Campaigns without impressions",
    
    DATE_RANGE : "TODAY",
    COMPARE : true,
    COMPARE_DATERANGE : "LAST_7_DAYS",
    ACCOUNT_LABEL : "Active",
    
    // Change this to true if you always want an email, 
    // even if there are no campaigns without impressions.
    SEND_MAIL : true
  }
  
////////////////////////////////////////////////////////////////////
  
  function main() {
    
    var emailContent = config.EMAIL_INTRO;
        
    var accountIterator = AdsManagerApp
        .accounts()
        .withCondition("LabelNames CONTAINS '"+config.ACCOUNT_LABEL+"'")
        .get();
    
    while(accountIterator.hasNext()){
      var account = accountIterator.next();
      AdsManagerApp.select(account);
      var emailContentTemp = '';
      var accountHeading = false;
  
      var campaignIterator = AdsApp
          .campaigns()
          .withCondition("campaign.status = ENABLED")
          .withCondition("metrics.impressions = 0")
          .withCondition("campaign.experiment_type = BASE")
          .forDateRange("TODAY")
          .get();
      
      while(campaignIterator.hasNext()){
        var campaign = campaignIterator.next(); 
        
        // Only add campaigns with > 0 impressions previous period
        if(config.COMPARE === true){
          
          // Check for impressions previous period
          if(campaign.getStatsFor(config.COMPARE_DATERANGE).getImpressions() > 0){
  
            if(config.LOG === true){
              Logger.log("Campaign: " + campaign.getName());
            }
            config.SEND_MAIL = true;
            accountHeading = true;
            emailContentTemp += campaign.getName() + "<br />";
            
          }
          
        } // compare with previous period
        else {
          
          if(config.LOG === true){
            Logger.log("Campaign: " + campaign.getName());
          }
        
          accountHeading = true;
          emailContentTemp += campaign.getName() + "<br />";
          
        } 
        
      } // campaignIterator
      
      var shoppingCampaignIterator = AdsApp
        .shoppingCampaigns()
        .withCondition("campaign.status = ENABLED")
        .withCondition("metrics.impressions = 0")
        .withCondition("campaign.experiment_type = BASE")
        .forDateRange("TODAY")
        .get();
      
      while(shoppingCampaignIterator.hasNext()){
        var campaign = shoppingCampaignIterator.next();
        accountHeading = true;
  
        // Only add campaigns with > 0 impressions previous period
        if(config.COMPARE === true){
          
          // Check for impressions previous period
          if(campaign.getStatsFor(config.COMPARE_DATERANGE).getImpressions() > 0){
  
            if(config.LOG === true){
              Logger.log("Campaign: " + campaign.getName());
            }
            config.SEND_MAIL = true;
            accountHeading = true;
            emailContentTemp += campaign.getName() + "<br />";
            
          }
          
        } // compare with previous period
        else {
          
          if(config.LOG === true){
            Logger.log("Campaign: " + campaign.getName());
          }
        
          accountHeading = true;
          emailContentTemp += campaign.getName() + "<br />";
          
        } 
        
      } // shoppingCampaignIterator
      
      var pmaxCampaignIterator = AdsApp
        .performanceMaxCampaigns()
        .withCondition("campaign.status = ENABLED")
        .withCondition("metrics.impressions = 0")
        .withCondition("campaign.experiment_type = BASE")
        .forDateRange("TODAY")
        .get();
      
      while(pmaxCampaignIterator.hasNext()){
        var campaign = pmaxCampaignIterator.next();      
  
        // Only add campaigns with > 0 impressions previous period
        if(config.COMPARE === true){
          
          // Check for impressions previous period
          if(campaign.getStatsFor(config.COMPARE_DATERANGE).getImpressions() > 0){
  
            if(config.LOG === true){
              Logger.log("Campaign: " + campaign.getName());
            }
            config.SEND_MAIL = true;
            accountHeading = true;
            emailContentTemp += campaign.getName() + "<br />";
            
          }
          
        } // compare with previous period
        else {
          
          if(config.LOG === true){
            Logger.log("Campaign: " + campaign.getName());
          }
        
          accountHeading = true;
          emailContentTemp += campaign.getName() + "<br />";
          
        } 
        
      } // pmaxCampaignIterator
      
      var videoCampaignIterator = AdsApp
        .videoCampaigns()
        .withCondition("campaign.status = ENABLED")
        .withCondition("metrics.impressions = 0")
        .withCondition("campaign.experiment_type = BASE")
        .forDateRange("TODAY")
        .get();

      while(videoCampaignIterator.hasNext()){
        var campaign = videoCampaignIterator.next();

        // Only add campaigns with > 0 impressions previous period
        if(config.COMPARE === true){

          // Check for impressions previous period
          if(campaign.getStatsFor(config.COMPARE_DATERANGE).getImpressions() > 0){

            if(config.LOG === true){
              Logger.log("Campaign: " + campaign.getName());
            }
            
            config.SEND_MAIL = true;
            accountHeading = true;
            emailContentTemp += campaign.getName() + "<br />";

          }

        } // compare with previous period
        else {

          if(config.LOG === true){
            Logger.log("Campaign: " + campaign.getName());
          }

          accountHeading = true;
          emailContentTemp += campaign.getName() + "<br />";

        }

      } // videoCampaignIterator
            
      //Add accountname as heading in email
      if(accountHeading === true){
        emailContent += "<br /><b>" + account.getName() + "</b><br />" + emailContentTemp;
        
        if(config.LOG === true){
          Logger.log("Account: " + account.getName());
        }
      }    
      
      if(config.LOG === true){
        Logger.log("----");
      }
      
    } // accountIterator
    
    if(config.SEND_MAIL === true && emailContent != config.EMAIL_INTRO){
        sendEmail(emailContent);
        Logger.log(emailContent);
    }
    
  } // function main
  
////////////////////////////////////////////////////////////////////
  
  function sendEmail(emailContent) {
      MailApp.sendEmail({
        to: config.EMAIL,
        subject: config.EMAIL_SUBJECT,
        htmlBody: emailContent
      });
  } // function sendEmail

The script credit goes to: Tibbe Van Asten

Google Ads On Steroids

Uncover Game-Changing Trends, Proven Strategies, and Expert Tips to Elevate Your Marketing Every Week