From 908ee5918ab56f7742536ce18d73fd5b364946e4 Mon Sep 17 00:00:00 2001 From: Duck Date: Sun, 7 Oct 2018 20:17:53 +0800 Subject: [PATCH] Do not send analysis information when page loading on locahost. https://github.com/Huxpro/huxblog-boilerplate/pull/7 --- _includes/footer.html | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/_includes/footer.html b/_includes/footer.html index d3b72ab..007467a 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -155,14 +155,18 @@ var _gaId = '{{ site.ga_track_id }}'; var _gaDomain = '{{ site.ga_domain }}'; - // Originial - (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', _gaId, _gaDomain); - ga('send', 'pageview'); + // check whether running on localhost + var re = new RegExp('^(127.0.0.1|localhost)$') + if (!re.test(document.location.hostname)) { + // Originial + (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', _gaId, _gaDomain); + ga('send', 'pageview'); + } {% endif %} @@ -173,13 +177,17 @@ // dynamic User by Hux var _baId = '{{ site.ba_track_id }}'; - // Originial - var _hmt = _hmt || []; - (function() { - var hm = document.createElement("script"); - hm.src = "//hm.baidu.com/hm.js?" + _baId; - var s = document.getElementsByTagName("script")[0]; - s.parentNode.insertBefore(hm, s); - })(); + // check whether running on localhost + var re = new RegExp('^(127.0.0.1|localhost)$') + if (!re.test(document.location.hostname)) { + // Originial + var _hmt = _hmt || []; + (function() { + var hm = document.createElement("script"); + hm.src = "//hm.baidu.com/hm.js?" + _baId; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); + })(); + } {% endif %}