How to create a data-element based on JSON-ld data layer?
Hello all,
We are currently using JSON-LD Schema on one of our sites and I am looking to create a data element and not sure how to do the data mapping. I usually use the w3c standard but for this client they have Json-LD Schema implemented on the site.
For mapping i am use to using this format digitalData.page.pageinfo but not sure how to use the script objects in Json-ld.
e.g based on the below example how do i create a data element for @type: product or "sku" or event offers[array]
i am using var jsonld = JSON.parse(document.querySelector('script[type="application/ld+json"]').innerText); to display the script on the console (for testing purposes)
document.getElementsByTagName('script') also returns script object on the console but using document.getElementsByTagName('script').getAttribute('type'); or document.querySelector(jsonld["@type"]); returns null. so I need help in capturing these object in a data element.. i need something similar to digitalData.page.pageinfo.attribute to capture an element.
<script type="application/ld+json">{"@context": "http://schema.org","@type": "Product","sku": "305FS-UJNA5","offers": [{"@type": "Offer","price": "99.00","availability": "InStock","priceCurrency": "USD"}]}</script>