简体   繁体   English

如何通过dom元素发送Google结构化数据?

[英]How to send google structured data via dom element?

I'm setting up google structured data via javscript, using dom element 我正在使用dom元素通过javscript设置Google结构化数据

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 然后我有一个sctipt标签

<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. 当我检查网站正常运行时,会产生预期的结果,问题是当我尝试通过google结构化数据工具( https://search.google.com/structured-data/testing-tool )验证网址时,标记为空。

Its because this tool doesn't load javascript or I'm doing it wrong? 是因为此工具无法加载javascript还是我做错了?

The Structured Data Testing Tool has very limited support for JavaScript. 结构化数据测试工具对JavaScript的支持非常有限。 Use the Rich results Testing tool or the URL Inspector in the Google Search Console to make live tests that render JavaScript. 使用Rich results Testing工具或Google Search Console中的URL Inspector进行实时测试以呈现JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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