将 Google 标签管理器与 DNN 结合使用时,结构化数据测试工具无法检测到架构代码

Schema Code cant be detected with Structure Data Testing Tool when using Google Tag Manager with DNN

我已经创建了一个 JSON-LD 网站架构,并试图将此代码添加到 Google 标签管理器的自定义 HTML 容器中。

我已经为综合浏览量设置了一个触发器,并将其更改为 DOM 准备好在测试预览模式时查看它是否有所不同。

每次更改触发器后,我都会继续发布更改。我确实启用了支持 Document.write.

的选项

问题是,当我使用结构化数据测试工具测试网站时,它没有接收到它。

我已将此代码移至 DNN 中的页眉本身,它现在可以拾取它。

DNN 是否会做一些事情来阻止 Google 标签管理器触发代码?它可能是触发设置或它加载它的顺序。

<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "WebSite",
  "name": "Our Company Name",
  "alternateName": "Other name",
  "url": "https://www.google.co.za",
  "potentialAction": {
  "@type": "SearchAction",
   "target": "https://www.google/Search-Result/search/{search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WholesaleStore",
"name": "Our Company Name",
"image": "www.http://ourcompany.com/",
"@id": "",
"url": "http://ourcompany.com/",
"telephone": "0000000",
"priceRange": "0",
"address": {
"@type": "PostalAddress",
"streetAddress": "",
"addressLocality": "",
"postalCode": "",
"addressCountry": "ZA"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 0,
"longitude": 0
},
"openingHoursSpecification": {
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday"
],
"opens": "08:00",
"closes": "17:00"
},
"sameAs": [
  "https://www.facebook.com/"      
 ]
 }
</script>

尝试将 GTM 中 HTML 标记中的所有架构替换为如下内容:

<script>
  // Your regular schema data
  var jsonData = {
    "@context": "http://schema.org/",
    "@type": "WebSite",
    "name": "Our Company Name",
    "alternateName": "Other name",
    "url": "https://www.google.co.za",
    "potentialAction": {
      "@type": "SearchAction",
      "target": "https://www.google/Search-Result/search/{search_term_string}",
      "query-input": "required name=search_term_string"
    }
  };
  // And then you append it to the head
  var script = document.createElement('script');
  script.type = "application/ld+json";
  script.innerHTML = JSON.stringify(data);
  document.head.appendChild(script);
</script>

结构化数据测试工具不再识别 <script type="application/ld+json">... 注入方式,现在必须通过 JS 以编程方式注入。

来源:1, 2