我正在遵循https://developers.google.com/analytics/devguides/collection/amp-analytics/
的简单指南尝试添加网页浏览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.
任何人都遇到过这些错误并知道修复,我按照指示跟踪了他们的文档,但仍面临两个问题。
答案 0 :(得分:7)
我已经解决了,请确保从示例代码中删除这些注释,错误将不复存在。
即。您从以下代码中删除评论,即删除" //替换为您的媒体资源。"
和//触发器名称可以是任何字符串。 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>
&#13;
所以我会成为这个:
<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
"vars": {
"account": "UA-XXXXX-Y"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
}
}
}
</script>
</amp-analytics>
&#13;