Google Ads Script to Receive High CPC Bid Alerts

“You’re spending tons of my money every month, you better be damned proficient at what you do. Failure is not an option!

Sounds familiar?

It’s a quote from a job interview conducted by a VP of Marketing. I was helping him out, recruiting an in-house PPC specialist earlier this year.
Yep. We’ve got a long way to go there. But that’s a different story (next to his style of management, failures are, of course, the only way to make the most out his ad spend).

His words did remind me though, of the importance of not completely f@#king up. Not making the mistakes that make us look like the incompetent idiot in the room.

Yet, that is just what I did. A couple of months ago. I f@#ked up.

Continue reading “Google Ads Script to Receive High CPC Bid Alerts”

Effortlessly Monitor Close Variants with this Google Ads Script

UPDATES:

2018, Oct 6: Added Close Variant search terms to seperate sheet.

2018, Sep 23: Added Cost metrics, and added column for analyzing the difference in Cost per Conversion between the Exact Match keyword and its Close Variants.

2018, Sep 16: Added Click metrics, and “Alerting Percentage Highlighting” to output.

***

Google Ads Exact Match Close Variants

Google’s exact match close variants will expand again: Google is using it’s “AI” to include same meaning variations, and searches with “same intent”.

According to Google, this change will roll out for English keywords through October, with more languages to follow over the next few months.

So, Google is removing yet another level of control for experienced account managers. Exact Match will no longer be…Exact Match. Google provides itself with a lot more runway to match your exact keywords to whatever the heck they deem relevant.

In order to make sure this change does not harm the performance of my clients’ accounts i decided to write script to monitor the impact.

Continue reading “Effortlessly Monitor Close Variants with this Google Ads Script”

A Script to receive Daily Budget Overdelivery Alerts

Here’s a script that will alert you if and when the latest Daily Budget change by Google will cause Google to overdeliver and spend more than your daily budget.
The script will compare the anticipated ad spend based on your campaign daily budget settings with the actual ad spend.
It will check for overdelivery in any of three periods: yesterday, last week and last month.
In case of big differences (overdelivery by Google) it will report an alert, log the alert in the specified Google Sheet and inform you about the alert via email

Here’s what the output will look like:

 

Don’t worry if you have never run an Adwords Script before. It is fairly easy if you follow these steps on how to set up and run Adwords Scripts.

Be sure to create a new empty spreadsheet and add the url to the script. Also add your email adress. (lines 28 and 29)
You can also set the threshold variables to whatever percentage of overdelivery is acceptable to you. (lines 36 to 38)

You can schedule the script to run daily. If you do so, change the ‘firstRun’ to false (line 33).

Here are some instructions on how to install the script if you’ve never done so before.

Subscribe to my mailing list to receive more scripts and updates on how to start learning to write your own Google Ads Scripts.

 

// Copyright 2017, Nils Rooijmans, All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/**
* @overview:
* For each campaign that is NOT labeled 'noBudgetAlert' this script will compare the anticipated ad spend based on daily budget settings with the actual ad spend. 
* In case of big differences (overdelivery by Google) it will report an alert, log the alert in the specified Google Sheet and inform about the alert via email
* 
* For the MCC version please contact Nils Rooijmans [nils@nilsrooijmans.com]
*
* @author:  Nils Rooijmans [nils@nilsrooijmans.com]
* @version: 1.0
*/

// 
var SPREADSHEET_URL = "[REPLACE WITH YOUR SPREADSHEET URL]";  //insert a new blank spreadsheet url, replace everything between and including the square brackets
var EMAIL = "[REPLACE WITH YOUR EMAIL]"; //insert your email, replace everything between and including the square brackets

var CAMPAIGNLABEL = "noBudgetAlert";  //campaign level label for campaigns to ignore

var firstRun = true; // set to false if you schedule the script to run on daily basis, set to true for first run or if you run only once

// Config variables to set the percentage of overdelivery allowed before an alert is sent
var dailySpendAlertThreshold = 0.2; // alert if overdelivery is greater than 20% of daily budget
var weeklySpendAlertThreshold = 0.1; // alert if overdelivery is greater than 10% of 7 times the daily budget (for the 7 days before today)
var fourWeeklySpendAlertThreshold = 0.05; // alert if overdelivery is greater than 5% of 28 times the daily budget (for the 28 days before today)


