Skip to main content

Technical SEO Implementation: Set up the SEO check script

Add one on-page action to your Audit to check the SEO tags on every page, such as titles, meta descriptions, canonical URLs, and structured data.

Written by Luiza Gircoveanu

Overview

Several checks in the Technical SEO Framework look at tags in a page's HTML that ObservePoint doesn't report on by default, such as the meta description or canonical URL.

This script checks all of them at once. It runs on every page in your Audit and writes a short message to the browser console for each issue it finds. You then review those messages in the Browser Logs report.

Why It Is Important

Using one script keeps your setup simple: you configure it once, and every SEO check that depends on page tags is covered. Because the results are console messages, you can filter and export them like any other Audit data.

Implementation

  1. Open the Audit you use for Technical SEO and go to its On-Page Actions.

  2. Add an Execute JavaScript action and paste in the script below.

  3. Run the Audit.

  4. Create a Browser Logs report and filter Log Message that contains OP-SEO.

Reuse the script with an Action Set (optional)

If you run Technical SEO checks in more than one Audit, save the script as an Action Set so you only maintain it in one place.

  1. In the Audit's On-Page Actions, click Create Action Set.

  2. Select the Execute JavaScript action and click Save as New Action Set.

  3. In other Audits, add an action with the type Action Set and select it.

Any change you make to the Action Set applies to every Audit that uses it.

(function () {
var PREFIX = 'OP-SEO | ';
function log(check, result, detail) {
console.log(PREFIX + check + ' | ' + result + (detail ? ' | ' + detail : ''));
}
log('Script', 'RAN', location.href);

// Page title
var title = (document.title || '').trim();
if (!title) log('Title', 'FAIL', 'Missing or empty');
else if (title.length < 10 || title.length > 65) log('Title', 'WARN', title.length + ' characters');

// Meta description
var desc = document.querySelector('meta[name="description" i]');
var descText = desc ? (desc.getAttribute('content') || '').trim() : '';
if (!descText) log('Meta Description', 'FAIL', 'Missing or empty');
else if (descText.length > 155) log('Meta Description', 'WARN', descText.length + ' characters');

// Mobile viewport
var vp = document.querySelector('meta[name="viewport" i]');
if (!vp || !(vp.getAttribute('content') || '').trim()) log('Viewport', 'FAIL', 'Missing or empty');

// H1 heading
if (!document.querySelector('h1')) log('H1', 'FAIL', 'Missing');

// Social title tags (Open Graph or Twitter)
var socialTags = document.querySelectorAll('meta[property="og:title" i], meta[name="twitter:title" i], meta[property="twitter:title" i]');
var hasSocial = false;
for (var s = 0; s < socialTags.length; s++) {
if ((socialTags[s].getAttribute('content') || '').trim()) hasSocial = true;
}
if (!hasSocial) log('Social Title', 'WARN', 'No og:title or twitter:title');

// Word count (visible text only, for reference)
var bodyText = document.body ? (document.body.innerText || '') : '';
var words = bodyText.split(/\s+/).filter(Boolean).length;
log('Word Count', 'INFO', words + ' words');

// URL structure (path only, query string and hash are ignored)
var path = location.pathname;
try { path = decodeURIComponent(path); } catch (e) {}
var urlIssues = [];
if (path !== path.toLowerCase()) urlIssues.push('uppercase letters');
if (/\s/.test(path)) urlIssues.push('spaces');
if (path.indexOf('_') > -1) urlIssues.push('underscores');
var baseUrl = location.origin + location.pathname;
if (baseUrl.length >= 100) urlIssues.push(baseUrl.length + ' characters');
if (urlIssues.length) log('URL Structure', 'WARN', urlIssues.join(', '));

// Robots meta tags
var robots = document.querySelectorAll('meta[name="robots" i], meta[name="googlebot" i]');
for (var r = 0; r < robots.length; r++) {
var rc = (robots[r].getAttribute('content') || '').toLowerCase();
if (rc.indexOf('noindex') > -1 || rc.indexOf('none') > -1) log('Robots', 'NOINDEX', 'meta ' + robots[r].getAttribute('name') + '="' + rc + '"');
}

// Structured data (JSON-LD)
var ld = document.querySelectorAll('script[type="application/ld+json" i]');
if (!ld.length) log('JSON-LD', 'NONE', 'No JSON-LD found');
for (var j = 0; j < ld.length; j++) {
try {
var data = JSON.parse(ld[j].textContent);
var items = Array.isArray(data) ? data : (data['@graph'] || [data]);
var types = items.map(function (i) { return i && i['@type']; }).filter(Boolean).join(', ');
log('JSON-LD', 'FOUND', types || 'No @type');
} catch (e) {
log('JSON-LD', 'FAIL', 'Invalid JSON');
}
}

// URL checks: canonical, hreflang, X-Robots-Tag header
function checkUrl(check, url) {
var abs;
try { abs = new URL(url, location.href); } catch (e) { log(check, 'FAIL', 'Invalid URL: ' + url); return; }
if (abs.origin !== location.origin) { log(check, 'SKIPPED', 'Other domain: ' + abs.href); return; }
fetch(abs.href, { method: 'GET', redirect: 'follow', credentials: 'same-origin' })
.then(function (res) {
if (!res.ok) log(check, 'FAIL', res.status + ' ' + abs.href);
else if (res.redirected) log(check, 'WARN', 'Redirects to ' + res.url);
})
.catch(function () { log(check, 'FAIL', 'Request failed ' + abs.href); });
}
var canon = document.querySelectorAll('link[rel="canonical" i]');
if (!canon.length) log('Canonical', 'WARN', 'Missing');
if (canon.length > 1) log('Canonical', 'FAIL', canon.length + ' canonical tags');
if (canon.length) checkUrl('Canonical', canon[0].getAttribute('href'));
var alt = document.querySelectorAll('link[rel="alternate" i][hreflang]');
for (var h = 0; h < alt.length; h++) checkUrl('Hreflang', alt[h].getAttribute('href'));

fetch(location.href, { method: 'GET', credentials: 'same-origin' }).then(function (res) {
var xr = (res.headers.get('x-robots-tag') || '').toLowerCase();
if (xr.indexOf('noindex') > -1 || xr.indexOf('none') > -1) log('Robots', 'NOINDEX', 'X-Robots-Tag header "' + xr + '"');
}).catch(function () {});
})();

