Skip to content

Instantly share code, notes, and snippets.

@twkm
Last active August 9, 2016 17:05
Show Gist options
  • Save twkm/b123b9246de9c8f95ee778fb090da978 to your computer and use it in GitHub Desktop.
Save twkm/b123b9246de9c8f95ee778fb090da978 to your computer and use it in GitHub Desktop.
Quick reference for inserting JSON-LD in a page to use for Schema.org purposes within Google Tag Manager.

Schema.org JSON-LD in Google Tag Manager

Quick reference for inserting JSON-LD in a page to use for Schema.org purposes within Google Tag Manager.

From this excellent Moz post.

<script>
    (function()
    {
        var data = {
            "@context": "http://schema.org",
            "@type":    "LocalBusiness",
            "name":     "",
            "url":      "",
            "logo":     "",
            "address":  {
                "@type": "PostalAddress",
                "streetAddress":    "123 Main Street",
                "addressLocality":  "Sometown",
                "addressRegion":    "AB",
                "addressCountry":   "Canada",
                "postalCode":       "T1T 1T1"                
            },
            "email": "", 
            "telephone": "",
            "telephone": "", 
            "faxNumber": "",
            "sameAs":   [
                "https://www.linkedin.com/company/111111",
                "<Facebook Page URL>",
                "<Twitter Profile URL",
            ]
        }
        var script = document.createElement('script');
        script.type = "application/ld+json";
        script.innerHTML = JSON.stringify(data);
        document.getElementsByTagName('head')[0].appendChild(script);
    }
    )(document);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment