Example of using JavaScript directly in your browser’s console.

How to Use JavaScript to Automate SEO (With Scripts)

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Get Stunning Website in just 30 days

Services on: Website Design & Development | Website revamp | SEO | Social Media Optimization | Digital Marketing 


Programming and automation are more and more well-liked matters within the SEO business, and rightfully so.

Leveraging new methods to extract, remodel, and analyze information at scale with minimal human enter could be extremely helpful.

Though pace is vital, one of many foremost advantages of utilizing automation is that it takes the load off our shoulders from repetitive duties and leaves us extra time to use our brains.

Learn on to study a number of the advantages of utilizing JavaScript to automate SEO duties, the principle avenues you may take to begin utilizing it, and some concepts to hopefully spark your curiosity.

Why Study Automation With JavaScript?

Lots of improbable automation initiatives locally come from SEO professionals coding in Python together with Hamlet Batista, Ruth Everett, Charly Wargnier, Justin Briggs, Britney Muller, Koray Tuğberk GÜBÜR, and lots of extra.

Nonetheless, Python is simply one of many many instruments you need to use for automation. There are a number of programming languages that may be helpful for SEO equivalent to R, SQL, and JavaScript.

Outdoors of the automation capabilities you’ll study within the subsequent part, there are clear advantages from studying JavaScript for SEO. Listed here are just some:

1. To Advance Your Data to Audit JavaScript on Web sites

Whether or not or not you take care of internet apps constructed with well-liked frameworks (e.g., Angular, Vue), the probabilities are that your web site is utilizing a JavaScript library like React, jQuery, or Bootstrap.

(And even perhaps some customized JavaScript code for a particular objective.)

Studying to automate duties with JavaScript will enable you to construct a extra stable basis to dissect how JavaScript or its implementation could also be affecting your website’s natural efficiency.

2. To Perceive and Use New Thrilling Applied sciences Primarily based on JavaScript

The online growth business strikes at an extremely quick tempo. Therefore, new transformative applied sciences emerge always, and JavaScript is on the heart of it.

By studying JavaScript, you’ll have the ability to higher perceive applied sciences like service workers, which can immediately have an effect on SEO and be leveraged to its profit.

Moreover, JavaScript engines like Google’s V8 are getting higher yearly. JavaScript’s future solely appears brighter.

3. To Use Instruments Like Google Tag Supervisor That Depend on JavaScript to Work

If you happen to work in SEO, chances are you’ll be acquainted with Tag Administration Methods like Google Tag Supervisor or Tealium. These providers use JavaScript to insert code (or tags) into web sites.

By studying JavaScript, you can be higher outfitted to perceive what these tags are doing and probably create, handle and debug them in your web site.

4. To Construct or Improve Your Personal Web sites with JavaScript

One of many nice issues about studying to code in JavaScript is that it’s going to enable you to to construct web sites as aspect initiatives or testing grounds for SEO experiments.

There isn’t a higher approach to perceive one thing than by getting your palms soiled, particularly if what you need to check depends on JavaScript.

Paths to Leveraging JavaScript for SEO Automation

JavaScript was initially developed as a browser-only language however has now advanced to be in every single place, even on {hardware} like microcontrollers and wearables.

For the needs of SEO automation, there are two foremost environments the place you may automate SEO duties with JavaScript:

  • A browser (front-end).
  • Instantly on a pc/laptop computer (back-end).

SEO Automation with Your Browser

One of many foremost benefits that separate JavaScript from different scripting languages is that browsers can execute JavaScript. This implies the one factor you want to get began with JavaScript automation is a browser.

Automation Utilizing the Browser’s Console

The simplest approach to get began is utilizing JavaScript immediately in your browser’s console.

There are some straightforward and enjoyable automations you are able to do. For instance, you can also make any web site editable by typing “document.body.contentEditable = true” in your console.

Example of using JavaScript directly in your browser’s console.

This could possibly be helpful for mocking up new content material or headings on the web page to present to your shoppers or different stakeholders in your organization with out the necessity for picture enhancing software program.

However let’s step it up a bit extra.

The Lesser-Recognized Bookmarklets

Since a browser’s console can run JavaScript, you may create customized capabilities that carry out particular actions like extracting info from a web page.

