Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Analytics Proxy using Nginx to bypass Adblock and other blockers
server {
listen 80;
server_name your.domain.com;
location = /analytics.js {
# you have to compile nginx with http://nginx.org/en/docs/http/ngx_http_sub_module.html (this is not default)
# and http://nginx.org/en/docs/http/ngx_http_proxy_module.html (it's a default module)
proxy_set_header Accept-Encoding "";
sub_filter 'www.google-analytics.com' 'your.domain.com';
sub_filter_types *;
sub_filter_once off;
proxy_pass https://www.google-analytics.com/analytics.js;
break;
}
location / {
proxy_pass http://www.google-analytics.com/;
}
}
(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','//your.domain.com/analytics.js','ga');
# after this run your regular ga code
ga('create', 'UA-XXXXXXX-Y', 'auto');
ga('set', 'userId', 'your logged user id');
ga('send', 'pageview');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.