I tried to implementing google analytics API in a node-webkit application with Analytics Measurement Protocol, I managed to do that with ga-dev-tools.appspot.com but I can't use it with a simple javascript request. I suppose the problem was the header parameter "Origin" (in a node-webkit app is "file://"), therefore I tried to use a http request with node but I reached the same result: google respond with "hitParsingResult": [ {"valid": true,...
however in Google Analytics Dashboard ? can't see the event or, in this case, a pageview.
我尝试在带有分析测量协议的node-webkit应用程序中实现谷歌分析API,我设法用ga-dev-tools.appspot.com做到这一点,但我不能用简单的javascript请求使用它。我想问题是标题参数“Origin”(在node-webkit应用程序中是“file://”),因此我尝试使用节点的http请求,但我得到了相同的结果:google以“hitParsingResult”回应:[{“valid”:true,...但是在Google Analytics信息中心?无法看到该事件,或者在本例中是一个综合浏览量。
The strange thing is that if I copy the request with chrome inspector on the ga-dev-tools.appspot.com (copy as cURL) and I exec it in the linux terminal it works but not with nodejs http request.
奇怪的是,如果我在ga-dev-tools.appspot.com上复制带有chrome检查器的请求(复制为cURL)并且我在linux终端执行它,它可以工作但不能与nodejs http请求一起使用。
The details: cURL call
细节:cURL电话
curl 'https://www.google-analytics.com/collect' -H 'Accept: */*' -H 'Referer: https://ga-dev-tools.appspot.com/hit-builder/' -H 'Origin: https://ga-dev-tools.appspot.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'v=1&t=screenview&tid=UA-XXXXX-X&cid=develop&an=mainapplication&av=2.0.1&cd=login'
nodejs code
request.post("https://www.google-analytics.com/debug/collect",
var options = {
url: 'https://api.github.com/repos/request/request',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36',
'Origin': 'https://ga-dev-tools.appspot.com',
'Referer': 'https://ga-dev-tools.appspot.com/hit-builder/',
'Accept': '*/*'
},
formData: 'v=1&tid=UA-XXXXX-X&cid=develop&an=mainapplication&av=2.0.1&t=screenview&cd=login'
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
else
{
console.error(error)
}
})
I tried to find a nodejs module to do that but I can't find one with Application integration (screenview, an, av..)
我试图找到一个nodejs模块来做到这一点,但我找不到一个与应用程序集成(screenview,an,av ..)
Someone can help me?
有人可以帮帮我吗?
2 个解决方案
#1
1
Your curl request is going to https://www.google-analytics.com/collect
and your Node.js request is going to https://www.google-analytics.com/debug/collect
(notice the debug
in the URL).
您的curl请求将转至https://www.google-analytics.com/collect,您的Node.js请求将转至https://www.google-analytics.com/debug/collect(请注意网址中的调试)。
The debug endpoint is for debugging errors only. It does not send actual hits to Google Analytics. I suspect that's your problem.
调试端点仅用于调试错误。它不会向Google Analytics发送实际匹配。我怀疑那是你的问题。
#2
1
I resolved all my issues and posted the code on github, if someone needed it: nwjs-analytics
我解决了所有问题并在github上发布了代码,如果有人需要它:nwjs-analytics
#1
1
Your curl request is going to https://www.google-analytics.com/collect
and your Node.js request is going to https://www.google-analytics.com/debug/collect
(notice the debug
in the URL).
您的curl请求将转至https://www.google-analytics.com/collect,您的Node.js请求将转至https://www.google-analytics.com/debug/collect(请注意网址中的调试)。
The debug endpoint is for debugging errors only. It does not send actual hits to Google Analytics. I suspect that's your problem.
调试端点仅用于调试错误。它不会向Google Analytics发送实际匹配。我怀疑那是你的问题。
#2
1
I resolved all my issues and posted the code on github, if someone needed it: nwjs-analytics
我解决了所有问题并在github上发布了代码,如果有人需要它:nwjs-analytics