Skip to content

Instantly share code, notes, and snippets.

@chrisgoddard
Last active July 23, 2023 16:52
Show Gist options
  • Save chrisgoddard/bbc998efc270929d0a67305d0941c6eb to your computer and use it in GitHub Desktop.
Save chrisgoddard/bbc998efc270929d0a67305d0941c6eb to your computer and use it in GitHub Desktop.
JSON-LD GTM Tag
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{SCHEMA - Article Headline}},
"image": {
"@type": "ImageObject",
"url": {{SCHEMA - Article Image}},
"height": 413,
"width": 1159
},
"datePublished": {{SCHEMA - Article datePublished}},
"author": {
"@type": "Person",
"name": {{SCHEMA - Author Name}}
},
"publisher": {
"@type": "Organization",
"name": "SERPs.com",
"logo" : {
"@type": "ImageObject",
"url": "https://serps.com/app/uploads/2016/05/serps-logo-60.png",
"height": 60,
"width": 300
}
},
"description": {{SCHEMA - Article Description}}
}
var dateModified = {{SCHEMA - Article dateModified}};
if(dateModified){
data.dateModified = dateModified;
} else {
data.dateModified = {{SCHEMA - Article datePublished}};
}
var script = document.createElement('script');
script.type = "application/ld+json";
script.innerHTML = JSON.stringify(data);
document.getElementsByTagName('head')[0].appendChild(script);
})(document);
</script>
@marekcech
Copy link

really useful, thank you very much for sharing this script and idea

@cacarrilloc
Copy link

cacarrilloc commented May 4, 2018

Thanks man! This is perfect for a junior SEO analyst like me!

@caokytung
Copy link

Thank man! Great code <3

@kmhrussell17
Copy link

Perfect!

@jerinisready
Copy link

+1 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment