Welcome back to our Intro to AdWords scripts series where we will train you to automate your account management using scripts.
As you’ll have noticed in our earlier posts, we make frequent use of the AdWords scripts documentation, which is vitally important.
In this article we’ll go through an example script making effective use of the documentation, we’ll focus on the campaign selector and we’ll give you an AdWords pro tip.
Example: pulling campaigns
The snippet of code below shows you how to retrieve a campaign from AdWords.
We define a campaignSelector on lines 2-3 using AdWordsApp.campaigns(). There are many options available to the campaignSelector, known as methods.
To make sure we’re looking at just one campaign, we use the withLimit method which specifies the number of campaigns to use in the brackets (known as the argument).
If you don’t include withLimit, the selector will try to pull all the campaigns stopping at a maximum of 50,000.
You can see a list of possible methods below (the full page is available here). Clicking on the name of a method in the documentation will scroll you down to that section, Wikipedia-style.
(click image to enlarge)
An option you’ll find yourself frequently using is the withCondition method where you can refine your search by choosing campaigns with certain names or those which have spent more than a threshold amount, for example.
If you have multiple withCondition methods, the selected campaigns will satisfy all the conditions (think of it as a filter with conditions joined by an AND operator, e.g. cost >10 AND cost < 30).
For example, how would you be able to choose two campaigns that have completely unrelated names? Take a look at the first image below. We included two withCondition lines in our selector.
As a result all the campaigns pulled by the selector will have to satisfy both conditions – not very useful when trying to return data on unrelated campaign groups.
You’ll notice that using multiple conditions can be quite restrictive because you can’t specify campaigns which satisfy one of two conditions. The documentation won’t help you here but we found a solution.
As in the second image, use an array containing a list of all the campaign names you want your selector to pull. This technique overcomes the problem in the first image as campaigns with either name are now retrieved by the selector.
Going through the campaign –> keyword hierarchy is time consuming and using a keyword selector with a campaign name condition such as the one shown in the second image is much more efficient. There will be more on this issue in our upcoming article on AdWords scripting best practices.
Keep an eye out for our next article: Landing pages: putting an end to errors. We’ll be showing you how to scan your destination URLs for error pages and email the results.