Web Notes
2016.08.20
Using Liquid in Jekyll - Live with Demos
Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.
Just set up the Google Analytics 4 with Google Tag Manager, however, both of them are been blocked by AdBlockers or DNS filters. A self-hosted Ackee helps to record the web traffics, but duplicate the same function with more traffic loads is not worthing. Therefore, I’m trying to reverse proxy the GTM and GA4 with Nginx.
Just a sample configuration here (only works for GA4), comments below to make it better.
set $gtm 'www.googletagmanager.com';
set $ga 'analytics.google.com';
location /gtm.js {
sub_filter $gtm $server_name;
sub_filter_types *;
sub_filter_once off;
proxy_set_header Accept-Encoding '';
proxy_pass https://$gtm/gtm.js$is_args$args;
proxy_redirect off;
# cache on server
proxy_cache ZONE0;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 60m;
# cache in client browser
expires 1h;
}
location /gtag/js {
sub_filter $gtm $server_name;
sub_filter $ga $server_name;
sub_filter_types *;
sub_filter_once off;
proxy_set_header Accept-Encoding '';
proxy_pass https://$gtm/gtag/js$is_args$args;
proxy_redirect off;
proxy_cache ZONE0;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 60m;
expires 1h;
}
location /g/collect {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://$ga$uri$is_args$args&uip=$remote_addr;
proxy_redirect off;
# proxy_cache ZONE0;
# proxy_cache_key $host$uri$is_args$args;
# proxy_cache_valid 200 304 60m;
proxy_cache off;
expires epoch; # browser no-cache control
}
If you want to reverse proxy the Universal Analytics, see the reference gist: https://gist.github.com/fhferreira/14015373d49b6543601ec5b23f169089.
Although the above snippet have set
uip=$remote_addr
, the geolocation is still not correct in Google Analytic’s report…What I’m actually implemented on this site is reverse proxy Baidu Tongji… 😂, much easy than Google’s system.
Frank Lin, PhD
Web Notes
2016.08.20
Liquid is a simple template language that Jekyll uses to process pages for your site. With Liquid you can output complex contents without additional plugins.
Linux Notes
2019.11.26
AdGuard Home supports all modern DNS encryption protocols, which enable us to setup a secure DNS server with custom AdBlock filters.
Web Notes
2022.03.01
Notes of Nextcloud installation on Ubuntu server with Nginx web server and PlanetScale cloud database.