Convert LD+JSON Schema to Javascript to use in Google Tag Manager

The Solution to the LD+JSON GTM “schema not showing” Problem

For those of us who were used to pasting LD+JSON schema into a script tag in Google Tag Manager, we awoke one day to find out that this approach no longer worked.  Regardless of the reason why, you can still add your schema markup to GTM, but you have to wrap in in a Javascript function.

Remember, once you have the function, you still have to add it to GTM as a custom html tag.

The video below details how you do it (it’s easy), and below that is the code for you to copy to use:

<script>
(function(){
var data ={

// INSERT LD+JSON MARKUP HERE

};
var script = document.createElement('script');
script.type = 'application/ld+json';
script.innerHTML = JSON.stringify( data );
document.getElementsByTagName('head')[0].appendChild(script);
})(document);
</script>

Hat-tip to @simoahava for his advice on the tag manager product forum!

Join “The Dental Web Development and SEO Group” on Facebook!

Use this group to ask your questions about dental web development, dental SEO, Google My Business, Google Maps, Google Analytics, etc. I will try to answer as many questions as possible, and it is my hope that members of the group will help each other out with questions, as well!