Free SEO Tools with Google App Script

Free SEO Tools on Google Sheets with Google App Script

Google Sheets have many restrictions, quota limits however they can still be helpful in daily SEO tasks especially if you have a small website or else if you want to check SEO data quickly on small number of URLs.

Please find below 5 javascript functions written with Google App Script which can be used as Free SEO Tools on Google Sheets.

The source code is also available at https://github.com/aysunakarsu/Simple/blob/master/SEOTools.js

function Response(uri)
{
  try {
  var options = {
  followRedirects : false
 };
  var response = UrlFetchApp.fetch(uri, options);
  return response.getResponseCode() ;  
  }  
   catch (error) {        
     return "Error";
    }
}
function Title(uri) {
  var html = getContents(uri);
  var title = html.match('<title>([^\<]+)</title>')[1];
  return title;
}
function H1(uri) {
  var html = getContents(uri);
  var h1 = html.match('<h1[^\>]*>([^\<]+)</h1>')[1];
  return h1;
}
function ILinks(uri) {
  var base_uri = uri.split('://')[0] + "://" + uri.split('://')[1].split('/')[0];
  var inner_links = [];
  inner_links=getInnerLinks(uri,base_uri);
  return inner_links.length;
}

function getInnerLinks(get_uri,getbase_uri) {
  try  {
    var html = getContents(get_uri);
    if (html.indexOf('</head>') !== -1 ) {
        html = html.split('</head>')[1];    
        if (html.indexOf('</body>') !== -1 ) {
           html = html.split('</body>')[0] + '</body>';
           var inner_links_arr= [];
           var linkRegExp = /href="([^\"#]+)"/gi; // regex href
           var extractLinks = linkRegExp.exec(html);
           var item=getbase_uri;
           var pagesVisited = {};
           while (extractLinks != null) {
              if ((extractLinks[0].indexOf("href=")==0))
                  if (extractLinks[1].indexOf(getbase_uri)==0)  item= extractLinks[1];                 
                  else if (extractLinks[1].indexOf("http")!==0) item= getbase_uri+extractLinks[1];
                  if (!(item in  pagesVisited)) {
                    pagesVisited[item]=true;
                    inner_links_arr.push(item);
                    }
              extractLinks = linkRegExp.exec(html); }
           return inner_links_arr;  
           }
       }
  }
  catch (e) {
   return "Error"
  }
}
function ELinks(uri) {
  var base_uri = uri.split('://')[0] + "://" + uri.split('://')[1].split('/')[0];
  var external_links = [];
  external_links=getExternalLinks(uri,base_uri);
  if (typeof external_links !== 'undefined' && external_links.length > 0 )
      return external_links.length;
 return 0;       
}
function getExternalLinks(get_uri,getbase_uri) {
  try  {
    var html = getContents(get_uri);
    if (html.indexOf('</head>') !== -1 ) {
        html = html.split('</head>')[1];    
        if (html.indexOf('</body>') !== -1 ) {
           html = html.split('</body>')[0] + '</body>';
           var external_links_arr= [];
           var linkRegExp = /href="(http[^"#]+)"/gi; // regex href
           var extractLinks = linkRegExp.exec(html);
           var pagesVisited = {};
           while (extractLinks != null) {
              if (extractLinks[0].indexOf("href=")==0)  {
                  if (extractLinks[1].indexOf(getbase_uri) != 0 &&  (!(extractLinks[1] in  pagesVisited)) ){
                    pagesVisited[extractLinks[1]]=true;
                    external_links_arr.push(extractLinks[1]);}
                    }
              extractLinks = linkRegExp.exec(html); }
           return external_links_arr;  
           }
       }
  }
  catch (e) {
    return e;
  }
}
function getContents(uri) {
  var result = UrlFetchApp.fetch(uri);
  var contents = result.getContentText();
  return contents;
}

How to use SEO Tools functions?

  1. Go to Google Drive and create a new spreadsheet, name it , e. g. simpleseotools
  2. Add the URLs you want to check in the first column, one URL per row.
  3. From the Tools menu choose Script Editor.
  4. Paste the script code from above into the file and save it.
  5. Go to the spreadsheet, and call the function you select on each row in the next columns, for example

   For the URL in the first column first row; call =Response($A1) or else =Title($A1) or else =H1($A1) or else  =ILinks($A1) or else =Elinks($A1) on the same row in the next column. Repeat the same process on the following rows and columns. 

For more information on Quota Limits please see the table on the Google Apps Script Dashboard.  

  

 

Thanks for taking time to read this post. I offer consulting, architecture and hands-on development services in web/digital to clients in Europe & North America. If you'd like to discuss how my offerings can help your business please contact me via LinkedIn

Have comments, questions or feedback about this article? Please do share them with us here.

If you like this article

Follow Me on Twitter

Follow Searchdatalogy on Twitter

Comments

About Us

My objective is bringing all my experience and expertise together to deliver solid technology solutions that can take your search traffic acquisition to the next level. My main goal is to assist you in building and maintaining your search marketing analytics platforms. My will is to leverage your marketing and IT teams search knowledge while bridging the gap between two.

Certificates

Botify: Botify Certified Consultant

IBM: Data Scientist, Data Engineering Certificates

Google: Google Analytics, Google Adwords, Mobile Sites, Digital Sales Certificated Professional

Coursera: Data Engineering on Google Cloud Platform Specialization

Legal Terms Privacy

Recent Posts

HTTP2 On Top Sites 1 month, 2 weeks ago
Desktop & Mobile Performances 5 months, 4 weeks ago
Alexa Top 1 Million Sites 6 months, 1 week ago
Best SEO Conferences In 2018 7 months, 1 week ago
BrightonSEO Conference 11 months, 1 week ago
Web Marketing Festival 1 year, 1 month ago
WebCampDay 1 year, 2 months ago
QueDuWeb 1 year, 3 months ago
SEOCamp'us 1 year, 5 months ago
1 Million #SEO Tweets 1 year, 6 months ago
SEO, Six Blind Men & An Elephant 1 year, 7 months ago
SEO Hero 2017 1 year, 8 months ago
Digitalzone 1 year, 8 months ago
Technical SEO Log Analysis 1 year, 9 months ago
3 Ways For Free HTTPS 1 year, 10 months ago
Crawl Dictionary 1 year, 10 months ago
HTTPS On Top Sites 1 year, 11 months ago

Recent Tweets