If you’re an SEO professional or content creator, you know how important it is to ensure your target keywords are present in your web content. Manually checking for keywords can be time-consuming and error-prone. But what if you could automate this process with just a few lines of code?
In this guide, I’ll show you how to set up a Google Apps Script that checks your webpage for exact and phrase matches of your selected keywords and highlights them if they are found in your webpage. Let’s dive in!
Step 1: Set Up Your Google Sheet
- Open Google Sheets and create a new spreadsheet.
- In cell A2, enter the URL of the webpage you want to check.
- In column B, starting from B2, list your target keywords.
Here’s how your sheet should look:
| A | B |
|---|---|
| URL | Keywords |
| https://www.yourselectedwebpage.com | example keyword |
| keyword of your choice | |
| example keyword of your choice |
Step 2: Open Google Apps Script
- In your Google Sheet, click on Extensions > Apps Script.
- This will open the Google Apps Script editor in a new tab.
Step 3: Add the Script
Add a Script
- Adding a script is straightforward task. Simply click on the ‘+’ symbol located in the Files tab, select ‘Script,’ and proceed to provide a name for your script. In this case you may write Keyword Checker. Copy and paste the code below and save:
function checkKeywords() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const url = sheet.getRange("A2").getValue();
if (!url) {
SpreadsheetApp.getUi().alert("No URL found in A2!");
return;
}
try {
const response = UrlFetchApp.fetch(url, { muteHttpExceptions: true });
if (response.getResponseCode() !== 200) {
SpreadsheetApp.getUi().alert(`Failed to fetch the webpage. HTTP Code: ${response.getResponseCode()}`);
return;
}
const htmlContent = response.getContentText().toLowerCase();
const keywordsRange = sheet.getRange("B2:B" + sheet.getLastRow());
const keywords = keywordsRange.getValues();
keywords.forEach((keyword, index) => {
const keywordText = keyword[0].trim().toLowerCase();
if (!keywordText) return;
const words = keywordText.split(/\s+/);
let exactMatch = htmlContent.includes(keywordText);
let phraseMatch = words.every(word => htmlContent.includes(word));
if (exactMatch) {
sheet.getRange(index + 2, 2).setBackground("#00FF00");
} else if (phraseMatch) {
sheet.getRange(index + 2, 2).setBackground("#FFFF00");
} else {
sheet.getRange(index + 2, 2).setBackground("#FF0000");
}
});
} catch (error) {
SpreadsheetApp.getUi().alert("Error fetching URL: " + error.message);
}
}
Step 4: Save and Run the Script
- Click the Save button (or press
Ctrl + S) and give your project a name, such as SEO Keyword Checker. - To run the script, click the Run button (▶️) in the toolbar.
- The first time you run the script, Google will ask for authorization. Click Review Permissions, select your Google account, and allow the necessary permissions.
Step 5: Check the Results
- Go back to your Google Sheet.
- You’ll see that the script has highlighted the keyword cells:
- Green: Exact match found.
- Yellow: Phrase match found (all words in the keyword are present, but not in exact order).
- Red: No match found.
Benefits and Advantages of Using the Script
This script can be very useful for SEO professionals, content editors as well as creators because it automates the tedious process of keyword checking, saving times. It ensures your content is optimized by highlighting exact and phrase matches, providing clear, actionable insights. With its scalability, accuracy, and ease of use, it’s perfect for auditing single pages of importance. Plus, it’s completely free and customizable, making it a cost-effective solution for anyone looking to improve their SEO strategy without any paid tools. Whether you’re a beginner or an expert, this script empowers you to create better-optimized content, boost search rankings, and drive more organic traffic—all with just a few clicks.
- Automates keyword checking, saving hours of manual work.
- Ensures content optimization by highlighting exact and phrase matches.
- Provides clear, actionable insights with color-coded results (green, yellow, red).
- Scales effortlessly for single pages or entire websites.
- Boosts accuracy by eliminating human error in keyword audits.
- Cost-effective and free, running on Google’s infrastructure.
- Customizable to fit your specific SEO needs.
Conclusion
In the ever-evolving world of SEO, staying ahead means leveraging tools that save time, improve accuracy, and deliver actionable insights. This Google Apps Script is more than just a convenience—it’s a powerful ally in your quest for better-optimized content. By automating keyword checks, it eliminates the tedious manual work, ensures your content aligns with your SEO goals, and provides a clear visual roadmap for improvements. Whether you’re auditing a single page or scaling up for an entire website, this script is a cost-effective, customizable, and efficient solution that empowers you to focus on what truly matters: creating content that ranks. Give it a try, and experience firsthand how a few lines of code can transform your SEO workflow. Happy optimizing! 🚀