我正在尝试实施 amp-analytics - 没有 Google AMP 页面的供应商,用于网页浏览。我使用 URL 参数将指标发送到页面以定义我要跟踪的内容,并且此 URL 可以正常工作:
https://tru.am/page_views?clientID=1182&version=13&canonical=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&ogURL=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&referrer=TBA&title=test%20page%20for%20AMP%20analytics&image=http%3A%2F%2Fwww.trueanthem.com%2Fwp-content%2Fuploads%2F2016%2F03%2Fabout_bottom.jpg&callback=eqwest_1502748414821
我收到一条回复,说明数据已收集。
现在,当我在 Google AMP 页面中实现它时,当它调用我的 URL 并发送参数以收集数据时,我收到由 Google transport.js 库触发的错误代码 404,第 84 行。
transport.js:与问题相符的是:
const result = win.navigator.sendBeacon(request, '');
这是来自 transport.js 的上下文:
...
/**
* @param {!Window} win
* @param {string} request
* @return {boolean} True if this browser supports navigator.sendBeacon.
*/
static sendRequestUsingBeacon(win, request) {
if (!win.navigator.sendBeacon) {
return false;
}
const result = win.navigator.sendBeacon(request, '');
if (result) {
dev().fine(TAG_, 'Sent beacon request', request);
}
return result;
}
...
我正在使用的分析代码在 AMP 页面中是这样的:
<amp-analytics>
<script type="application/json">
{
"requests": {
"pageview": "https://tru.am/page_views?clientID=${clientId}&version=${version}&canonical=${canonical}&ogURL=${ogURL}&referrer=${referrer}&title=${title}&image=${image}&callback=${callback}"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview",
"vars": {
"eventId": "pageview",
"clientId": "1182",
"version" : "13",
"canonical": "https://s3.amazonaws.com/tru-am-dev/promote/test.amp.6.analytics.html",
"ogURL": "https://s3.amazonaws.com/tru-am-dev/promote/test.amp.6.analytics.html",
"referrer": "TBA",
"title": "test page for AMP analytics",
"image": "http://www.trueanthem.com/wp-content/uploads/2016/03/about_bottom.jpg",
"callback": "eqwest_1502748414821"
}
}
}
}
</script>
</amp-analytics>
我在页面中没有收到其他错误代码,并且#development=1
在 URL 中使用我AMP validation successful
在浏览器的控制台中收到消息。
404错误的详细信息:
Request URL:https://tru.am/page_views?clientID=1182&version=13&canonical=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&ogURL=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&referrer=TBA&title=test%20page%20for%20AMP%20analytics&image=http%3A%2F%2Fwww.trueanthem.com%2Fwp-content%2Fuploads%2F2016%2F03%2Fabout_bottom.jpg&callback=eqwest_1502748414821
Request Method:POST
Status Code:404
Remote Address:104.25.163.34:443
Referrer Policy:no-referrer-when-downgrade
那么,如果相同的 URL 在浏览器中有效但在 Google transport.js 库中失败(错误代码 404),为什么?