Sign up for weekly recaps of the ever-changing search marketing landscape.
Keep Your Accounts Clutter-Free With This AdWords Script
Columnist Russell Savage shows us how to build an MCC-level AdWords Script that will find and delete your "dud" keywords.
I love trying and testing out new keywords, but I usually forget to clean up after myself. According to Larry Kim’s article about Keyword Hoarding, I’m not alone. What he found was that around 98 percent of the keywords in your account don’t really do much except slow things down. Finding that needle in the haystack is a little easier when the haystack is 98 percent smaller.
Luckily, we have the power of AdWords Scripts to help us clear out the clutter and get rid of the duds. Let’s write an MCC-level AdWords Script to clean up after ourselves as we load and test new keywords.
I encourage you to follow along as we build the script, but for those who can’t wait, feel free to jump to the full script at the end of this post.
Initial Script Design
It turns out that 98 percent of the keywords in your account don’t really do anything. This script is going to attempt to find those useless keywords and clear them out.
We have a few things to keep in mind when building this script.
First, deleting things can be a dangerous thing to do with scripting. We never want to be surprised when a keyword disappears. Let’s make sure we build in a period of time where we are warned about our keywords being deleted beforehand, so we can stop it if we want to. We can apply labels to those keywords to give users in the account a warning that the keyword will soon be deleted.
Second, we need a way to stop the script from deleting keywords that are near and dear to us for some reason. Some things you just aren’t ready to part with, so let’s also add a label that, when used, makes sure the script will ignore it.
Third, we probably don’t want the script to delete keywords that were recently added to the account and don’t have any activity yet. That’s a little tricky, since keywords don’t have a creation date that is easily accessible, but we can use the reporting API to look back in time.
And finally, we want the script to keep us up to date via email about all the changes it is making. Because this is an MCC-level script, if we leverage the executeInParallel function, we can collect the results from each account and generate a summary email of the changes.
So with that in mind, the logic of our script is probably going to look something like this:
- For each account in our MCC…
- Figure out what keywords have existed for enough time to be considered duds.
- Figure out how many of those keywords haven’t done anything for us lately.
- For each keyword that’s a dud…
- If this is a Saved keyword, ignore it.
- If this is the first time we’ve seen it, give it a warning label saying it will be deleted soon.
- If it already has a label, reduce the number of days by 1.
- If the days remaining hits 0, delete the keyword.
- Report on what happened.
This seemingly simple script has turned out to be a little more complicated than we might have thought, so we’d better get started.
For something like this to work, we’ll need a few configuration options. First, we need to know how to classify a dud. I’d stick with anything that has zero conversions, but feel free to pick whatever metric from the Keywords Report works for you.
We’ll also need to know how far back to look at data and how many days we want to give ourselves before the script automatically deletes the keyword. Since this is going to run across a number of accounts, let’s add the ability to specify unique configurations for each one with a default to fall back to. Our initial MCC script should look something like this:
The ability to send configuration information to each executeInParallel script is relatively new and a much welcome addition. Now we just need to write a function to run in each account, and one more to gather the results and send an email with what happened.
Working With Labels
This script is going to leverage labels to help identify keywords that will soon be deleted, as well as ones we want to save. In order to do this, we’ll need to create a few labels, one for each of the days a keyword will be in limbo as specified by the configuration. Here’s a quick helper function that does the job nicely:
We started small, but now let’s work on finding the keywords we are going to be clearing out.
Stepping Back In Time
The performance of a keyword is always measured over a period of time which we have already specified in our configuration file. Since AdWords doesn’t let us filter by creation date in our queries, we need to look at a Keyword report from the oldest date in the range to find all the keywords that have been around since then. This way, we can use those keywords to make sure we don’t delete anything that’s too young and hasn’t had enough time to generate data.
I’ve tried to document the code as much as possible to let you know what is going on. This function will return a mapping of unique identifiers that we can use to filter our other data.
Finding The Duds
Finally, we get to the function where we find all the duds. These keywords that just don’t cut it are the clutter we’ve been looking for. The logic for this is almost identical to that of the function above, except we need to add the criteria for finding the duds. We also want to make sure we are looking across the entire time frame, not just a single day.
Processing The Duds
Now we have the IDs we need to start processing things. This code will run through each keyword in the list, determine what label to apply, if any, and collect all the changes that need to be made into a set of lists. In order to keep the speed up, we are first going to gather all the changes we want to make on the account and then apply those changes all at once.
While we’re here, we should probably write the function that is going to actually apply the changes we just collected. All the function does is apply each of the changes in tight loops so that we can take advantage of any batch processing behind the scenes.
Putting It All Together
Now that we have all the functions we need, let’s put them all together in the function we will be calling from our executeInParallel method in our main function. Since we’ve already written most of this, even though this function does the majority of processing for our script, it is relatively short.
Some of you may have already seen a problem with our script so far. What happens when one of the keywords in limbo gets a conversion and is no longer in the penalty box? Our code so far would ignore those keywords and keep the limbo labels in place. We can fix that pretty quickly with this script to grab the keywords for each label, check if they are in the duds list, and if not, remove the label.
We can add the call to this function in our findKeywordsToDelete function just before we start processing the duds (line 28).
Reporting Our Results
For something like this, we want to generate a nice summary report to send in an email. You’ll notice that at the end of the previous function, there is a call to generateSummaryReport. The last part of this script is the function to gather all the data from the accounts and generate a nice-looking email to send out. The code itself isn’t complicated, but there is a lot of formatting for the HTML part of the email that takes up a lot of space. Check it out.
Well, what started out as a simple keyword deletion script morphed into something pretty complex. You can find a copy of the full Keyword Cleanup script here. Once you schedule it, you should receive an email with the results nicely formatted letting you know where the clutter is. You can log into your account and use the labels report to easily find the keywords that are going to disappear soon. If you have any issues getting this to work, feel free to let me know on Twitter.
Some opinions expressed in this article may be those of a guest author and not necessarily Search Engine Land. Staff authors are listed here.