Skip to content

Instantly share code, notes, and snippets.

@0xDing
Last active May 18, 2017 20:03
Show Gist options
  • Save 0xDing/428bc3c1c93ddc4fe8ea62a8413639f8 to your computer and use it in GitHub Desktop.
Save 0xDing/428bc3c1c93ddc4fe8ea62a8413639f8 to your computer and use it in GitHub Desktop.
Google Analytics Proxy
server {
listen 443 http2 ssl;
server_name analytics.example.com;
location /ga_proxy {
proxy_set_header X-real-ip $remote_addr;
rewrite ^/ga_proxy/(.*)$ /$1?$args&uip=$remote_addr;
proxy_pass http://www.google-analytics.com;
break;
}
location /analytics.js {
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer https://www.google-analytics.com;
proxy_set_header Host www.google-analytics.com;
proxy_pass https://www.google-analytics.com;
proxy_set_header Accept-Encoding ""; subs_filter_types text/css text/xml text/javascript;
subs_filter www.google-analytics.com analytics.example.com/ga_proxy;
}
}
@0xDing
Copy link
Author

0xDing commented Jan 18, 2017

  (function (i, s, o, g, r, a, m) {
    i['GoogleAnalyticsObject'] = r;
    i[r] = i[r] || function () {
          (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date();
    a = s.createElement(o),
        m = s.getElementsByTagName(o)[0];
    a.async = 1;
    a.src = g;
    m.parentNode.insertBefore(a, m)
  })(window, document, 'script', '//analytics.example.com/analytics.js', 'ga');
  ga('create', 'UA-XXXX-X', 'auto');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment