1
我正在尝试使用此library来实现跟踪像素。无法将跟踪像素发送数据到api
我在使用Apache的localhost机器上测试。
我在的htdocs/openpixel /一个index.html页面的index.html
具有以下内容:
<html>
<head>
Test Pixel
</head>
<body>
Test Pixel
<!-- Start Open Pixel Snippet -->
<script>
!function(e,t,n,p,o,i,a,s,c){e[o]||(a=e[o]=function(){a.process?a.process.apply(a,arguments):a.queue.push(arguments)},a.queue=[],a.t=1*new Date,s=t.createElement(n),s.async=1,s.src=p+"?t="+Math.ceil(new Date/i)*i,c=t.getElementsByTagName(n)[0],c.parentNode.insertBefore(s,c))}(window,document,"script","http://127.0.0.1/openpixel/v1/openpixel.js","opix",864e5),opix("init","ID-123"),opix("event","pageload");
</script>
<!-- End Open Pixel Snippet -->
</body>
</html>
这是openpixel.js,它应该将数据发送到端点
...
window.onload = function() {
var aTags = document.getElementsByTagName('a');
for (var i = 0, l = aTags.length; i < l; i++) {
aTags[i].onclick = function (e) {
if (Url.externalHost(this)) {
Config.externalHost = { link: this.href, time: now() };
}
}.bind(aTags[i]);
}
};
}(window, document, window["opix"], "opix", "http://localhost:3000/pixel_data", 1));
...
我还在Node.JS中创建了一个端点api来接收这个像素。当我用浏览器测试它时,它正在响应。
app.get('/pixel_data', function(req, res) {
console.log(req.query);
});
问题是当我访问pixel.html时,endpoint/pixel_data没有记录任何东西。我试图在这里了解问题。
使用Chrome开发工具,网络选项卡是否显示带查询字符串的请求? –
是的,在源代码 - > openpixel - > v1我看到这个:http://127.0.0.1/openpixel/v1/openpixel.js?t=1488326400000 –
我仍然没有获得节点中的数据 –