Basic SEO Data

Many pieces of information can be captured from web pages to help with SEO analysis. Using the OP Custom Tag snippet below in an audit produces the following list of variables in the Variable Summary report:

  • Canonical_URL: Shows the server response for the canonical URL for the page. The page fails if the server does not return a 200 code for the canonical URL.
  • h1: Fails if the H1 tag is missing or empty on the page. Indicates if there is more than one.
  • h2-h6: Detects the text of any H2-H6 tags on the page. Displays "0 tags found" message if the page is missing any of these tags or the tag is empty.
  • Hidden_Content: Invisible and/or JavaScript loaded content found on the page. Includes content served after the page has loaded or content that is hidden with display:none style.
  • Hreflang_URL: Fails if the URL in an hreflang tag does not resolve to a 200 status code.
  • Image_Alt: Shows the number of images on a page where the image tags are missing the alt attribute.
  • Image_Width: Shows the number of images on the page missing the width attribute.
  • Meta_Description: Shows the length of the meta description tag and notes those that exceed 155 characters. Fails if the description is less than 155 characters, missing or empty.
  • Meta_Viewport: Fails if a page does not have a viewport meta tag or it is empty.
  • Page_Size: Shows the page size in kilobytes. Fails if the page is larger than 500kb.
  • Page_Title: Shows the size of the page's Title tag in characters. Fails if it is less than 10 characters, greater than 65 characters, missing or empty.
  • Page title too short: Shows the length of the page's Title tag in kilobytes.
  • Word_Quantity: Shows the number of words on the pages. Fails if there are fewer than 500 words.
  • Robots.txt: Indicates the presence of a lack of a robots.txt file.
  • Maximum number of H1 tags: More than one h1 tag found on the page
  • Too few words per page (<500 words): Page contains less than 500 words rendered with page load (content served post-load or in JavaScript should not be included)
  • Image size not specified: Image does not contain size attributes for faster rendering

To capture these details in an audit or web journey, paste the snippet below into an Execute Action:

function opReqGetAsync(paramObject, acct, callback) {
var baseURL = "https://opreq.observepoint.com/?acct=" + acct;
var opReq = new XMLHttpRequest();
opReq.onreadystatechange = function() {
if (opReq.readyState == 4 && opReq.status == 200){
callback(opReq.responseText);
}
}
opReq.open("POST", baseURL, true);
opReq.send(JSON.stringify(paramObject));
}
var object=new Object,images=document.querySelectorAll("img"),missing=0,noWidth=0;for(i=0;i<images.length;i++)""!=images[i].getAttribute("alt")&&images[i].getAttribute("alt")||missing++,images[i].getAttribute("width")&&images[i].getAttribute("height")||noWidth++;noWidth>0?object.Image_Width=noWidth+" of "+images.length+" missing":object.Image_Width="Passed",missing>0?object.Image_Alt=missing+" of "+images.length+" missing":object.Image_Alt="Passed";var failed=0;getStatus=function(e,t,a){try{var n=new XMLHttpRequest;n.onreadystatechange=function(){4==n.readyState&&200==n.status?runAfter(n.status,t):4==n.readyState&&0==n.status&&runAfter(n.responseText,t)},n.open("GET",e),n.send(),0==n.status&&4==n.readyState&&runAfter(n.status,t)}catch(o){failed++}};var badstatus=0,goodstatus=0,total=0;runAfter=function(e,t){"200"!=e?(badstatus++,object.Hreflang_URL=goodstatus+" Passed. "+badstatus+" Bad status. "+failed+" Failed"):"Canonical_URL"==t&&"200"==e?object[t]="Passed Status-"+e:(goodstatus++,object.Hreflang_URL=goodstatus+" Passed. "+badstatus+" Bad status. "+failed+" Failed"),total=goodstatus+badstatus+failed,total==i&&opReqGetAsync(object,"SEO")};var canonical=document.querySelector("link[rel='canonical']"),hreflang=document.querySelectorAll("link[rel='alternate']");for(canonical&&""!=canonical?(canonical=canonical.getAttribute("href"),getStatus(canonical,"Canonical_URL")):object.Canonical_URL="None Specified",hreflang[0]&&""!=hreflang[0]||(object.Hreflang_URL="No URLs Specified"),i=0;i<hreflang.length;i++){var hrefLangURL=hreflang[i].getAttribute("href");getStatus(hrefLangURL,"Hreflang_URL")}var DTL=document.title.length;document.title|""==document.title?object.Page_Title="Missing or Empty":10>DTL?object.Page_Title="<10":DTL>65?object.Page_Title=">65":object.Page_Title=DTL+" Passed";var metaD=document.querySelector("meta[name='description']");metaD&&""!=metaD?metaD.getAttribute("content").length>155?object.Meta_Description=">155 chars":object.Meta_Description=metaD.getAttribute("content").length+" chars Passed":object.Meta_Description="Missing or Empty";var metaView2=document.querySelector("meta[name='viewport']");if(metaView2)var metaView=metaView2.getAttribute("content");var metaFunc=document.querySelectorAll("script:not([type]):not([src])");for(j=0;j<metaFunc.length;j++){var metaFuncJS=metaFunc[j].innerHTML.indexOf("iewport"),metaJSFound=0;-1!=metaFuncJS&&metaJSFound++}metaView||0!=metaJSFound?object.Meta_Viewport="Passed":object.Meta_Viewport="JS & HTML Missing or Empty";var h1=document.querySelectorAll("h1");h1.length>1?object.h1=h1.length+" h1's":h1&&0!=h1.length?object.h1="Passed":object.h1="Missing or Empty";var h2=document.querySelectorAll("h2");0==h2.length?object.h2="h2 missing":object.h2="Passed";var words=document.body.innerText.split(/\s/).filter(function(e){return/\S/.test(e)}).length;500>words?object.Word_Quantity="<500 Words":words&&(object.Word_Quantity=words+" Passed");var hidden=document.querySelectorAll("[display='none']");hidden.length>0?object.Hidden_Content=hidden.length+" Hidden":0==hidden.length&&(object.Hidden_Content="Passed");var pagebytes=document.documentElement.innerHTML.length,kbytes=Math.round(pagebytes/1024);kbytes>500?object.Page_Size="Failed "+kbytes+" kb":object.Page_Size="Passed "+kbytes+" kb",hreflang[0]||canonical||opReqGetAsync(object,"SEO");
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.