Nonetheless, creating capabilities on the spot generally is a bit tedious and time-consuming. Subsequently, Bookmarklets are an easier approach to save your individual customized capabilities with out the necessity for browser plugins.

Bookmarklets are small code snippets saved as browser bookmarks that run capabilities immediately from the browser tab you’re on.

An example of a Bookmarklet.

For instance, Dominic Woodman created a bookmarklet here that enables customers to extract crawl stats information from the previous Google Search Console person interface and obtain it to a CSV.

It’d sound a bit daunting, however you may find out how to create your individual Bookmarklets following the steps in this great resource on GitHub.

Snippets, a Person-Pleasant Model of Bookmarklets

If you happen to use Chrome, there’s an excellent less complicated resolution utilizing Snippets. With this, you may create and save the identical sort of capabilities in a way more user-friendly approach.

For instance, I’ve created a small Snippet that checks what number of “crawlable” hyperlinks are on-page and obtain the listing to a CSV file. You possibly can download the code from GitHub here.

Chrome snippet link counter SEO.

Whereas these are normally small duties which might be “nice to have” you’d in all probability need to do extra heavy-lifting duties that may assist together with your SEO workload in a extra vital approach.

Subsequently, it’s a lot better to use JavaScript immediately in your laptop computer (or a server within the Cloud) utilizing Node.js.

SEO Automation within the Again-Finish with Node.js

Node.js is software program that allows you to run JavaScript code in your laptop computer with out the necessity for a browser.

There are some variations between operating JavaScript in your browser and JavaScript in your laptop computer (or a server within the Cloud) however we’ll skip these for now as that is only a brief intro to the subject.

Nodejs homepage screenshot.

So as to run scripts with Node.js, you will need to have it put in in your laptop computer. I’ve written a brief weblog put up the place I am going step-by-step on how you can install Node in addition to a number of extra setup suggestions to make it simpler to get you began.

Though your creativeness is the restrict when it comes to automation, I’ve narrowed it down to a number of areas that I see SEO professionals come again to when utilizing Node.js.

I’ll embody scripts which might be prepared to run so you may get began very quickly.

Extracting Information From APIs

Accumulating info from completely different sources to present insights and advocate actions is without doubt one of the commonest jobs in SEO.

Node.js makes this extremely easy with completely different choices, however my most well-liked go-to module is Axios.

// Create an index.js file inside a folder & paste the code under

// Import axios module
const axios = require('axios');

// Customized perform to extract information from PageSpeed API
const getApiData = async (url) => {
  const endpoint="https://www.googleapis.com/pagespeedonline/v5/runPagespeed";
  const key = 'YOUR-GOOGLE-API-KEY' // Edit with your individual key;
  const apiResponse = await axios(`${endpoint}?url=${url}&key=${key}`); // Create HTTP name
  console.log(apiResponse.information); // Log information
  return apiResponse.information;
};

// Name your customized perform
getApiData('https://www.searchenginejournal.com/');

To start out interacting with APIs, you want a module that’s ready to deal with HTTP requests (HTTP shopper) and an endpoint (a URL to extract info).

In some circumstances, you may additionally want an API key, however this isn’t at all times crucial.

For a style of how Node.js interacts with APIs, try this script I printed that makes use of Google’s PageSpeed API to extract Core Net Vitals information and different lab metrics in bulk.

Scraping Web sites

Whether or not you want to to monitor your individual web site, control your rivals or just extract info from platforms that don’t supply an API, scraping is an extremely great tool for SEO.

Since JavaScript interacts nicely with the DOM, there are numerous benefits to utilizing Node.js for scraping.

The most typical module I’ve used for scraping is Cheerio, which has a really comparable syntax to jQuery, together with an HTTP shopper like Axios.

// Import modules
const cheerio = require('cheerio');
const axios = require('axios');

// Customized perform to extract title
const getTitle = async (url) => {
  const response = await axios(url); // Make request to desired URL
  const $ = cheerio.load(response.information); // Load it with cheerio.js
  const title = $('title').textual content(); // Extract title
  console.log(title); // Log title
  return title;
};

// Name customized perform
getTitle('https://www.searchenginejournal.com/');

