4

我正在遵循https://developers.google.com/analytics/devguides/collection/amp-analytics/的简单指南

尝试添加 Pageviews GA 代码,但在控制台中遇到这两个错误:

amp-analytics-0.1.max.js:243 AmpAnalytics analytics1 Analytics config could not be parsed. Is it in a valid JSON format? SyntaxError: Unexpected token /

AmpAnalytics analytics1 No triggers were found in the config. No analytics data will be sent.

任何人都遇到过这些错误并且知道解决方法,我按照指示遵循了他们的文档,但仍然面临上述两个问题。

4

1 回答 1

10

我已经解决了,请确保您从示例代码中删除这些注释,这样就不会再出现错误了。

即,您从以下代码中删除注释,即删除“// 替换为您的属性 ID”。

and // 触发器名称可以是任何字符串。trackPageview 不是必需的名称。

<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
  "vars": {
    "account": "UA-XXXXX-Y"  // Replace with your property ID.
  },
  "triggers": {
    "trackPageview": {  // Trigger names can be any string. trackPageview is not a required name.
      "on": "visible",
      "request": "pageview"
    }
  }
}
</script>
</amp-analytics>

所以我会变成这样:

<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
  "vars": {
    "account": "UA-XXXXX-Y" 
  },
  "triggers": {
    "trackPageview": { 
      "on": "visible",
      "request": "pageview"
    }
  }
}
</script>
</amp-analytics>

于 2016-02-25T15:15:55.170 回答