Skip to content

Commit

Permalink
feat(analytics): Add Analytics
Browse files Browse the repository at this point in the history
- Add Baidu analytics & Google analytics
- Close #75
  • Loading branch information
simonsmh authored and neoFelhz committed Jan 17, 2017
1 parent 8db6d0d commit 83249b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ search:
use: google
swiftype_key:

# Analytics Systems
analytics:
baidu_id:
google_id:

# Leancloud Views
leancloud:
enable: false
Expand Down
25 changes: 24 additions & 1 deletion layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

<%- css("css/highlight/" + theme.reading.code_highlight ) %>

<!-- UC Browser Compatible-->
<!-- UC Browser Compatible -->
<script>
var agent = navigator.userAgent.toLowerCase();
if(agent.indexOf('ucbrowser')>0) {
Expand All @@ -95,6 +95,29 @@
}
</script>

<% if(theme.analytics.baidu_id) { %>
<!-- Baidu Analytics -->
<script>
var _hmt = _hmt || [];
(function() {var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%= theme.analytics.baidu_id %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<% } %>

<% if(theme.analytics.google_id) { %>
<!-- Google Analytics -->
<script>
(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');
ga('create', '<%= theme.analytics.google_id %>', 'auto');ga('send', 'pageview');
</script>
<% } %>

<!-- Custom Head -->
<% if (site.data.head) { %>
<% for (var i in site.data.head) { %>
Expand Down

0 comments on commit 83249b3

Please sign in to comment.