forked from fr0der1c/google-analytics-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
70 lines (60 loc) · 2.29 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
server {
listen 80;
server_name _;
# New analytics codes will use Google Tag Manager by default. This file will do calls to both the old analytics domain, and itself so we have to proxy both domains.
location /gtag/ {
# Needed for sub_filter to work
proxy_set_header Accept-Encoding "";
# sub_filter docs: http://nginx.org/en/docs/http/ngx_http_sub_module.html
# TL:DR; It replaces a string with another string in file contents.
sub_filter 'www.google-analytics.com' '${GAPROXY_HOST}/a';
sub_filter 'www.googletagmanager.com' '${GAPROXY_HOST}/t';
sub_filter_types *;
sub_filter_once off;
proxy_pass https://www.googletagmanager.com/gtag/;
break;
}
location = /a/analytics.js {
# Needed for sub_filter to work
proxy_set_header Accept-Encoding "";
# sub_filter docs: http://nginx.org/en/docs/http/ngx_http_sub_module.html
# TL:DR; It replaces a string with another string in file contents.
sub_filter 'www.google-analytics.com' '${GAPROXY_HOST}/a';
sub_filter_types *;
sub_filter_once off;
proxy_pass https://www.google-analytics.com/analytics.js;
break;
}
location = /t/gtm.js {
proxy_set_header Accept-Encoding "";
sub_filter 'www.google-analytics.com' '${GAPROXY_HOST}/a';
sub_filter 'www.googletagmanager.com' '${GAPROXY_HOST}/t';
sub_filter_types *;
sub_filter_once off;
proxy_pass https://www.googletagmanager.com/gtm.js;
break;
}
location = /t/ns.html {
proxy_set_header Accept-Encoding "";
sub_filter 'www.google-analytics.com' '${GAPROXY_HOST}/a';
sub_filter 'www.googletagmanager.com' '${GAPROXY_HOST}/t';
sub_filter_types *;
sub_filter_once off;
proxy_pass https://www.googletagmanager.com/ns.html;
break;
}
location /a/ {
set $delimiter "";
if ($is_args) {
set $delimiter "&";
}
if ($http_x_real_ip = "") {
set $http_x_real_ip $remote_addr;
}
set $args "${args}${delimiter}uip=${http_x_real_ip}";
proxy_pass http://www.google-analytics.com/;
}
location /t/ {
proxy_pass http://www.googletagmanager.com/;
}
}