我正在使用以下代码通过衡量协议将服务器端匹配发送到GA:
location = /example {
access_by_lua_block {
local request = {
v = 1,
t = "pageview",
tid = "UA-XXXXXXXX-Y",
cid = ngx.md5(ngx.var.remote_addr .. ngx.var.http_user_agent),
uip = ngx.var.remote_addr,
dp = ngx.var.request_uri,
dr = ngx.var.http_referer,
ua = ngx.var.http_user_agent,
ul = string.sub(ngx.var.http_accept_language, 1, 2)
}
local res = ngx.location.capture( "/gamp", {
method = ngx.HTTP_POST,
body = ngx.encode_args(request)
})
}
}
location = /gamp {
internal;
expires epoch;
access_log off;
proxy_pass_request_headers off;
proxy_pass_request_body on;
proxy_pass https://google-analytics.com/collect;
}
我希望能够从内容中传递更多信息,例如标题等。相应的标头(例如X-title
)已经从后端(php / wordpress)生成,但是当我将dt = ngx.resp.get_headers()["X-title"]
添加到请求中,该请求不检索任何内容。我认为这是因为nginx尚未看到它们。他们会以某种方式被拦截然后发送出去吗?