How to Schedule Your Google Text Ads using Ads Scripts?

I have a client (another Google Ads manager) asking me how he can run different kinds of Ads during different days of the week. Say for example if he has a client who wants to run a promotion on Saturday and a different promotion on Sunday using the same campaign, adgroup and keyword combination set up.

He said that it might be a waste of Ad and Keyword quality score if he has to split his campaign into two or three if his client have different kinds of promotions. Which I agreed. I believe the easiest way to do this is to create a simple script that will enable ads based on the accounts time and use labels to control what day an ad should be turn on or off.

Let’s say he has 2 regular ads, 2 promotional ads for Saturdays and 2 promotional ads for Sundays. How would things be configured and how would the script behave?

First of all, we need to tell the script which of the ads are regular ads, Saturday promotional ads and Sunday promotional ads. And the easiest way to do this is to use labels. Second thing we need to do is have the script read the labels and determine which one needs to be turned on or off.

I proposed that we indicate in the label when the ads should be turned on and off so that the script can be very versatile and can be used in different situations. Here’s my suggestion:

All labels should start with AdSchedule, second information is when should the ad be on.

  • Ex 1: AdSchedule=0123456 – Ad is on all days, ideally you don’t need this label.
  • Ex 2: AdSchedule=12345 – Ad is On from Mondays to Fridays.
  • Ex 3: AdSchedule=0 – Ad is On on Sundays.
  • Ex 4: AdSchedule=6 – Ad is On on Saturdays.

Where 0 to 6 tells the script that it needs to be ON for certain day. 0 being Sunday, 1 being Monday and so on until 6 being Saturday.

For his purposes, the regular ads will have the label AdSchedule=12345, the Saturday Ad will have the label AdSchedule=6 and the Sunday Ad will have the label AdSchedule=0 (zero)

The idea is you would run this script every 1am or so, so that it will pick up the accounts day and it would go through all the ads that needs to be turned on or off.

 

 

/**
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the LeadCamp PSL License.
 *
 * This source file is subject to the LeadCamp PSL License that is
 * bundled with this package in the license.txt file.
 *
 * @name       Schedule Your Expanded Text Ads to run for a specific day of the week - weekly.
 * @desc       This script allows you to set when your Expanded Text Ads should be ON or OFF.
 * @version    101.01
 * @author     Harris Lim
 * @license    LeadCamp PSL
 * @copyright  (c) 2008-Beyond, LeadCamp, Inc
 * @link       https://searchadspro.com/scheduling-your-expanded-text-ads-google-ads-script/
 */
function main() {  
  schedule();
}
var labelPrefix = "AdSchedule=";
function schedule(){
  var labelSelector = AdsApp.labels()
  .withCondition("Name STARTS_WITH '" + labelPrefix + "'");

  var labelIterator = labelSelector.get();
  while (labelIterator.hasNext()) {
    var label = labelIterator.next();
    var labelName = label.getName();
    var daysOn = isLabelValid(labelName);
    var dayOfWeek = getDayOfWeek();
    var ads = label.ads().get();
    if(ads.totalNumEntities()>0){
      while(ads.hasNext()){
        var ad = ads.next();
        var correctAdType = getRightAdType(ad);
        if(correctAdType!=null){
          if(daysOn!=-1 && daysOn.indexOf(dayOfWeek)!=-1){
            correctAdType.enable();
          }else{
            correctAdType.pause();
          }
        }
      }
    }
  }  
}
function getRightAdType(ad){
  var correctAdType = null;
  if(ad.isType().expandedTextAd()){
    correctAdType = ad.asType().expandedTextAd();
  }  
  return correctAdType;
}
function isLabelValid(labelName){
  var regExpr = /^AdSchedule\=([0-9]\d*)$/;
  var valid = regExpr.exec(labelName);
  Logger.log(labelName + ":" + valid);
  if(valid){
    return valid[1];
  }else{
    return false;
  }
}
function getDayOfWeek(){
  var thedate = new Date(Utilities.formatDate(new Date(),
      AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));
  return thedate.getDay();
}

 

What if you want to schedule the other types of ads?

This is the code you would need to add and replace the old function getRightAdType(ad). Since I didn’t have time to test all the different types of ads, I’ve excluded all of them except for the Expanded Text ad in the original code above.

function getRightAdType(ad){
  var correctAdType = null;
  if(ad.isType().expandedTextAd()){
    correctAdType = ad.asType().expandedTextAd();
  }else if(ad.isType().gmailImageAd()){
    correctAdType = ad.asType().gmailImageAd();
  }else if(ad.isType().gmailMultiProductAd()){
    correctAdType = ad.asType().gmailMultiProductAd();
  }else if(ad.isType().gmailSinglePromotionAd()){
    correctAdType = ad.asType().gmailSinglePromotionAd();
  }else if(ad.isType().html5Ad()){
    correctAdType = ad.asType().html5Ad();
  }else if(ad.isType().imageAd()){
    correctAdType = ad.asType().imageAd();
  }else if(ad.isType().responsiveDisplayAd()){
    correctAdType = ad.asType().responsiveDisplayAd();
  }else if(ad.isType().responsiveSearchAd()){
    correctAdType = ad.asType().responsiveSearchAd();
  }  
  return correctAdType;
}

 

How to Schedule AdGroups for a Specific Day of the Week Using Google Ads Scripts

