{% if site.google_analytics_tracking_id %}
<!-- Google Analytics -->
<style>.async-hide { opacity: 0 !important} </style>
<script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'{{ site.google_optimize_code }}':true});</script>
<script>
    (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', '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', '{{ site.google_analytics_tracking_id }}', 'auto');
    ga('set', 'anonymizeIp', true);
    ga('require', '{{ site.google_optimize_code }}');
    ga('send', 'pageview');
</script>
<!-- /Google Analytics -->
{% endif %}

{% if site.google_analytics_tracking_id %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics_tracking_id }}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '{{ site.google_analytics_tracking_id }}', { 'anonymize_ip': true });
</script>
<!-- /Google Analytics -->
{% endif %}

Use gtag.js incl. IP anonymization
Use gtag.js incl. IP anonymization