简体   繁体   中英

How to send google structured data via dom element?

I'm setting up google structured data via javscript, using dom element

like this

    function setStructuredDataGeneral() {
        structuredData = '{"@context": "https://schema.org/", "@type": "Product", "name": "Ofertas", "image": "<?php echo $wLanding->getFSlideImage(); ?>", "offers": { "@type": "AggregateOffer", "lowPrice": "'+Math.min(...offerPrices)+'", "highPrice": "'+Math.max(...offerPrices)+'", "priceCurrency": "EUR"}}';

        var elementScriptStructuredData = document.getElementById("structuredDataGeneral");
        var text = document.createTextNode(structuredData);
        elementScriptStructuredData.appendChild(text); 
    }

then I have a sctipt tag where it goes

<script type="application/ld+json" id="structuredDataGeneral">
</script> 

when I check the website it works, generate the expected results, problem is when I try to validate the URL via google structured data tool ( https://search.google.com/structured-data/testing-tool ) the tag is empty.

Its because this tool doesn't load javascript or I'm doing it wrong?

The Structured Data Testing Tool has very limited support for JavaScript. Use the Rich results Testing tool or the URL Inspector in the Google Search Console to make live tests that render JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM