Reputation: 31
Good day, I really need someone's help, please. I am trying to dynamically generate schema for the news article section. When I test it using the rich results tool, everything looks fine, but google console returns the following error: 'unparsable structured data'. I presume I have to wrap the code up in JS, but I am not very strong in this, will appreciate your help, please. Thanks very much for looking into this for me.
The screenshot of the jsonld script
Upvotes: 3
Views: 1150
Reputation: 3409
Both the Rich Results Test tool and the Search Console Test render before testing, so there could still be an issue in how the json-ld is being added to the page.
The tools normally pinpoint to the place where a syntax error like this happens.
One possible issue is if the dynamic content (e.g UA-CJS-Schema-Meta-Description) contains double quotes or a closing script tag. I'm not sure how GTM escapes this content but if it does not, they can cause invalid json.
Upvotes: 0
Reputation: 8111
In short: you're most likely good. The error you're seeing is just due to the fact that Google testing tool fetches source and doesn't render DOM. Google Bot will render it properly, so no issues there.
You certainly don't need a JS wrapper, though you can use it. I used it with schema when I didn't want to inflate the size of it with variables. Here is a quick example:
var script = document.createElement('script');
script.type = "application/ld+json";
script.innerHTML = JSON.stringify(data);
document.getElementsByTagName('head')[0].appendChild(script);
Where Data is your JS object representing the schema json.
Your error is most likely due to Google Fetching the code rather than rendering the page and letting JS populate the DOM.
Deployment of Schema with GTM, though convenient, leads to issues in Future. It should be considered as a temporary solution contributing to the technical debt.
I just tested your code and it looks fine.
Here is the code for those who want it:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "NewsArticle",
"mainEntityofPage": {
"@type": "WebPage",
"id": "{{Page URL}}"
},
"headline": "{{UA-CJS-Schema-Heading}}",
"description": "{{UA-CJS-Schema-Meta-Description}}",
"image": "{{UA-CJS-BlogImageURL}}",
"author": {
"@type": "Organization",
"name": "Association for Project Management"
},
"publisher": {
"@type": "Organization",
"name": "Association for Project Management",
"logo": {
"@type": "ImageObject",
"url": "https://www.apm.org.uk/"
}
},
"datePublished": "{{UA-CJS-Schema-Date Published-Edited}}",
"dateModified": "{{UA-CJS-Schema-DatePublished-Edited}}"
}
</script>
I will add some debugging steps, but you don't really need them since you used a different service and it confirmed that the schema is there. But just in case.
Debugging steps:
Upvotes: 2