gpt4 book ai didi

node.js 请求多行

转载 作者:行者123 更新时间:2023-12-03 17:16:14 24 4
gpt4 key购买 nike

谷歌分析测量协议(protocol)说他们的/batch使用多行端点:

https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#batch

POST /batch HTTP/1.1
Host: www.google-analytics.com

v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fabout
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fcontact

我将如何使用 node.js 和请求做类似的事情?这是我当前的 /collect 代码
request.post(
'http://www.google-analytics.com/batch',
{ form: { v:1,tid:'UA-xxxxx-1',cid:event.queryStringParameters.cid,t:'event',ec:'xxx',ea:"xxx", el:"xxx", ev:"xxx", dr:'xxx'} },
function (error, response, body) {
done(null,'Check for GA event');
}
);

最佳答案

将每一行组合成一个字符串,用“\n”分隔。

const request = require("request");

request({
url: "http://www.google-analytics.com/batch",
method: "post",
body: "v=1&t=pageview&tid=UA-XXXXXXXX-X&cid=555&dl=https%3A%2F%2Fmydomain.com%2Ftest&dt=Test\nv=1&t=pageview&tid=UA-XXXXXXXX-X&cid=554&dl=https%3A%2F%2Fmydomain.com%2Ftest2&dt=Test2"
}, function(error, response, body) {
if (error) { console.log(error); }
});

您的实时报告将在 2 个不同页面上显示 2 个活跃用户。

关于node.js 请求多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403271/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com