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?
- Go to Google Drive and create a new spreadsheet, name it , e. g. simpleseotools
- Add the URLs you want to check in the first column, one URL per row.
- From the Tools menu choose Script Editor.
- Paste the script code from above into the file and save it.
- 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
Comments