Just like scheduling text ads, have you ever had a client ask you if you can turn off a set of AdGroups for a particular day of the week? The reason could be anything, as each business is different, there could be a number of reasons why they want to pause a few AdGroups for a particular day of the week.

Reasons could fall into of of these categories:

  1. A team that handles a particular service is off or out of office for a particular day of the week.
  2. A team that handles a particular service works on different aspect of the business.
  3. Or the client finds that for a particular service they provide, it just doesn’t work on that day of the week so they want to turn the AdGroups off.

Regardless of the reason, if you can provide such a service you will be ahead of the pack. Now you can.

This script will allow you to attach a Label to your AdGroup and the script below will pick up the AdGroup and process the AdGroup based on what the label is. Say you want to pause an AdGroup or AdGroups on Saturdays and Sundays, you only need to attach the label AGSchedule=12345 to the AdGroup(s), this means the script will make sure the AdGroup(s) will be online Mondays to Fridays and Offline Saturday and Sundays.

The basic idea of this script is it will allow you to define what days your AdGroup should be turned on or turned off. Here’s a list of possible set ups. Should be very self explanatory.

  1. AGSchedule=06 – Zero and Six, so online only Sundays and Saturdays.
  2. AGSchedule=135 – One, Three and Five, so online only on Mondays, Wednesdays and Fridays.
  3. AGSchedule=61235 – Six, One, Two, Three and Five, so online only on Saturdays, Mondays, Tuesdays, Wednesdays and Fridays.

Possible setup combinations:

Combination 1:

  • AdGroups A, B and C has the label AGSchedule=135
  • AdGroups D, E and F has the label AGSchedule=246

This means AdGGroups A, B and C will run Mondays, Wednesdays and Fridays while AdGroups D, E and F will run Tuesdays, Thursdays and Saturdays. The AdGroups A, B and C could contain similar keywords inside D, E and F or they could be completely different, it’s really up to you.

Combination 2:

  • AdGroups A, B and C has the label AGSchedule=12345
  • AdGroups D, E and F has the label AGSchedule=60

This means AdGroups A, B and C will run on Weekdays and D, E and F will run on Weekends.

Alright, hopefully the examples above gives you an idea how you can use this script to run a more flexible campaign without splitting your campaign up into several campaigns.

/**
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the LeadCamp PSL License.
 *
 * This source file is subject to the LeadCamp PSL License that is
 * bundled with this package in the license.txt file.
 *
 * @name       AdGroup Scheduler
 * @desc       This script allows you to schedule your adgroups to run for a specific day of the week - weekly.
 * @version    101.01
 * @author     Harris Lim
 * @license    LeadCamp PSL
 * @copyright  (c) 2008-Beyond, LeadCamp, Inc
 * @link       https://searchadspro.com/how-to-schedule-adgroups-to-run-on-a-specific-day-of-the-week/
 */
function main() {  
  schedule();
}
var labelPrefix = "AGSchedule=";
function schedule(){
  var labelSelector = AdsApp.labels()
  .withCondition("Name STARTS_WITH '" + labelPrefix + "'");

  var labelIterator = labelSelector.get();
  while (labelIterator.hasNext()) {
    var label = labelIterator.next();
    var labelName = label.getName();
    var daysOn = isLabelValid(labelName);
    var dayOfWeek = getDayOfWeek();
    var adgroups = label.adGroups().get();
    if(adgroups.totalNumEntities()>0){
      while(adgroups.hasNext()){
        var adgroup = adgroups.next();
        if(daysOn!=-1 && daysOn.indexOf(dayOfWeek)!=-1){
          adgroup.enable();
        }else{
          adgroup.pause();
        }
      }
    }
  }  
}
function isLabelValid(labelName){
  var regExpr = /^AGSchedule\=([0-6]\d*)$/;
  var valid = regExpr.exec(labelName);
  Logger.log(labelName + ":" + valid);
  if(valid){
    return valid[1];
  }else{
    return false;
  }
}
function getDayOfWeek(){
  var thedate = new Date(Utilities.formatDate(new Date(),
      AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));
  return thedate.getDay();
}

 

How To Schedule Keywords For a Specific Day of the Week Using Google Ads Scripts

coming soon…

Want to run this in your MCC Account? 

There are a few things you need to consider if you want to run this in your MCC account. Specially if you have accounts the span across different timezone. When your MCC hit 1am, chances are some of your accounts might be ahead a few hours and some accounts would be behind a few hours too. So if you are considering running this on an MCC you need to consider the following:

First thing, you need to consider running this script hourly.

Second thing, you would need to configure the script to execute only at 1am local time, this way, the ads that are suppose to be ON or OFF for that day would correctly turned on or off.

Third thing, if you are running this across multiple accounts, there is a good chance you might have an account with a lot of Ads. Don’t forget each account is given about 30 minutes to execute a script, if you have an account with a lot of Ads that needs processing, your script could time out. Consider adding bulk upload as a feature to your script so that it would process all your ads within 30 minutes.

Fourth thing, the current script only handles Expanded Text Ads. Google came out with a few other ads like Responsive Text Ads and other ads, if you use those ads this script won’t work. (updated: I included a snippet that would handle the most recent type of ads, replace the function and test.)

If you’d like to get a specific script, just let me know by subscribing to my email alerts and replying to my email when I send you a welcome note. Just let me know in the email what type of script you want.