Find AdWords Scripts a bit scary? The truth is any computer savvy person can edit and customize AdWords Scripts. Not a coder? Not a problem.
Most scripts are very detailed and vetted by loads of users, but sometimes you need to tweak them to meet your very specific needs.
If you’re just getting started with adding a script to your account this quick tutorial at the bottom of this post will guide you.
You don’t need to know a lot before we start, but you should checkout the layout of a script by Daniel Gilbert. It always helps me to understand how something works by working through a short example and using it.
- Function: A function contains code between two curly brackets.
- Variable: A variable contains information which can be accessed at a later point in time.
- String: A string is information in the form of text wrapped in quotation marks.
- Parameter: A parameter is information in the form of a variable such as a date range, number, and so on.
- Object: An object is a collection of variables and functions contained between two curly brackets. The object pointed to in the picture, MailApp, is one of the many objects that comes ready-made in AdWords.
- Method: When a function is contained within an object, it is known as a method. From the picture: the sendMail method is one of the functions belonging to the MailApp object.
Still with me? It gets easier. Trust me.
1) Using variables in a script.
You can name a variable anything you want. As long as it makes sense to you it doesn’t really matter. What’s important is that the information (or String) the variable contains is correct and referred to correctly in the object.
For example, the object in the picture MailApp, uses recipient, subject, body as the variable names.
var recipient = “firstname.lastname@example.org”;
var subject = “Scripts are my jam”;
var body = “Information you want to share.”;
MailApp.sendEmail(recipient, subject, body);
You can change (recipient, subject, body) to (email, emailaddress, useremail) and the MailApp object works exactly the same only the variable names have changed. You can even add a variable. Just remember to add the variable name to the object.
var email = “email@example.com”;
var subjectline = “It’s kind of sad scripts are my jam”;
var emailbody = “Information you want to share within the email body.”;
var secondemailbody = “Other information you want to share.”;
MailApp.sendEmail(email, subjectline, emailbody, secondemailbody);
2) Removed Pause and Deleted Ads
If want to remove certain types of ads in a script you simply set the status to ENABLED in your script and paused or deleted campaigns are filtered out.
var campaignStatus = (“Status = ENABLED”);
You want to make sure to add the above line before the line that contains the iterator like keywordIterator or campaignIterator. Then below the iterator line add the campaign status .withCondition(campaignStatus) line.
var keywordsIterator = AdWordsApp.keywords()
The campaign status is now set to filter paused and deleted. You can change the campaign status to ENABLED, PAUSED, or REMOVED.
3) Adding a Metric
Adding a metric is simple. Typically metrics are added below the iterator that has .next() added to the iterator. Here is a list of metrics you can add – AdWords Developer.
var keyword = keywordsIterator.next();
var cost = stats.getCost();
var avgcpc = stats.getAverageCpc().toFixed(2)*100/100; //fixed to 4 decimal places
var avgposition = stats.getAveragePosition();
Below you’ll see an area for Keys, Rows, and Wraps. Be sure to add your variable name to Keys and Rows, then add another “True” in Wraps.
In my next scripts post I’ll discuss how to manipulate the spreadsheet when adding metrics.
4) Conditions and Limits
Below the iterator you can add conditions and limits to your script. Here are few examples:
var keywordsIterator = AdWordsApp.keywords()
//You can change the number from “0” to any number.
.withCondition(campaignStatus).withCondition(“Impressions > 0”)
.withCondition(“Conversions = 0”)
.orderBy (“Clicks DESC”)
5) Date Ranges
You’ll notice the last line above contains the parameter “timerange.” That’s because the time range was set very early on in the script. Normally in the first 10-20 lines. Timerange is then referred to later on in the script in one or more places.
var timerange = ‘LAST_30_DAYS’;
You can select a time ranges from any of the following options: TODAY, YESTERDAY, LAST_7_DAYS, THIS_WEEK_SUN_TODAY, LAST_WEEK, LAST_14_DAYS, LAST_30_DAYS, LAST_BUSINESS_WEEK, LAST_WEEK_SUN_SAT, THIS_MONTH, LAST_MONTH, ALL_TIME.
I hope you found this helpful! This is by no means an exhaustive list of things you can change within AdWords Scripts or uses exact coding terminology, it’s simply meant to be an introduction for those interested in tweaking scripts without having to rely on a programmer. Good luck scripting!