function main() {  

  var accountAlert = false;
  var campaignAlert_dailyCheck = false;
  var campaignAlert_weeklyCheck = false;
  var campaignAlert_fourWeeklyCheck = false;
  
  var adSpendYesterday = 0;
  var adSpend1to7DaysAgo = 0;
  var adSpend1to28DaysAgo = 0;
  var differenceDailyCheck = 0;
  var differenceWeeklyCheck = 0;
  var differenceFourWeeklyCheck = 0;
  
  var d = Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy");
  var dayOfTheWeek = new Date(d).getDay(); 
  var dayOfTheMonth = new Date(d).getDate();

  //prepare the sheet
  var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
  var sheet = ss.getActiveSheet();
  if (sheet.getRange('A1').isBlank()) {
    sheet.appendRow([
    "Date", 
    "Account Name", 
    "Campaign Name", 
    "Ad Spend Yesterday", 
    "Anticipated Spend", 
    "Difference", 
    "Ad Spend 1 to 7 Days Ago", 
    "Anticipated Spend", 
    "Difference", 
    "Ad Spend 1 to 28 Days Ago", 
    "Anticipated Spend", 
    "Difference"
    ]);
  }
  
  // prepare contents of email
  var html = [];
  html.push(
    "<html>",
    "<body>", 
    "<p>Alerts are logged in sheet: ", SPREADSHEET_URL ,"</p>",
    "<p>----------------------------------------------------</p>",
    "<p>OVERDELIVERY ALERTS FOR:</P>",
    "<P>ACCOUNT - CAMPAIGN</p>",
    "<p>----------------------------------------------------</p>"
  );  
 
     
  // if not already created, create label used to Ignore campaigns
  // this is necessary for the script to run even if no campaign has been labeled
  var labelName;
  var labelExists = false;
  var labelIterator = AdWordsApp.labels().get();
  while (labelIterator.hasNext()) {
    labelName = labelIterator.next().getName();
    if (labelName.localeCompare(CAMPAIGNLABEL) == 0){labelExists = true; break;} else {labelExists = false}
  }
  if (labelExists == false) {
    AdWordsApp.createLabel(CAMPAIGNLABEL);
    Logger.log("labelCreated");
  } else {
    Logger.log("labelExists");
  } 
  
  
  // Let's check the campaigns for overdelivery
  Logger.log("Checking account: "+AdWordsApp.currentAccount().getName());    
  
  var campaignSelector = AdWordsApp.campaigns()
     .withCondition("LabelNames CONTAINS_NONE ['" + CAMPAIGNLABEL + "']")
     .withCondition("Status = ENABLED")
     .forDateRange("YESTERDAY");
  
  var campaignIterator = campaignSelector.get();
  
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    Logger.log("    Checking Campaign: "+campaign.getName());

    var campaignAlert_dailyCheck = false;
    var campaignAlert_weeklyCheck = false;
    var campaignAlert_fourWeeklyCheck = false;
    
    var anticipatedDailyAdSpend = campaign.getBudget().getAmount();
    var anticipatedWeeklyAdSpend = 7 * anticipatedDailyAdSpend;
    var anticipatedFourWeeklyAdSpend = 28 * anticipatedDailyAdSpend;

    // daily check
    //Logger.log("DAILY CHECK");
    adSpendYesterday = campaign.getStatsFor("YESTERDAY").getCost();
    differenceDailyCheck = (adSpendYesterday-anticipatedDailyAdSpend)/anticipatedDailyAdSpend;
    if (differenceDailyCheck > dailySpendAlertThreshold ) {
       campaignAlert_dailyCheck = true;
       Logger.log("DAILY overdelivery spend alert");
    }
    
    // weekly check  
    if (dayOfTheWeek == 1 || firstRun){  // if not the firstRun this check runs only on mondays
      //Logger.log("WEEKLY CHECK");
      adSpend1to7DaysAgo = campaign.getStatsFor(dateBefore(7),dateBefore(1)).getCost();
      differenceWeeklyCheck = (adSpend1to7DaysAgo-anticipatedWeeklyAdSpend)/anticipatedWeeklyAdSpend;
      if (differenceWeeklyCheck > weeklySpendAlertThreshold ) {
         campaignAlert_weeklyCheck = true;
         Logger.log("WEEKLY overdelivery spend alert");
      }
    }

    // 4 weekly check
    if ((dayOfTheWeek == 1 && dayOfTheMonth < 8) || firstRun){ //if not the firstRun this check runs only on the first monday in a month //Logger.log("MONTHLY CHECK"); adSpend1to28DaysAgo = campaign.getStatsFor(dateBefore(28),dateBefore(1)).getCost(); differenceFourWeeklyCheck = (adSpend1to28DaysAgo-anticipatedFourWeeklyAdSpend)/anticipatedFourWeeklyAdSpend; if (differenceFourWeeklyCheck > fourWeeklySpendAlertThreshold) {
         campaignAlert_fourWeeklyCheck = true;
         Logger.log("4-WEEKLY overdelivery spend alert");           
      }   
    }
  
    // add alerts to sheet  
    if (campaignAlert_dailyCheck||campaignAlert_weeklyCheck||campaignAlert_fourWeeklyCheck) {

      accountAlert = true;
        
      sheet.appendRow([
        d, 
        AdWordsApp.currentAccount().getName(), 
        campaign.getName(), 
        adSpendYesterday, 
        anticipatedDailyAdSpend, 
        (differenceDailyCheck*100).toFixed(1)+"%", 
        adSpend1to7DaysAgo, 
        anticipatedWeeklyAdSpend, 
        (differenceWeeklyCheck*100).toFixed(1)+"%", 
        adSpend1to28DaysAgo, anticipatedFourWeeklyAdSpend, 
        (differenceFourWeeklyCheck*100).toFixed(1)+"%"
      ]);  
      
      Logger.log("ALERT ADDED TO SHEET");
      
      if (campaignAlert_dailyCheck) sheet.getRange(sheet.getLastRow(), 6).setFontColor("red");
      if (campaignAlert_weeklyCheck) sheet.getRange(sheet.getLastRow(), 9).setFontColor("red");
      if (campaignAlert_fourWeeklyCheck) sheet.getRange(sheet.getLastRow(), 12).setFontColor("red");
      
      html.push("<p>" + AdWordsApp.currentAccount().getName() + " | " + campaign.getName() + "</p>");             
    }

  if (accountAlert) { // if there is any alert for any of the campaigns , send email
    MailApp.sendEmail(EMAIL, "Overdelivery Alerts", "", {htmlBody: html.join("\n")});
  }

}
  