Reading the results

Every message starts with OP-SEO, followed by the check name and the result:

Message example

Meaning

OP-SEO | Script | RAN | <page URL>

The script ran on this page. Pages with no FAIL or WARN messages passed every check.

OP-SEO | Title | FAIL | Missing or empty

The page has no title.

OP-SEO | Title | WARN | 72 characters

The title is shorter than 10 or longer than 65 characters.

OP-SEO | Meta Description | FAIL | Missing or empty

The page has no meta description.

OP-SEO | Meta Description | WARN | 180 characters

The description is longer than 155 characters.

OP-SEO | H1 | FAIL | Missing

The page has no H1 heading.

OP-SEO | Social Title | WARN | No og:title or twitter:title

The page has no title for social sharing.

OP-SEO | URL Structure | WARN | uppercase letters, underscores

The URL has uppercase letters, spaces, or underscores, or is 100 characters or longer.

OP-SEO | Word Count | INFO | 1834 words

The number of words of visible text on the page.

OP-SEO | Canonical | WARN | Missing

The page has no canonical tag.

OP-SEO | Canonical | FAIL | 404 <URL>

The canonical URL is broken.

OP-SEO | Canonical | FAIL | 2 canonical tags

The page has more than one canonical tag.

OP-SEO | Canonical | WARN | Redirects to <URL>

The canonical URL redirects instead of loading directly.

OP-SEO | Hreflang | FAIL | 404 <URL>

An hreflang URL is broken.

OP-SEO | Hreflang | WARN | Redirects to <URL>

An hreflang URL redirects instead of loading directly.

OP-SEO | Canonical | SKIPPED | Other domain: <URL>

The canonical or hreflang URL is on another domain and wasn't tested.

OP-SEO | Robots | NOINDEX | ...

The page asks search engines not to index it, through a robots meta tag or X-Robots-Tag header.

OP-SEO | Viewport | FAIL | Missing or empty

The page has no mobile viewport tag.

OP-SEO | JSON-LD | FOUND | Product

Structured data was found, with its type.

OP-SEO | JSON-LD | NONE

No structured data was found.

OP-SEO | JSON-LD | FAIL | Invalid JSON

Structured data exists but can't be read.

A few things to keep in mind:

  • The script only tests canonical and hreflang URLs on the same domain as the page. URLs on other domains are listed as SKIPPED so you can review them separately. Multi-region sites often use separate domains for each language (such as example.de and example.fr), so expect more SKIPPED messages there.

  • The word count includes all visible text, such as menus and footers, and can't count words in languages that don't use spaces, such as Japanese or Chinese. Use it as a guide, not an exact number.

  • To fix the issues the script finds, see the guide for each check in the Technical SEO Framework.

Conclusion

With the script in place, every Audit run checks these SEO tags on each page automatically, so you can find and fix issues without any extra setup.

Did this answer your question?