attila_pelican_theme/templates/partials/analytics.js
Vitaly Potyarkin e6ccaf33d2 Google analytics update (#31)
* Update Google Analytics tracking code

Previous template was using ga.js which is considered legacy now. The
recommended way to enable Google Analytics now is via gtag.js:
https://support.google.com/analytics/answer/1008080

* Do not store IP address (personally identifyable information)

With GDPR in effect IP addresses are considered personally identifyable
information, and storing them becomes legally complicated. Anonymizing IPs
seems to be a sensible default behavior.

The only drawback is slightly reduced geolocation accuracy.

More information:
- https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization
- https://support.google.com/analytics/answer/2763052
- https://www.blastam.com/blog/5-actionable-steps-gdpr-compliance-google-analytics
2018-06-29 10:45:14 +05:30

44 lines
1.7 KiB
JavaScript

{% if GOOGLE_ANALYTICS %}
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{GOOGLE_ANALYTICS}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{GOOGLE_ANALYTICS}}', { 'anonymize_ip': true });
</script>
{% endif %}
{% if GAUGES %}
<script type="text/javascript">
var _gauges = _gauges || [];
(function() {
var t = document.createElement('script');
t.type = 'text/javascript';
t.async = true;
t.id = 'gauges-tracker';
t.setAttribute('data-site-id', '{{GAUGES}}');
t.src = '//secure.gaug.es/track.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(t, s);
})();
</script>
{% endif %}
{% if PIWIK_URL and PIWIK_SITE_ID %}
<script type="text/javascript">
{% if PIWIK_SSL_URL %}
var pkBaseURL = "{{ PIWIK_SSL_URL }}";
{% else %}
var pkBaseURL = "{{ PIWIK_URL }}";
{% endif %}
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http")+"://"+pkBaseURL+"/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "{{ PIWIK_SITE_ID }}"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
{% endif %}