Generating Keywords for Search Campaigns
Automatically generate keywords for a search engine marketing campaign using Python to send website visitors to the right landing page.
When structuring a search engine marketing account, a key task is mapping the right keywords to the right ads and making sure they send users to the right landing pages.
In this project, you'll practice how to automatically generate keywords for a search engine marketing campaign using Python to send website visitors to the right landing page.
Imagine working for a digital marketing agency, and the agency is approached by a massive online furniture retailer. They want to test your skills at creating large campaigns for all of their website. You are tasked with creating a prototype set of keywords for search campaigns for their sofas section. The client says that they want you to generate keywords for the following products:
- sofas
- convertible sofas
- love seats
- recliners
- sofa beds
The client is a low-cost retailer, offering many promotions and discounts. You will need to focus on such keywords. You will also need to move away from luxury keywords and topics, as you are targeting price-sensitive customers. Because they are going to be tight on budget, it would be good to focus on a tightly targeted set of keywords and make sure they are all set to exact and phrase match.
Based on the brief above you will first need to generate a list of words, that together with the products given above would make for good keywords. Here are some examples:
- Products: sofas, recliners
- Words: buy, prices
The resulting keywords: 'buy sofas', 'sofas buy', 'buy recliners', 'recliners buy', 'prices sofas', 'sofas prices', 'prices recliners', 'recliners prices'.
As a final result, you want to have a DataFrame that looks like this:
Campaign | Ad Group | Keyword | Criterion Type |
---|---|---|---|
Campaign1 | AdGroup_1 | keyword 1a | Exact |
Campaign1 | AdGroup_1 | keyword 1b | Exact |
Campaign1 | AdGroup_2 | keyword 2a | Exact |
What keywords would help the client sell the listed products through search campaigns?
- Save at least 60 unique keywords as a DataFrame called
keywords_df
and a CSV file calledkeywords.csv
. - Both of these should contain four columns:
Ad Group
: containing the product namesKeyword
: containing the product and keyword combinations, combined in both directions (word + product, and product + word)Campaign
: with the valueSEM_Sofas
in every rowCriterion
Type: with the valueExact
in every row.
import pandas as pd
1. Pair words with products
Create a list of six to ten strings that contain words you think would work well with the given five furniture products: sofas, convertible sofas, love seats, recliners, and sofa beds. Loop through these words in the list and the list containing the furniture products and append each product and keyword combination (word + product, and product + word) into a new keywords list.
# List of words to pair with products
words = ['buy', 'price', 'discount', 'promotion', 'promo', 'shop']
# Print list of words
print(words)
products = ['sofas', 'convertible sofas', 'love seats', 'recliners', 'sofa beds']
keywords_list = []
for product in products:
# Loop through words
for word in words:
# Append combinations
keywords_list.append([product, product + ' ' + word])
keywords_list.append([product, word + ' ' + product])
# Inspect keyword list
print(keywords_list)
2. Convert the list into a DataFrame with descriptive column names
Use your newly created keywords list and convert this into a DataFrame called keywords_df
and the columns "Ad Group
" and "Keyword
".
# Create a DataFrame from list
keywords_df = pd.DataFrame(keywords_list, columns=['Ad Group', 'Keyword'])
print(keywords_df, '\n\n', keywords_df.dtypes)
3. Add a campaign and match type column
Add the Campaign
and Criterion Type
columns with the values "SEM_Sofas
" and "Exact
" in every row respectively, to your newly created keywords_df
DataFrame.
# Add a campaign column
keywords_df['Campaign'] = 'SEM_Sofas'
# Add a criterion type column
keywords_df['Criterion Type'] = 'Exact'
print(keywords_df)
4. Save a DataFrame as a CSV file
Save keywords_df
to a CSV file named 'keywords.csv
' using the pandas to_csv()
method. Exclude the DataFrame index in the saved file by specifying index=False
.
The index parameter here refers to the column name or columnar position of an index in your dataset to be included as an index in the saved data. However, if you do not wish to save an explicit index to your dataset, you can set the index parameter to False
# Save the final keywords to a CSV file
keywords_df.to_csv('keywords.csv', index=False)