Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tiancheng91/5f645ebc9f9e8b8d903799fee779ff9a to your computer and use it in GitHub Desktop.

Select an option

Save tiancheng91/5f645ebc9f9e8b8d903799fee779ff9a to your computer and use it in GitHub Desktop.

Revisions

  1. @paivaric paivaric revised this gist Feb 28, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion 1.google-analytics-proxy-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,8 @@ server {
    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
    # 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';
  2. @paivaric paivaric revised this gist Feb 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 2.browser-javascript-file.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    (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','http//your.domain.com/analytics.js','ga');
    })(window,document,'script','//your.domain.com/analytics.js','ga');

    # after this run your regular ga code
    ga('create', 'UA-XXXXXXX-Y', 'auto');
  3. @paivaric paivaric revised this gist Feb 28, 2018. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
  4. @paivaric paivaric created this gist Feb 28, 2018.
    11 changes: 11 additions & 0 deletions browser-javascript-file.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    (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','http//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');
    21 changes: 21 additions & 0 deletions google-analytics-proxy-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@

    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

    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/;
    }
    }