0

我想使用 sendBeacon API (transport "beacon": true) 将分析数据发送到自定义 URL。查询字符串中编码的有效负载运行良好,但我想将其放入 POST 正文中。

我尝试了PR #1162中建议的配置,但后来我意识到它没有合并到amp-analytics中。有没有办法在当前实现中配置它?

4

1 回答 1

1

尝试添加

"transport": {
  "beacon": true,
  "xhrpost": false,
  "image": false
}

到你的代码。

一个完整的示例如下所示:

<amp-analytics>
<script type="application/json">
{
  "requests": {
    "pageview": "https://example.com/analytics?url=${canonicalUrl}&title=${title}&acct=${account}",
    "event": "https://example.com/analytics?eid=${eventId}&elab=${eventLabel}&acct=${account}"
  },
  "vars": {
    "account": "ABC123"
  },
  "triggers": {
    "trackPageview": {
      "on": "visible",
      "request": "pageview"
    },
    "trackAnchorClicks": {
      "on": "click",
      "selector": "a",
      "request": "event",
      "vars": {
        "eventId": "42",
        "eventLabel": "clicked on a link"
      }
    }
  },
  "transport": {
    "beacon": true,
    "xhrpost": false,
    "image": false
  }
}
</script>
</amp-analytics>

于 2016-04-26T00:39:35.940 回答