function dateBefore(days){ 
  var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
  var now = new Date();
  var dateBefore = new Date(now.getTime() - days * MILLIS_PER_DAY);
  var timeZone = AdWordsApp.currentAccount().getTimeZone();
  return Utilities.formatDate(dateBefore, timeZone, 'yyyyMMdd');
}

 

Subscribe to my mailing list to receive more scripts and updates on how to start learning to write your own Google Ads Scripts.

The Best Google Ads Script I Have Ever Used

“What is the best Google Ads Script you have ever used?”

Although I have many favorite scripts in my arsenal and they are all very useful there is one single clear winner for me. This is the script I install the first day when taking over a new account. It is also a great way to finally get started using Google Ads Scripts.

I’m talking about a script that automatically alerts me if any of my landers are broken: the Broken Link Checker script, published by our friends at Google.

Broken links occur because of many reasons, mostly out of your control. Not the least one is IT deploying new versions of the website without proper testing. Recognizable? Uhhh, yeah.

A click on a broken landing page url is not only a waste of your budget, it’s also a missed opportunity to convert. That visitor is never coming back! Next to that, it’s a negative brand experience that even might hurt future CTRs, and thus Quality Scores.

What makes this script my winning script?

My all-time favorite script enables me to do something that is practically impossible without automation. In this sense, it does not improve the efficiency of my work that much, since before using the script I just didn’t do this task at all. (Yes, fair to say I’ve spend buckets of coins on clicks to 404 error pages, especially from sitelinks).
It does however enormously improve the effectivity of my work. How so? Well, it reduces the amount of wasted ad spend in my accounts and reduces missed opportunities for increasing revenue.
More revenue, at fewer costs! That makes me a happy camper.

Next to that, the script is publicly available, open source and free to use.
It is easy to install, easy to configure and easy to run. You don’t need any scripting knowledge whatsoever to get started with this one.
It is well-documented and continuously supported by Google developers. So no worries about running a script that malfunctions. No need to debug or maintain anything yourself.

So…do yourself a favor. Make sure all your links work correctly.
Install the script. Set it, forget it.

PRO TIP: let your fellow SEO colleagues know when you’ve discovered some broken links. They will thank and praise you for it.

And for all you working at an agency, here’s the MCC version of the script.

 

Be sure to check out more great scripts in The Ultimate Google Ads Scripts Library, containing over 400 free Google Ads scripts. 

Join thousands of PPC geeks who already have access: