2

我有一个 amp 故事,我还使用 Google Analytics 实现了跟踪。诸如故事页面可见之类的事件运行良好。但是,当我尝试在故事页面内的锚标记上跟踪点击事件时,它不起作用。这些是我的触发器和锚标记:

更新代码

 <amp-analytics type="gtag" data-credentials="include">
        <script type="application/json">
        {
          "vars": {
            "gtag_id": "UA-YYYY-Y",
            "event_category": "<%= storyName %>",
            "config": {
              "UA-YYYY-Y": {
                "groups": "default"
              }
            }
          },
          "extraUrlParams": {
            "cd75": "AMP",
            "cd69": "AMP",
            "cd81": "marketplace",
            "cd76": "${ampdocHostname}"
          },
          "triggers": {
            "linkClick" : {
              "on": "click",
              "selector": "a",
              "request": "event",
              "vars": {
                "eventCategory" : "click"
              }
            }
          }
        }
      </script>
    </amp-analytics>
 <a href="https://amp.dev/" >
                <p>click here to read more</p>
            </a>

单击锚标记或单击工具提示不会触发任何事件。任何建议都会非常有帮助。

4

2 回答 2

2

我试过你的例子,它似乎工作。我发布了我使用的完整配置,以便您可以与您的进行比较。另外,您是否在文档开头添加了 amp-analytics 脚本?

<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>

--

<amp-analytics type="googleanalytics">
<script type="application/json">
{
  "vars": {
    "account": "UA-YYYY-Y"
  },
  "triggers": {
    "default click": {
      "on": "click",
      "selector": "a",
      "request": "event",
      "vars": {
        "eventCategory": "amp click"
      }
    }
  }
}
</script>
</amp-analytics>

在这里你有一个错字并忘记关闭</p>标签,但它应该仍然可以工作。

<a href="https://amp.dev/" >
  <p>click here to read more</p>
</a>
于 2019-08-27T18:14:48.980 回答
0

我遇到了同样的问题,在触发器中添加event_name解决了这个问题

   <amp-analytics type="gtag" data-credentials="include">
    <script type="application/json">
    {
      "vars": {
        "gtag_id": "UA-YYYY-Y",
        "event_category": "<%= storyName %>",
        "config": {
          "UA-YYYY-Y": {
            "groups": "default"
          }
        }
      },
      "extraUrlParams": {
        "cd75": "AMP",
        "cd69": "AMP",
        "cd81": "marketplace",
        "cd76": "${ampdocHostname}"
      },
      "triggers": {
        "linkClick" : {
          "on": "click",
          "selector": "a",
          "request": "event",
          "vars": {
            "event_name" : "login",
            "eventCategory" : "click"
          }
        }
      }
    }
  </script>
</amp-analytics>
于 2020-01-14T11:10:55.193 回答