Check to see if a page links to your URL or mentions your brand.

With this script you can input a URL to check and a keyword to check (optional) to see whether they’re included on a particular page. Perfect for reviewing unlinked brand mentions or for checking to see whether pages on your site link to a target page. 🚀

Check out the GIF to see it in action 🎥

How to add the Script to Google Sheets

1. Copy the script below:

  * Check to see if a domain, path and/or mention exists on a page. 
  * @param {""} host input the host URL.
  * @param {""} url input the URL you want to check.
  * @param {"brand"} mention input the string you want to check.
  * @return auto suggested questions from Google Search.
  * @customfunction

function linkChecker(host, url, mention) {

  // split up domain to remove protocols
  const domainSplitter = (url) => {
    const name = url.split('.')[1];
    const cc = url.split('.')[2];
    const cc2 = url.split('.')[3];

    return (cc2 ? name.concat(",", cc, ".", cc2) : name.concat(".", cc));

  // check to see if there's path
  const pathChecker = (url) => {
    const split = url.split('/');
    return (split[3] !== '' ? true : false);

  try {

    const doc = UrlFetchApp.fetch(host).getContentText();

    // use Cheerio library to return body content
    const $ = Cheerio.load(doc);
    const body = $('body').html().toLowerCase();

    mention = mention || -1;
    let mentionIndex = mention;

    // if there's a mention passed as an arg, search for mentions in content
    if (mention !== -1) {
      mention = mention.toLowerCase();
      mentionIndex =;

    // search for relative path or domain in content
    const urlSearch = pathChecker(url) ? "/" + url.split('/').slice(3).join('/') : domainSplitter(url).replace(/\//g, '');
    const urlIndex =;

    if (urlIndex != -1 && mentionIndex != -1) {
      return "There's a link and a mention";
    } else if (urlIndex != -1) {
      return "There's a link";
    } else if (mentionIndex != -1) {
      return "There's a mention";
    } else {
      return "There's no link or mention";

  } catch (e) {
    return "Website failed";


2. Head over to Google Sheets

Or if you’re really smart, create a new sheet by going to:

Select Script editor from the Tools menu.

Paste the script and save it.

3. Add the Cheerio Library in Apps Script

Search for the Cheerio Library using the ID below. The Cheerio Library makes it easier to parse the HTML from the requested page.


If you’re not sure how to add a library in Apps Script, follow the gif below:

4. Add the formula to any cell in your sheet


Replace A1 with any cell that includes your host page (the page you want to crawl).
Replace A2 with any cell that includes the link you’d like to check.
Replace A3 with any cell that includes the keyword you’d like to check (this could your brand name for example) – this is optional.

My link checker script will search for a relative path if you input a page, rather than a domain. So for example, let’s say you input ‘’, it will search for ‘/page’ as many internal links are often relative.

If you input a domain, say “”, it will search for ‘’ to capture all protocols that a referring page might use.

*Websites could fail when fetching because of bot detection algorithms.

Thanks for stopping by 👋

I’m Andrew Charlton, the Google Sheets nerd behind Keywords in Sheets. 🤓

Questions? Get in touch with me on social or comment below 👇

More Scripts

Submit your response

Your email address will not be published. Required fields are marked *

11 Responses on this post

  1. Thanks for all the scripts Andrew!

    This is great but I’m running into a trailing slash issue…
    If I add the slash to the “URL to check” (e.g., it doesn’t pick up when a page has the link without it (
    And if I remove it from the URL to check, the script seems to say all pages include the link (which I know they don’t).

    Any help much appreciated and keep up the good work!

    1. Ahh this is a bug I already knew about but thought it would be an edge case. I’ll see if I can fix that for you! 🙂

      1. Okay, I’ve now made a change to the code and template to try and fix this. Could you re-test please? 🙂

  2. Hi Andrew

    Just tried the script off to find potential internal link options.

    Unfortunately, it seems that the script also checks for our menu which is why we end up getting mentions and links on almost all urls.

    1. Hmm yeah that sucks! So if your website is using semantic HTML and your content is contained within a

      you can change the line: const body = $(‘body’).html().toLowerCase(); to const body = $(‘section’).html().toLowerCase(); and it will only extract the body content. Hope that helps! 🙂
        1. I can see the comment-field has removed some of my comment cause of HTML. I meant to write “P tags” 🙂

        1. Great, I might add an argument into the function to allow you to specify where to look for links 🙂