2017-02-28 55 views
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沒有記錄任何東西。我試圖在這裏瞭解問題。

+0

使用Chrome開發工具,網絡選項卡是否顯示帶查詢字符串的請求? –

+0

是的,在源代碼 - > openpixel - > v1我看到這個:http://127.0.0.1/openpixel/v1/openpixel.js?t=1488326400000 –

+0

我仍然沒有獲得節點中的數據 –

回答

2

您是Node.js服務器無法看到查詢字符串,因爲它看起來像您的服務器在localhost:3000上,並且您正在向127.0.0.1/openpixel/v1/openpixel.js發送請求。

將像素標籤更改爲localhost:3000http://127.0.0.1/openpixel/v1/openpixel.js更改爲http://localhost:3000/pixel_data