Automating Google Ads Negative Keywords with ChatGPT For Less Than $1
Is updating negative keywords by hand giving you a headache? Embrace Google Ads Scripts automation with ChatGPT and take your hassle to zero. If you spend hours every week looking at Google Ads for clients or your company, automation can save you time, energy and unnecessary stress.
With the power of revolutionary technology like OpenAI’s ChatGPT and other large language models, programming knowledge is optional. Automation has never been more accessible and it can cost you next to nothing.
Power up your Google Ads optimisation with ease.
Whether you’re a beginner or an expert this article will provide you with the knowledge and tools to supercharge your Negative Keyword game and keep ahead of the curve.
Mandatory disclaimer: how you use this power is up to you. We’re not responsible for any outcomes (positive or negative) from applying what you learn below. All information is educational in nature and may become outdated as the tools mentioned evolve and change. You should always review automated changes before approving, regardless of the tool used.
Who Am I?
Before we get started, let me introduce myself. I’m Isaac, a digital marketing specialist. I work for Fisher Digital, a leading provider of SEO and PPC services in Perth. Learn more about what we’re doing on the Fisher Digital website.
Being a part of the Search Team requires keeping a close eye on industry news and trends. Between ChatGPT, generative AI and the move of search engines to conversational AI, it’s difficult to understate the impact of AI on the digital marketing landscape. I would be foolish not to pay attention to such a groundbreaking technology.
The Importance of Negative Keywords – Worth the Hassle?
Exploring search terms and manually identifying opportunities for terms to exclude is not always popular with Google Ads specialists. It can be draining, time-consuming and repetitive. Here’s why it’s extremely important.
The greatest predictor you have of future searches is the information that you already have.
Negative keywords allow you to remove terms with a 0% (or close to 0%) chance of converting. If you move 2% of your total impressions from zero-value search terms to high-value ones each week, your campaigns stand to reap exponential benefits over time.
Let’s get started with Google Ads Scripts.
What are Google Ads Scripts?
From Google:
“Google Ads scripts provide a way to programmatically control your Google Ads data using simple JavaScript in a browser-based IDE. You can use scripts to automate common procedures or interact with external data—for one to many Google Ads accounts.
Only entry-level familiarity with JavaScript is needed—the IDE helps with syntax highlighting, auto-complete, and previewing. All you need is a Google Ads account to start writing your first scripts.”
Google Ads Scripts are one of the most underutilised tools for optimising Ads Accounts. They had a bump in popularity in the mid-2010s but adoption is low due to their technical barrier to entry.
Several old-school Ad Scripts examples can be found (here) and (here). Some example use cases include:
- Checking for dead links
- Generating reports
- Automating bid adjustments
- Pausing ads / campaigns / keywords if a certain condition is met
- Manage locations more efficiently
These are pretty handy and I recommend exploring what’s possible.
But with the power of ChatGPT, we have access to a new world of possibilities. Not only can we create scripts with ease, but we can use them to interpret, optimise and generate language in exciting ways that were not accessible just a year ago.
What is ChatGPT?
If you have an internet connection and work in the digital space, hearing about ChatGPT is almost inevitable. Powered by OpenAI’s advanced language model, ChatGPT is an AI tool that interprets natural, human text and responds in kind. It’s knowledgeable, intuitive and responsive to instructions.
ChatGPT has an excellent grasp of language and that is what we’re going to be taking advantage of today. Luckily for us, both search terms and code fall under this category.
Getting Started with Google Ads Automation – Prerequisites
To get started with AI-powered Google Ads automation, there are a few things you will need. Don’t worry – getting set up is pretty easy.
Access to a Google Ads Account
You should have an active Google Ads account to implement the automation techniques discussed in this guide. You’ll get the most out of this if you have an Ad Account to work with, preferably with at least 30 days of history.
An OpenAI Account
ChatGPT Plus is a bonus but not strictly needed for anything today.
To use ChatGPT, you’ll need to create a free account on the OpenAI platform. Head over to OpenAI’s website and sign up for an account.
Once your account has been created, log in. Then navigate to the API Key page.
You will need to create a new Secret Key. Give your Secret Key a name and then save the code somewhere on your PC where you won’t lose it. The clue’s in the name – you’ll want to keep this secret. We will go over how to use this key later on.
You’ll also need to add a payment method to your account. Don’t worry about spending too much. I recommend setting a hard usage limit of $1. In the process of writing this article, I spent less than 10 cents – this will be plenty to get started with.
(Optional) Some knowledge of programming concepts
While not mandatory, having a basic understanding of programming concepts may make this smoother for you. We’ll explain the code snippets and concepts in a beginner-friendly manner, so don’t worry if you’re new to programming. Additionally, ChatGPT is more than willing to explain the steps it takes if you ask it to.
Using ChatGPT – General Prompting Tips
Be Specific, Descriptive & Detailed
Provide detailed prompts to ChatGPT to ensure it understands your requirements. The more information you provide, the better the generated response will be. The most important thing is getting practice.
As OpenAI puts it on their blog:
“Be specific, descriptive and as detailed as possible about the desired context, outcome, length, format, style, etc”
There are many different approaches to prompting. Research online or experiment with your own (a great no-nonsense guide).
Warmup Example – Detect Negative Keyword Opportunities in the Browser
Enough talking. Let’s illustrate the power of ChatGPT by having it detect negative keyword opportunities.
Open up ChatGPT’s web interface at chat.openai.com. I’ll be using the GPT-3.5 model as this is the model that all users have access to.
Based on our prompt guidelines from earlier, we know our instructions should be specific, descriptive and detailed.
Let’s pretend that we are running a campaign for promoting a local plumbing service that is called out to homes in the area. How can ChatGPT help us with negative keywords?
1. Quick & Dirty
Prompt: plumber ads negative keywords
This is… surprisingly okay. For the information we provided at least.
The response provides general categories which may be worth excluding, with a couple of examples for each. This response would definitely be useful when brainstorming negative keywords before a campaign’s launch.
While it’s a start and there is nothing fundamentally incorrect about the output, we can do much better. How about providing search terms from a campaign that’s already running? Let’s try and be a little more detailed.
2. Providing Search Terms
Navigate to ‘Search Terms’ for one of your campaigns in the Google Ads interface and export the result in your preferred spreadsheet format.
I suggest using a period of 30 days, but this is campaign-dependent. Generally, having more data to work with is a plus.
Open the spreadsheet, sort search terms by the number of Impressions in descending order and select a sample of your search terms. There is an upper limit on how much text ChatGPT can handle, so 50 search terms is a sensible number for the purpose of practice.
I’ve removed some info for privacy reasons below but the search terms are what you need.
For this example, I will make up 20 terms for our fictional plumber in the interest of privacy.
Our search terms are below. I’ve highlighted search terms that would normally be excluded via negative keywords manually.
24/7 plumber near me |
best plumber perth |
plumber adelaide |
water heater repair |
how to fix a broken faucet |
licensed plumbers near me |
clogged sink help |
plumber for tap leak |
burst pipe emergency |
commercial plumbing service |
plumber quote |
fix water leak |
best plumbers in my area |
cheap plumber |
plumbing repair coupon |
running toilet help |
plumber for leaky pipes |
compare plumber prices |
plumbing service reviews |
how much do plumbers usually charge |
Let’s revise our prompt to be a little more detailed and let us include the campaign’s search terms.
Prompt: A Google Ads campaign is advertising a local plumbing service. I have provided a list of search terms from this campaign. Respond by identifying irrelevant search terms for a local plumbing service.
Search terms: (Search term list)
This response is a little better. The bot’s reply provides specific examples of potentially problematic search terms. It also correctly identified situations where a user may be seeking information. ChatGPT had no issue bringing attention to concerns around the location of the business and potential clashes with the service provided using limited information either.
There are a couple of potential examples it missed, such as “plumbing repair coupon” (low probability of conversion) and “how to fix a broken faucet (looking for DIY advice). But it’s an impressive result nonetheless.
3. Adding Company & Campaign Information
Let’s see if we can improve the results by providing even more information in our prompt. I suggest opening a ‘New chat’ so the responses are not influenced by any previous conversation.
Prompt: A Google Ads campaign is advertising a local plumbing serviced named Perth Pleasant Plumbing based in Perth, WA. The aim of the ad campaign is to generate leads and phone calls through a form on their landing page. Perth Pleasant Plumbing will then send a qualified plumber to the customer’s location. We are only interested in reaching users who have a high probability of converting.
Perth Pleasant Plumbing competes through a broad service range, quick response times and friendly plumbers.
I have provided a list of search terms from this campaign. Respond with any search terms that may not be relevant to this campaign and explain why each one is not relevant.
Search terms: (Search term list)
Here, we provided additional information to steer ChatGPT in the right direction.
An understanding of what the campaign is trying to do (generate leads through converting users), where the service is located (Perth) and the company’s strengths (speed & service) help the bot provide more accurate results. This steers the focus towards non-commital search terms and irrelevant locations.
We also get more information on why ChatGPT believes a term is irrelevant by asking it to provide a rationale. While it was happy to do so in our previous example, requesting the rationale explicitly improves the consistency of responses.
This prompt successfully shortlisted almost all of the search terms that we identified as problematic (I would personally exclude “plumbing repair coupon” as well). Impressively, it also provided warnings for price-related terms (this wasn’t one of the company’s points of competitive advantage).
Skimming these terms and identifying negative keyword opportunities is much easier.
There’s infinite room to refine the prompt through trial and error, but this will be left as an experiment for the reader. Our prompt didn’t specify to only include irrelevant terms and occasionally it will provide these as well. Small improvements like these can add up if a prompt is going to be reused regularly.
By utilising ChatGPT’s ability to interpret natural language, you can save time and explore creative new possibilities for your Google Ads campaigns.
Let’s Automate! – Detect Negative Keyword Opportunities through Google Ads Scripts
1. Generate the base script
This is a great start. We can identify a shortlist of irrelevant search terms from a given campaign and speed up the pruning process via negative keywords.
But how can we make this process even more efficient?
How about pulling search terms from a campaign directly?
Once again, ChatGPT is coming to the rescue. Let’s try the following prompt:
“Generate a Google Ads Script to perform the following:
Using the name of a campaign that I provide, retrieve a list of search terms from the last 30 days who have at least 2 impressions.
Then, using the OpenAI API’s ‘/v1/chat/completions’ endpoint, send the following prompt to ChatGPT’s gpt-3.5-turbo model:
“A Google Ads campaign is advertising a local plumbing service named Perth Pleasant Plumbing based in Perth, WA. The aim of the ad campaign is to generate leads and phone calls through a form on their landing page. Perth Pleasant Plumbing will then send a qualified plumber to the customer’s location. We are only interested in reaching users who have a high probability of converting.
Perth Pleasant Plumbing competes through a broad service range, quick response times and friendly plumbers.
I have provided a list of search terms from this campaign. Respond with any search terms that may not be relevant to this campaign and explain why each one is not relevant.
(insert the list of search terms here) “
Send the API’s response to a Google Sheet, placing each search term and its rationale in a new cell.
Explain what each part of the script does using code comments. “
This should look familiar after the last exercise.
A version of our previous prompt can be found sandwiched in the middle of our new request. We also provided additional information in our request, namely:
- We want a Google Ads Script
- We want to be able to specify a campaign to target
- We want to pull a list of search terms from said campaign
- We want this script to communicate with ChatGPT (using the OpenAI API)
- We want this information to be recorded to a Google Sheet
- We want each part of this script to be explained
You don’t need to understand how the OpenAI API works or what the /v1/chat/completions/ endpoint refers to. Just know that there are multiple ways to communicate with ChatGPT via script. Outlining your requirements this way reduces the risk of confusing the bot and improves consistency.
Let’s see what ChatGPT gives us.
Looks good! Not only has it provided a script, but it’s outlined what each step is doing and given some info on how to set it up.
ChatGPT’s output will vary as there is an element of probability in responses. To make sure that we’re on the same page, I’ve included the code generated (for me) below.
// Set the name of the campaign you want to retrieve search terms from
var campaignName = "Your Campaign Name";
// Get the campaign ID based on the campaign name
var campaignIterator = AdsApp.campaigns().withCondition("Name = '" + campaignName + "'").get();
if (!campaignIterator.hasNext()) {
throw new Error("Campaign not found: " + campaignName);
}
var campaign = campaignIterator.next();
var campaignId = campaign.getId();
// Set the date range for retrieving search terms
var today = new Date();
var thirtyDaysAgo = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000);
// Retrieve search terms with at least 2 impressions in the last 30 days
var report = AdsApp.report(
"SELECT Query, Impressions " +
"FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
"WHERE CampaignId = " + campaignId + " " +
"AND Impressions >= 2 " +
"DURING " + Utilities.formatDate(thirtyDaysAgo, AdsApp.currentAccount().getTimeZone(), "yyyyMMdd") + "," + Utilities.formatDate(today, AdsApp.currentAccount().getTimeZone(), "yyyyMMdd")
);
var searchTerms = [];
while (report.hasNext()) {
var row = report.next();
searchTerms.push(row["Query"].trim());
}
// Prompt to send to ChatGPT
var prompt = "A Google Ads campaign is advertising a local plumbing service named Perth Pleasant Plumbing based in Perth, WA. The aim of the ad campaign is to generate leads and phone calls through a form on their landing page. Perth Pleasant Plumbing will then send a qualified plumber to the customer’s location. We are only interested in reaching users who have a high probability of converting.\n" +
"Perth Pleasant Plumbing competes through a broad service range, quick response times and friendly plumbers.\n" +
"I have provided a list of search terms from this campaign. Respond with any search terms that may not be relevant to this campaign and explain why each one is not relevant.\n\n" +
searchTerms.join("\n");
// Call the OpenAI API to get responses from ChatGPT
var openAiEndpoint = "https://api.openai.com/v1/chat/completions";
var openAiApiKey = "Your OpenAI API Key";
var response = UrlFetchApp.fetch(openAiEndpoint, {
method: "post",
headers: {
"Authorization": "Bearer " + openAiApiKey,
"Content-Type": "application/json"
},
payload: JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": prompt }
]
})
});
var responseData = JSON.parse(response.getContentText());
var searchTermsAndRationale = responseData.choices[0].message.content.split("\n");
// Save search terms and rationale to a Google Sheet
var sheetUrl = "Your Google Sheet URL";
var sheetName = "Sheet1";
var sheet = SpreadsheetApp.openByUrl(sheetUrl).getSheetByName(sheetName);
if (!sheet) {
sheet = SpreadsheetApp.openByUrl(sheetUrl).insertSheet(sheetName);
}
sheet.clearContents();
sheet.getRange(1, 1, searchTermsAndRationale.length, 2).setValues(searchTermsAndRationale.map(function (item) {
return [item.split(":")[0].trim(), item.split(":")[1].trim()];
}));
Logger.log("Search terms and rationale saved to Google Sheet: " + sheetUrl);
Let’s add this to our Ad Account.
2. Adding the Script to your Ad Account
Navigate to Scripts in the menu (under Tools & Settings) and click the plus symbol to create a new script.
Copy the contents of ChatGPT’s reply to the script and give it a name. You’ll want to paste this between the curly brackets following function main() in your new script
function main() {
[COPY AND PASTE CODE HERE]
}
As ChatGPT said, make sure you go through the code and update the campaign name you are using, your Open AI API key from earlier (see at https://platform.openai.com/account/api-keys) and a publicly editable Google Sheets link.
- var campaignName = “Your Campaign Name”;
- var sheetUrl = “Your Google Sheet URL”;
- var openAiApiKey = “Your OpenAI API Key”;
I recommend copy and pasting the campaign’s name directly as it needs to be an exact match. All of these values should be enclosed in quotation marks (“ “).
The first time that you try and run it, Google Ads will request you authorise the activity. Log in when prompted and follow the instructions you are provided.
I sometimes get a Bad Request error or another error code at this step. It’s not 100% clear why that is – perhaps a network issue? Despite this error, authorisation still works as intended.
If you click Run, Google will suggest previewing this script to make sure it works. Select Preview.
Navigate to Logs in the new popup.
Uh oh.
3. Squashing Bugs
That’s not right. Let’s ask ChatGPT what the issue is by pasting the error into chat directly.
It looks like the Script gets caught up somewhere. Copy the new script into Google Ads.
The updated Script manages to progress further but still produces an error. Once more, I will paste the error from the Logs tab into ChatGPT and watch the bot troubleshoot in real time.
Let’s update the code accordingly before running the preview.
The final version of the output script is below.
function main() {
// Set the name of the campaign you want to retrieve search terms from
var campaignName = "Your Campaign Name here";
// Get the campaign ID based on the campaign name
var campaignIterator = AdsApp.campaigns().withCondition("Name = '" + campaignName + "'").get();
if (!campaignIterator.hasNext()) {
throw new Error("Campaign not found: " + campaignName);
}
var campaign = campaignIterator.next();
var campaignId = campaign.getId();
// Set the date range for retrieving search terms
var today = new Date();
var thirtyDaysAgo = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000);
// Retrieve search terms with at least 2 impressions in the last 30 days
var report = AdsApp.report(
"SELECT Query, Impressions " +
"FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
"WHERE CampaignId = " + campaignId + " " +
"AND Impressions >= 2 " +
"DURING " + Utilities.formatDate(thirtyDaysAgo, AdsApp.currentAccount().getTimeZone(), "yyyyMMdd") + "," + Utilities.formatDate(today, AdsApp.currentAccount().getTimeZone(), "yyyyMMdd")
);
var searchTerms = [];
while (report.hasNext()) {
var row = report.next();
searchTerms.push(row["Query"].trim());
}
// Prompt to send to ChatGPT
var prompt = "A Google Ads campaign is advertising a local plumbing service named Perth Pleasant Plumbing based in Perth, WA. The aim of the ad campaign is to generate leads and phone calls through a form on their landing page. Perth Pleasant Plumbing will then send a qualified plumber to the customer’s location. We are only interested in reaching users who have a high probability of converting.\n" +
"Perth Pleasant Plumbing competes through a broad service range, quick response times and friendly plumbers.\n" +
"I have provided a list of search terms from this campaign. Respond with any search terms that may not be relevant to this campaign and explain why each one is not relevant.\n\n" +
searchTerms.join("\n");
// Call the OpenAI API to get responses from ChatGPT
var openAiEndpoint = "https://api.openai.com/v1/chat/completions";
var openAiApiKey = "YOUR API KEY HERE";
var response = UrlFetchApp.fetch(openAiEndpoint, {
method: "post",
headers: {
"Authorization": "Bearer " + openAiApiKey,
"Content-Type": "application/json"
},
payload: JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": prompt }
]
})
});
var responseData = JSON.parse(response.getContentText());
var searchTermsAndRationale = responseData.choices[0].message.content.split("\n");
// Save search terms and rationale to a Google Sheet
var sheetUrl = "YOUR GOOGLE SHEETS URL HERE";
var sheetName = "Sheet1";
var sheet = SpreadsheetApp.openByUrl(sheetUrl).getSheetByName(sheetName);
if (!sheet) {
sheet = SpreadsheetApp.openByUrl(sheetUrl).insertSheet(sheetName);
}
sheet.clearContents();
sheet.getRange(1, 1, searchTermsAndRationale.length, 2).setValues(searchTermsAndRationale.map(function (item) {
return [item.split(":")[0].trim(), item.split(":")[1].trim()];
}));
Logger.log("Search terms and rationale saved to Google Sheet: " + sheetUrl);
}
4. Executing the Final Google Ads Script
As we need a real-world Ad Account for this to work, I’ve redacted some information of the client’s information and updated the prompt accordingly. The final output can be found below.
Not bad right? We’ve managed to avoid manually trawling through the search terms of a campaign with a shortlist of irrelevant terms, alongside what makes them irrelevant. Consider how easy it is to manually review these, compared to the huge list of search terms we started with!
5. Scheduling the Script to Run Automatically
To get the most out of this script, navigate to the Scripts page and go to the Frequency column. As this script currently checks the last 30 days, repeating Monthly is appropriate. Set this up like so.
Personally, I opt for sometime early in the morning so that we’re never going to risk viewing the Google Sheet before it’s finished.
And there you have it! You now have a Google Ads Script which automatically highlights search terms that may be a poor fit for a campaign. For the sake of keeping our prompt short (100s of search terms can get a little messy), we opted to only include search terms with 2 or more impressions. With a shorter timeframe (or for smaller campaigns), using all search terms may be appropriate.
6. Modifying the Script Further
Making these updates is as simple as navigating through the script and making the changes or asking ChatGPT directly.
You can achieve similar results by requesting an update to the prompt used within the script, adding a new column to the sheet and more. The sky is the limit!
This includes automatically applying negative exact-match keywords to your Ad Account if desired. I don’t recommend this without human approval but the option exists.
Considerations & Limitations
Before applying to a live environment, you should be mindful of the following considerations and limitations.
Privacy and Sensitive Info
While search terms are generally fair game, you should avoid sharing sensitive or personally identifiable information with ChatGPT.
Your OpenAI API key should not be exposed in Google Ads Scripts or anywhere else that unauthorised users have access to (ie. anybody outside of your organisation).
Rate Limits
While Google has not been transparent about these, there are some limitations on how often you can request access to Ad Account information in a short period of time.
ChatGPT’s Data – Avoid Recent Info & Links
ChatGPT’s training data includes information up until September 2021. The model’s responses won’t reflect real-time updates so your mileage may vary for search terms about developing industries or topics.
Character Limits
There are limits on how much information ChatGPT can handle at once. While there’s not a specific limit on word count per se, prompts that are too long will produce an error. Research “ChatGPT context length” for a more in-depth explanation.
Numbers
When working with numerical data, ChatGPT can struggle. If the code you generate handles numerical values, it’s worth confirming they match with what you expect them to.
ChatGPT Can’t Replace an Experienced Developer (Yet!)
While ChatGPT can generate code that works, it is not always optimal and is not capable of replacing an experienced developer for the time being.
In our example earlier, the generated script calculated a date 30 days ago manually, but reviewing Google’s documentation reveals there is an inbuilt way to do the same thing with more consistent behaviour using one of their predefined date ranges (‘LAST_30_DAYS’).
If you are going to use a Google Ads Script consistently or in a client-facing way, it’s worth getting an expert pair of eyes to review it first.
Conclusion
ChatGPT is an invaluable boon to the modern PPC toolkit. You can use it to identify negative keyword opportunities, create a script from scratch, communicate with itself and give you a shortlist of irrelevant search terms. You’re also ready to get started with modifying it further and making it your own.
Have you come up with a cool new use case? I’d love to hear about it – shoot me a message on LinkedIn.
Want to experience the Fisher Digital difference firsthand? Reach out about your Google Ads needs and we will be in touch.
More Blogs & Latest News like this
Web Technologies
Safeguarding Your Digital Frontier: The Vital Importance of Website Maintenance and Security
In today's digital era, where online presence has become synonymous with credibility and success, the role of a wel...
Social Media
All About Threads
All About Threads Meta has recently launched a new app named Threads. Along with the rest of the world, we're st...
Social Media
2023 Social Media Video Trends: How Brands in Perth Can Benefit
The start of a new year is a great time to take a closer look at the upcoming video trends in the world of social media. This...
Latest Insights