Google跟踪代码管理器:在代码中发现未知变量

时间:2018-12-29 09:54:23

标签: javascript google-tag-manager schema.org json-ld

我正在尝试通过GTM在客户网站上集成Schema.org标记,我跟随this method from moz进行了JSON的位更改。

当我在GTM中单击预览时,出现以下错误消息:

  

在标记中找到未知变量'Schema-Article datePublished'。编辑标签并删除对未知变量的引用。

要做这项工作需要做什么?

<script>
  (function(){
    var data = {
        "@context": "http://schema.org",
        "@type": "NewsArticle",
        "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": "eltawkeel.com",
            "logo" : {
                "@type": "ImageObject",
                "url": "https://eltawkeel.com/images/logo.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>

0 个答案:

没有答案