AMP分析 - 如何跟踪"点击"并且"可见"放大器列表中的元素

时间:2017-11-30 15:14:31

标签: amp-html

我知道如何在amp-analytics标记内设置基本点击跟踪。但是,是否可以在<amp-list>

内的动态项目上绑定点击跟踪
<amp-analytics type="googleanalytics">
<script type="application/json">
{
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackClickOnMyDynamicItem" : {
      "on": "click",
      "selector": "#myElementInAmpList",
      "request": "event",
      "vars": {
        "eventCategory": "someCategory",
        "eventAction": "someAction",
        "eventLabel": "someDynamicLabelRetrievedFromAmpList"
      }
    }
  }
}
</script>
</amp-analytics>

1 个答案:

答案 0 :(得分:0)

你可以使用data-vars- *来做到这一点 例如:

<amp-list>
<template type="amp-mustache">
<a href="{{ Url }}" id="myElementInAmpList"  data-vars-product-name ="{{ ProductName }}">
</template>
</amp-list>

在跟踪脚本中,您可以:

<amp-analytics type="googleanalytics">
<script type="application/json"> {"vars": {
"account": "UA-XXXXX-Y"},
"triggers": {
 "trackClickOnMyDynamicItem" : {
  "on": "click",
  "selector": "#myElementInAmpList",
  "request": "event",
  "vars": {"eventCategory": "someCategory",
    "eventAction": "someAction",
    "eventLabel": "${productName}" //this will be dynamic 
         }
       }
     }
   }
</script>
</amp-analytics>

refer the documentation here in the last part of the page