针对AMP的Google anaytics - 社交变量

时间:2017-08-23 17:39:53

标签: google-analytics amp-html

如何向AMP analytics json属性添加多个社交值。

"vars": {
          "socialNetwork": "twitter",
          "socialAction": "tweet",
          "socialTarget": "https://www.examplepetstore.com",
          "socialNetwork": "facebook",
          "socialAction": "share"
      }

这就是我想到的,但我认为这是不正确的。 非常感谢!

1 个答案:

答案 0 :(得分:1)

你可以这样做:

ADD JS

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

跟踪Twitter和Facebook的代码

<amp-analytics type="googleanalytics">
<script type="application/json">
{
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackClickOnTwitterLink" : {
      "on": "click",
      "selector": "#tweet-link",
      "request": "social",
      "vars": {
          "socialNetwork": "twitter",
          "socialAction": "tweet",
          "socialTarget": "https://www.examplepetstore.com"
      }
    },
    "trackClickOnFacebookLink" : {
      "on": "click",
      "selector": "#facebook-link",
      "request": "social",
      "vars": {
          "socialNetwork": "facebook",
          "socialAction": "facebook",
          "socialTarget": "https://www.examplepetstore.com"
      }
    }

  }
}
</script>
</amp-analytics>