Maybe this is trivial, but I haven't found anything meaningful or I didn't know where to look...
(How) is it possible to to send a curl / whatever command as soon as a certain path is requested?
Something along these lines, but that would actually work:
location / {
curl --data 'v=1&t=pageview&tid=UA-XXXXXXXX-X&cid=123&dp=hit' https://google-analytics.com/collect
}
(as pointed out in the comments), ngx_http_lua_module
can do it!
location / {
access_by_lua_block {
os.execute("/usr/bin/curl --data 'v=1&t=pageview&tid=UA-XXXXXXXX-X&cid=123&dp=hit' https://google-analytics.com/collect >/dev/null 2>/dev/null")
}
}
note that the execution halts the pageload until curl has finished. to run curl in the background and continue the pageload immediately, add a space and an &
to the end so it looks like
>/dev/null 2>/dev/null &")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With