How much does a polar bear weigh?

Enough to break the ice!

Hi, I’m Connor Regan, an Account Manager here at Hanapin Marketing. Today we’ll be going over scripts, what they are, how they work and how we might best use them with PPC advertising. Neat!

What Are Scripts & How Do They Work?

Starting with the technical definition given by Google, “Google Ads scripts provide a way to programmatically control your Google Ads data using simple JavaScript in a browser-based IDE. You can use scripts to automate common procedures or interact with external data—for one to many Google Ads accounts.”

That definition says a lot without actually telling us much, meaning it’s incredibly vague and doesn’t really provide any insight into what scripts are and what they can do for us. Allow me to enlighten you a bit.

Scripts, while relatively simple, aren’t something which you can master in a couple of hours if you don’t have a serious coding background. Don’t let that deter you, however, as many scripts which you might use with PPC already exist out there on the internet, they’ll just take a bit of editing to make it work for your specific accounts.

Breaking scripts down, we start with the function, as seen in the screenshot below.

PPC Script Example

Most every script starts with a “function ()” followed by {…}. Everything within the squiggly brackets is the code which will be executed. While this may be the easiest part, no code will work without this.

Variables expressed as “var” in code, are containers which store data values. Each variable must correspond to specific objects and entities within the account you’re using the script for.

Objects, of which there are 4 basic types, tell the scripts where to look for the data you want. The 4 types of objects are:

• AdWordsApp (AdsApp)
• SpreadsheetApp
• MccApp (for those who use MCC accounts).
• UrlFetchApp

For example, you would use the AdWordsApp object to tell the script to look in Google Ads for the data you would want it to pull.

Entities live within the object, which sounds weird, I know. Hopefully, this example clears it up, “AdWordsApp.Keywords”. Remember that AdWordsApp is an object, meaning “Keywords” is the entity here within the object. There are many different entities but, for the most part, they’ll follow the object so it’s easiest to find the entity by identifying your object first.

In our screenshotted example, you can see that one of our snippets of code is “var campaigns = AdsApp.campaigns()”. In this example, AdsApp is our object and campaigns() is our entity within the object. We’re telling the script to look up our campaign data within Google Ads.

Next, Selectors are filters for the data that the script is going to pull from. Some selector examples are:

• withCondition()
• withIds()
• forDateRange()
• orderBy()
• withLimit()

Again, looking to our example, you’ll see “.withCondition(“Status = ENABLED”), “.withCondition(“Cost > 0”) and “.forDateRange(“TODAY”)”. With this snippet, we’re telling our script to find and pull data for those campaigns which are enabled and have spent more than $0 dollars today. Starting to make a bit more sense now, right? It’s important to know that we can use multiple selectors to continually refine the data we’re looking for.

Iterators essentially keep the script continually firing. For example, by using iterators such as hasNext() and next(), we set a loop that will continue to fire as long as our script returns valid data.

Lastly, Methods are the commands in the code, such as “Get”, “Set” and “Add”. In our script example, we have the snippet “var campaignIterator = campaigns.get();”. This is going to return the data of the campaigns which we have used Selectors to filter for.

That just about covers all the most important aspects of a script. My hope is that this guide can help you read and understand any scripts you come across in the wild, as being able to do even just that will help you immensely.

As I mentioned earlier, many scripts exist already and are out there waiting for you to copy/paste them into your account. If you can read the script and make any necessary edits/adjustments to make the script fit your account, you’ve likely saved yourself hours by avoiding writing the whole script yourself!

Ways to Use in PPC Advertising

Going back to our example, let me explain the purpose of this script (which I found on the internet and adjusted to fit the needs of our account) and how it helps us here at Hanapin. This script is meant to pause our campaigns once they have spent more than 20% of their daily budget (we implemented this because Google’s “spend twice your daily budget” policy was really interfering with our budgeting and pacing). More than anything, this script was a safety blanket, allowing for us to rest easy knowing that we weren’t going to blow through our budget during the first half of the month.

You might now be thinking, “cool, you have a nice, simple script which can pause campaigns once they’ve spent X amount of dollars. Don’t you then have to spend the next day looking through the account re-enabling those campaigns? How does this actually save time?”

A great question! Long story short, we created a second script which would re-enable those campaigns which were paused by the over-delivery script. In our screenshot below, we’re asking our script to find any campaigns with a specific label (which we had our over-delivery script give every campaign it paused) and then enable those campaigns. These scripts run in tandem, every day, saving us time and energy which we can then invest in other areas of the account. It’s a win-win-win.

Another PPC Script Example

There is a near limitless amount of ways to use scripts within your Ads accounts and I would encourage you to browse the internet as there are so many scripts out there already just waiting for us to give them a good home. For example, my peer, Jacob Fairclough, has some scripts to help with your bidding endeavors, among other routine optimizations.

Conclusion

All in all, scripts can do almost anything in the account that we ourselves might do, except they automate the process and save us time and energy. Really, life is just a combination of time and energy. Energy, we can manage…time, we cannot. Do yourself a favor and implement some scripts to give yourself some of sweet, sweet time back in your day.

Lastly, I would check out this blog by Christi Olson of Microsoft, who goes more in-depth with how scripts can work with Microsoft Ads!

Until next time!