If you happen to want the rendered model of a web site, well-liked modules like Puppeteer or Playwright can launch a headless occasion of an precise browser like Chrome or Firefox and carry out actions or extract info from the DOM.

Chris Johnson’s Format Shift Generator is a superb instance of how to use Puppeteer for SEO. Yow will discover more info here or download the script here.

There are additionally different choices like JSDOM that emulate what a browser does with out the necessity for a browser. You possibly can mess around with a JSDOM-based script utilizing this Node.js SEO Scraper constructed by Nacho Mascort.

Processing CSV and JSON Information

More often than not, the info extracted from APIs comes as JSON objects, and JavaScript is ideal for coping with these.

Nonetheless, as SEOs, we usually take care of information in spreadsheets.

Node.js can simply deal with each codecs utilizing built-in modules just like the File System module or extra simplified variations like csvtojson or json2csv.

Whether or not you need to learn information from a CSV and remodel it into JSON for processing, otherwise you’ve already manipulated the info and also you want to output to CSV, Node.js has your again.

// Import Modules
const csv = require('csvtojson');
const { parse } = require('json2csv');
const { writeFileSync } = require('fs');

// Customized perform to learn URLs and convert it to JSON
const readCsvExportJson = async () => {
  const json = await csv().fromFile('yourfile.csv');
  console.log(json); // Log conversion JSON

  const transformed = parse(json);
  console.log(transformed); // Log conversion to CSV
  writeFileSync('new-csv.csv', transformed);
};

readCsvExportJson();

Create Cloud Capabilities to Run Serverless Duties

It is a extra superior case, however it’s extremely useful for technical SEO.

Cloud computing suppliers like Amazon AWS, Google Cloud Platform, or Azure make it extremely easy (and low cost) to arrange “instances of servers” that run customized scripts created for particular functions with out the necessity for you to configure that server.

A helpful instance could be to schedule a perform that extracts information from the Google Search Console API routinely on the finish of every single day and shops the info right into a BigQuery database.

Cloud function exmple to extract search console data and load it to big query.

There are a number of shifting components on this case, however the potentialities are actually countless.

Simply to present you an instance of how to create a cloud perform, try this episode of Agency Automators the place Dave Sottimano creates his personal Google Developments API utilizing Google Cloud Capabilities.

A Potential Third Avenue, Apps Script

For me, it made extra sense to begin with the less-opinionated method.

However Apps Script might supply a much less intimidating approach to study to code as a result of you need to use it in apps like Google Sheets that are the bread and butter of technical SEO.

Appscript homepage screenshot.

There are actually helpful initiatives that may give you a way of what you are able to do with Apps Script.

For instance, Hannah Butler’s Search Console explorer or Noah Lerner’s Google My Business Postmatic for native SEO.

If you’re inquisitive about studying Apps Script for SEO, I might advocate Dave Sottimano’s Introduction to Google Apps Scripts. He additionally gave this awesome presentation at Tech SEO Increase, which explains some ways to use Apps Script for SEO.

Ultimate Ideas

JavaScript is without doubt one of the most popular programming languages in the world, and it’s right here to keep.

The open-source neighborhood is extremely lively and always bringing new developments in numerous verticals – from internet growth to machine studying – making it an ideal language to study as an SEO skilled.

What you’ve examine on this article is simply the tip of the iceberg.

Automating duties is a step towards forsaking boring and repetitive on a regular basis duties, changing into extra environment friendly, and discovering new and higher methods to carry worth to our shoppers.

Hopefully this text reduces in a small capability the marginally unhealthy fame that JavaScript has within the SEO neighborhood and instills a little bit of curiosity to begin coding.

Extra Sources:

  • Understanding JavaScript Fundamentals: Your Cheat Sheet
  • A Arms-On Introduction to Trendy JavaScript for SEOs
  • Superior Technical SEO: A Full Information

Picture Credit score

Featured picture created by writer, Could 2021





Courtesy:Source

#JavaScript #Automate #SEO #Scripts

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Openbrace

Chennai's Best Website Design & Development hub. We create Professional stunning WordPress websites and doing Digital Marketing to scale up your business.

Latest Articles

Happy to help you