Deliciously Timed Restaurant Ads

Posted on December 1, 2014 in

Use a Script to Toggle a Series of Labeled Ads On or Off

When I published my script to turn holidays ads on or off, it was politely pointed out to me that the same purpose could served using Automated Rules. They were right, and I knew it, but I also planned on using that little script to do something bigger in the future. I was determined to sometime present more robust scripts that could perform functions that could not simply be performed by Automate Rules. This is one of those AdWords Scripts.

This is in-fact a follow up to last week’s blog about running ads at different times of day, and it can be reverse engineered to serve a variety of industries.

 

Purpose of the Script

The AdWords Script below is designed to be used with a restaurant. It assumes that the restaurant in question has specials and/or menus for Breakfast, Lunch, Happy Hour, Dinner, and Late Night.

 

Overlap with Automated Rules

Admittedly, the script below performs functions that Automated Rules can do. It’s just that Automated Rules would create potential timing problems. The problem with Automated Rules is that each one can only look at one entity, or one type of entity. They could look at everything ad with a specified label and pause or activate them. But another Automated Rule would have to be written to pause another set of labeled ads.

It is worthwhile to note the order in which Automated Rules complete. While they run in the order they appear on the Automated Rules screen, some Rules may actually complete before the ones before them based on the size of the task they are completing.

This creates the possibility of overlap or even downtime, and neither lead to the optimum results for a business. The logical solution was to have a script that run both the pausing and enabling at the same time.

 

The Script

If you are using all five labels, you’ll need to add the script five times. The script below would need to scheduled after restaurant closing hours to ensure the breakfast ads are served up fresh and hot in the morning. Each of the other times you add it, between breakfast and lunch, between lunch and happy hour, between happy hour and dinner, and after dinner, you’ll need to change each function to either ad.enable(); or ad.pause();. If you don’t use all of the labels, there are no errors created. The simplicity of it should allow it be as customizable as you need it.

 

// Toggle on Breakfast Ads and Off Ads /w Other Labels
// Author: Kevin Adams
// Date: 2014-12-01

// Add this script after closing hours.
// The script activates ads with the label "Breakfast".
// It pauses "Lunch", "Happy Hour", "Dinner", "Late Night"

// There is no error if you don't have all the labels

function main() {
var adSelector = AdWordsApp
.ads()
.withCondition('LabelNames = "Breakfast"');
var adIterator = adSelector.get();
while (adIterator.hasNext()) {
var ad = adIterator.next();
ad.enable();
lunch();
happyhour();
dinner();
latenight();
}
}

function lunch() {
var adSelector = AdWordsApp
.ads()
.withCondition('LabelNames = "Lunch"');
var adIterator = adSelector.get();
while (adIterator.hasNext()) {
var ad = adIterator.next();
ad.pause();
}
}

function happyhour() {
var adSelector = AdWordsApp
.ads()
.withCondition('LabelNames = "Happy Hour"');
var adIterator = adSelector.get();
while (adIterator.hasNext()) {
var ad = adIterator.next();
ad.pause();
}
}

function dinner() {
var adSelector = AdWordsApp
.ads()
.withCondition('LabelNames = "Dinner"');
var adIterator = adSelector.get();
while (adIterator.hasNext()) {
var ad = adIterator.next();
ad.pause();
}
}

function latenight() {
var adSelector = AdWordsApp
.ads()
.withCondition('LabelNames = "Late Night"');
var adIterator = adSelector.get();
while (adIterator.hasNext()) {
var ad = adIterator.next();
ad.pause();
}
}

 

Conclusion

As with all automation, test, test, test. And, since this script heavily depends on proper timing, don’t forget to add Nathan Byloff’s fix to remove the nagging AdWords time zone issue.

Now, go make some money!

By Kevin Adams

Kevin Adams has been doing PPC since 2004. He has managed many accounts from local service companies to large mortgage companies. His primary proficiencies are Google AdWords, Google Analytics, and Bing Ads. He continually stays up-to-date on the latest tricks, tools and trends provided by the search engines. If there is one thing that Kevin excels at most is making his clients money with Pay-per-Click advertising.