How to find any Company's Main Competitors directly in Google Sheets

Jan 30, 2024

Founder Avatar

Frank Jenkins

How to find any Company's Main Competitors directly in Google Sheets

Finding other companies competitors can be a huge advantage for your email strategies. Whether it is for personalization or research. But finding the main competitors for each company can be a tedious task.

Well in this guide we'll show you how to get any company's main competitors in a matter of seconds right in Google Sheets. And the best part is that it is completely automatic and in bulk.

It is completely free and you can enrich up to 100 companies per day. It runs using Google Programmable Search combined with Google Search results and some query magic.

Set-up

First, you have to get an API key from Google Programmable Search to be able to do the queries. Don't worry it takes less than a minute and it's completely free.

1. Go to Programmable Search Overview

2. Under the "API Key" section, click "Get a Key"

3. In the popup, create a new project. Give it whatever name you like and save it

Create a project in Custom Search API

4. After that, click in the "Show Key" button. It will show an API key like the one below, copy it and save it.

Click show API Key and copy it

Google Sheets Script

Now we have to create the script that will run our query. Don't worry I'll give you the code so you can copy-paste it.

1. Open a Google Sheets document

2. Click on "Extensions" at the top and then click on "Apps Scripts"

Click on extensions and Apps Scripts

3. Once the script opens, replace the default function for the following code:

// Replace these with your actual API key
const API_KEY = 'YOUR_API_KEY';

/**
* Get the competitors for a specific company.
*
* @param {string} companyName - Name of the company
* @returns {string} Result
* @customfunction
*/
function findCompetitors(companyName) {
if (companyName == "") { return "Error - No Company Name" }

const SEARCH_ENGINE_ID = '87c12b985b8f94bda'; //eCold.ai's engine - you can use it too

// Create query to find top 10 alternatives of a company on G2's website
searchQuery = "Top 10 " + companyName + " Alternatives & Competitors site:g2.com/products"

// Construct the URL for the Google Custom Search JSON API
searchUrl = `https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${SEARCH_ENGINE_ID}&q=${encodeURIComponent(searchQuery)}`;

// Send a GET request to the API
response = UrlFetchApp.fetch(searchUrl, { method: 'get' });

// Parse the JSON response
data = JSON.parse(response.getContentText());

// If there are any items in the response data
if (data?.items?.length > 0) {
competitorsList = data.items[0]?.pagemap?.listitem;

// Filter competitors with a URL and a position, then map to their names
competitors = competitorsList?.length > 0 ? competitorsList.filter(item => !!item.url && !!item.position).map(item => item.name) : "Not found";

// If there are any competitors, return them as a comma-separated string, else return "Not found"
return competitors?.length > 0 ? competitors.join(', ') : "Not found";
} else {
return "Not found";
}
}

It should look like this:

Script code

4. Then, replace at the top where it says 'YOUR_API_KEY' with the key you got on the first step (Programmable Search Key)

5. Click the save icon at the top (or press Ctrl+S) to save it.

You can now close the Script tab if you want to return to the original Google Sheet.

You're ready to use it

Your extension is now ready! You can use it directly in your Google Sheet as if it was a normal formula.

Just type

=findCompetitors(A2)

Change A2 to the cell where the Company name is, click enter, and watch your script do the magic!

Here's a GIF of me using it so you can see it in action:

Find any company's competitors directly in Google Sheets

Hope you found this helpful! If you have any questions please feel free to contact us.

Personalize emails at
scale with eCold.ai

eCold.ai offers personalization for cold emailers at scale

Claim your free 20 credits