我正在尝试使用simple在节点下发布到Google Analytics
http
请求如下:
var http = require("http");
var post_options = ({
host: "www.google-analytics.com",
path: "/collect",
body: "ec=a&ea=bb&ev=1&cid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&v=1&tid=UA-123456789-0&t=event",
method: "POST",
headers: {}
});
http.request(post_options, function (res) {
console.log(res);
}).end();
但这从来没有到达谷歌分析服务器,我在那里的统计数据中看不到它。使用
https
这样也不行:
var http = require("http");
var post_options = ({
hostname: "www.google-analytics.com",
port: 443,
path: "/collect",
body: "ec=a&ea=bb&ev=1&cid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&v=1&tid=UA-123456789-0&t=event",
method: "POST",
headers: {}
});
https.request(post_options, function (res) {
console.log(res);
}).end();
如果我用
request
模块,如下所示:
var request = require("request");
var path = "https://www.google-analytics.com/collect";
var options = { "body": "ec=a&ea=bb&ev=1&cid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&v=1&tid=UA-123456789-0&t=event", "headers": {} }
request.post(path, options, (err, httpResponse, body) => {
console.log(httpResponse);
});
它立即显示在谷歌分析服务器上。你知道我的第一种方法有什么问题吗?