Overview
The snippet below grabs the JSON-LD content on a webpage to help you determine if it can be read well by search engines. The object (JavaScript Object Notation for Linked Data) is populated with descriptive data about the web page in a format the search engines can understand and use. This is one of the more advanced SEO practices and its format in addition to its presence is important. There are specific formatting requirements. This is often not included in a basic SEO reporting tool but it is extremely important to SEO marketers who want to raise the relevancy of their pages.
Under Variable Summary in ObservePoint data, select the Json-ld account to see the relevant variables.
To capture the following details in an Audit or 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 jsonLDs = document.querySelectorAll("script[type*='json'][type*='ld']")
for (i = 0; i < jsonLDs.length; i++) {
var data = jsonLDs[i].innerHTML;
var object = JSON.parse(data);
opReqGetAsync(object, "Json-ld");
}