Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Commit 41830a4

Browse files
committed
fix(ga): google analytics never active on localhost
1 parent 441c46e commit 41830a4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

layout/google_analytics.ejs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<% if (config.theme_config.google_analytics){ %>
22
<script>
3-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
5-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
6-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
7-
ga('create', '<%= config.theme_config.google_analytics %>', 'auto');
8-
ga('send', 'pageview');
3+
if (window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
4+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
5+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
6+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
7+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
8+
ga('create', '<%= config.theme_config.google_analytics %>', 'auto');
9+
ga('send', 'pageview');
10+
}
911
</script>
1012
<% } %>

0 commit comments

Comments
 (0)