From 6e607c4e6ea49cf11d8ebd1f436e2751f7991fa2 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 17 Feb 2016 19:15:56 +0200 Subject: [PATCH] Simplify the Google Analytics snippet using `async` & `defer` https://github.com/h5bp/html5-boilerplate/pull/1660#issuecomment-89285678 --- Gruntfile.js | 5 ++--- source/_includes/footer.html | 8 ++++++++ source/assets/js/google-analytics.js | 10 ---------- 3 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 source/assets/js/google-analytics.js diff --git a/Gruntfile.js b/Gruntfile.js index 755b9a50..d52266eb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -71,8 +71,7 @@ module.exports = function(grunt) { "<%= dirs.src %>/assets/js/vendor/jquery.mousewheel.js", "<%= dirs.src %>/assets/js/vendor/jquery.fancybox.js", "<%= dirs.src %>/assets/js/img-defer.js", - "<%= dirs.src %>/assets/js/no-js-class.js", - "<%= dirs.src %>/assets/js/google-analytics.js"], + "<%= dirs.src %>/assets/js/no-js-class.js"], dest: "<%= dirs.dest %>/assets/js/pack.js" } }, @@ -236,7 +235,7 @@ module.exports = function(grunt) { jshintrc: ".jshintrc" }, files: { - src: ["Gruntfile.js", "<%= dirs.src %>/assets/js/*.js", "!<%= dirs.src %>/assets/js/google-analytics.js"] + src: ["Gruntfile.js", "<%= dirs.src %>/assets/js/*.js"] } }, diff --git a/source/_includes/footer.html b/source/_includes/footer.html index 1c7c0844..843af3cc 100644 --- a/source/_includes/footer.html +++ b/source/_includes/footer.html @@ -88,5 +88,13 @@

Warning! + window.ga=function(){ga.q.push(arguments)};ga.q=[];ga.l=+new Date; + ga('create', 'UA-9335012-2', 'mpc-hc.org'); + ga('set', 'anonymizeIp', true); + ga('send', 'pageview') + + diff --git a/source/assets/js/google-analytics.js b/source/assets/js/google-analytics.js deleted file mode 100644 index 529e1d46..00000000 --- a/source/assets/js/google-analytics.js +++ /dev/null @@ -1,10 +0,0 @@ -// Google analytics - -(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', 'UA-9335012-2', 'mpc-hc.org'); -ga('set', 'anonymizeIp', true); -ga('send', 'pageview');