summaryrefslogtreecommitdiff
path: root/_includes/extensions
diff options
context:
space:
mode:
Diffstat (limited to '_includes/extensions')
-rw-r--r--_includes/extensions/google-analytics.html20
1 files changed, 14 insertions, 6 deletions
diff --git a/_includes/extensions/google-analytics.html b/_includes/extensions/google-analytics.html
index a3b6d85..9ae8963 100644
--- a/_includes/extensions/google-analytics.html
+++ b/_includes/extensions/google-analytics.html
@@ -1,3 +1,4 @@
+<!-- Google tag (gtag.js) -->
<script>
function initGoogleAnalytics() {
var doNotTrack = (window.doNotTrack === "1" || navigator.doNotTrack === "1" ||
@@ -5,13 +6,20 @@
var enableDNT = "{{ site.enableDNT | default: true }}" == "true";
if (!enableDNT || !doNotTrack) {
- (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','https://www.google-analytics.com/analytics.js','ga');
+ var measurementId = '{{ site.google_analytics }}';
- ga('create', '{{ site.google_analytics }}', 'auto');
- ga('send', 'pageview');
+ (function(src) {
+ var tag = document.createElement('script');
+ tag.src = src;
+ tag.async = true;
+ var firstScriptTag = document.getElementsByTagName('script')[0];
+ firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
+ })('https://www.googletagmanager.com/gtag/js?id=' + measurementId);
+
+ window.dataLayer = window.dataLayer || [];
+ function gtag(){dataLayer.push(arguments);}
+ gtag('js', new Date());
+ gtag('config', measurementId);
}
}
window.addEventListener("load", initGoogleAnalytics);