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

Legal Terms Privacy

Data SEO

Gael Gegourel: Data Engineer SEO

Hamlet Batista: CEO Ranksense

Walid Gabteni: Consultant SEO

Vincent Terrasi: Data Scientist SEO

Remi Bacha: Data Scientist SEO

Recent Posts

SEO data distribution analysis 1 year, 2 months ago
SEO data forecasting 2 years, 1 month ago
SEO data analysis 2 years, 1 month ago
BrightonSEO conference 2 years, 1 month ago
HTTP2 on top sites 2 years, 4 months ago
Desktop & mobile performances 2 years, 9 months ago
Alexa top 1 million sites 2 years, 9 months ago
1 million #SEO tweets 3 years, 9 months ago
SEO, six blind men & an elephant 3 years, 10 months ago
3 ways for free https 4 years, 1 month ago
Crawl dictionary 4 years, 1 month ago
Https on top sites 4 years, 2 months ago
SEO web server log files 4 years, 3 months ago
Hsts on google.com 4 years, 3 months ago

Recent Tweets