How to Generate Google Ads Keywords Using Python

I generated over a million unique Google Ads keywords — using just a few lines of code. If you want to learn how to save time generating keywords and building campaigns: programming is the answer. More specifically, the language Python.

I’m going to show you how I used Python to increase my productivity and lighten my workload. If you are intimidated by the word “programming”, I’m here to change your mind — and show you why you should start using Python to streamline your digital marketing process today!

Use Python to Generate Keywords for Google Ads Campaigns

Let’s take a look at how to generate keywords for search campaigns. Python has many different applications for e-commerce (including data analysis), but for now we’re only going to cover two examples of how to generate Google Ads keywords: one beginner and one advanced.

Generating Unlimited Exact Match and Broad Match Keyword Combinations for Google Ads 

I often need to generate lists of keyword combinations for my clients. You probably have to do something similar for your account. This task that usually takes hours, can be reduced to minutes using a simple Python process called a “for loop”.

In coding, a “for loop” is a way to program tasks which involve iterations. A great use case would be to generate keywords by iterating through different word combinations. 

For example, suppose you were to build a search campaign to sell shoes. On a spreadsheet, you would make the first column a descriptor, for this example we will use colors such as “red”, “green”, and “blue”.  Next, you would have a column with different types of footwear: “shoes”, “sneakers”, “sandals”. The third column is a specific term, in this case, shoe width: “wide”, “regular”, etc.

After setting up the spreadsheet, input that data into the program and it will generate exact and broad match variants of the keywords — like “red shoes narrow”, “green sandals wide” and so on.

Next, you’ll have to add them to an ad group. After that, you can easily upload it to the Google Ads editor. You can manipulate spreadsheets, CSVs, and Excel files in Python, so it is not difficult to integrate with tools that you are already using.

In the screenshot, you can see an example of using multiple for-loops to iterate through each list of terms to generate keywords from the example. While this is a simple example, you can use advanced features to import files as I have described above.

Creating Zip Code Keywords for a Local Campaign

If you’re running a local campaign, it is a good idea to include zip codes and cities in your keywords. If you have a lot of locations, however, it can be difficult to generate a comprehensive list of all the zip codes and cities within range of each store. Python makes this task a breeze. 

For a client with this particular ask, I found a census data set for every county and then put it into a machine learning model called K-Nearest Neighbors (KNN) which is a clustering algorithm.

To start, you define your initial set of points, then the algorithm does a calculation to find out which points (in this case – cities) are closest. Then you just have to populate the keywords. By using this process, I was able to generate over a million keywords for my client — using just a few lines of code. It would’ve taken much longer to find all of those cities and manually enter all of the stores (over 100).

Don’t Be Intimidated by Python 

If you think, “I can’t possibly learn that on my own!”, you would be surprised by the sheer number of resources that exist for learning programming languages these days. If you’re looking for structured classes, Code Academy is a great place to start. If you get stuck along the way, I recommend Stack Overflow — a message board for programming related questions.

On top of that, Python is one of the most accessible languages to learn. If I may get a little technical for a moment, a lot of programming languages have groups of functions called libraries. Libraries store long sets of code, so you don’t have to see all the complicated stuff. Instead, you can simply write a few lines of code. Python is an open source language, so anyone can contribute to it, which means there are a lot of libraries available! 

We can all agree that one of the most important resources is time. While it does take a little bit of time to learn Python, the payoff is huge — and will free up your schedule so you can dedicate energy to more important tasks. If you can commit even a little bit of time to learn the language, you won’t regret it. 

Need help generating keywords using Python? Reach out to speak to an Omnitail analyst today.

Did you find this article helpful?

Get more delivered to your inbox just like it!