无法跟踪像素发送数据到API

我试图使用这个库来实现一个跟踪像素。

我正在使用Apache在本地主机上进行testing。

我在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=[],at=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中创build了一个端点api来接收这个像素。 当我使用浏览器testing它时,它正在响应。

 app.get('/pixel_data', function(req, res) { console.log(req.query); }); 

问题是当我访问pixel.html时,endpoint / pixel_data没有logging任何东西。 我想在这里理解这个问题。

你是Node.js服务器无法看到查询string,因为它看起来像你的服务器是在localhost:3000 ,你正在发送一个请求到127.0.0.1/openpixel/v1/openpixel.js

通过将http://127.0.0.1/openpixel/v1/openpixel.js更改为http://localhost:3000/pixel_data ,将您的像素标记更改为请求localhost:3000