feat: Google Analytics,百度统计

This commit is contained in:
沈宇 2019-12-06 12:56:15 +08:00
parent 08c9fb777e
commit d7cf77544c
5 changed files with 61 additions and 27 deletions

View File

@ -125,6 +125,11 @@ cnzz:
enable: true
url: #
# Google Analytics
google_analytics: ''
# 百度统计
baidu_analytics: ''
# 数学公式
mathjax: true

View File

@ -86,6 +86,11 @@ cnzz:
enable: true
url: https://s9.cnzz.com/z_stat.php?id=1278069914&web_id=1278069914
# Google Analytics
google_analytics: ''
# 百度统计
baidu_analytics: ''
# 数学公式
mathjax: true

View File

@ -0,0 +1,11 @@
<% if (theme.baidu_analytics){ %>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?<%= theme.baidu_analytics %>";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<% } %>

View File

@ -0,0 +1,14 @@
<% if (theme.google_analytics){ %>
<%# "Google Analytics" %>
<script type="text/javascript">
(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', '<%= theme.google_analytics %>', 'auto');
ga('send', 'pageview');
</script>
<%# "End Google Analytics" %>
<% } %>

View File

@ -1,16 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="utf-8" />
<% var title = page.title; if (is_archive()) { title = __('archive_a'); if
(is_month()) { title += ': ' + page.year + '/' + page.month; } else if
(is_year()) { title += ': ' + page.year; } } else if (is_category()) { title
= __('categories.ejs') + ': ' + page.categories; } else if (is_tag()) {
title = __('tag') + ': ' + page.tag; } %> <% if (page.keywords){ %>
<meta
name="keywords"
content="<%= page.keywords %>,<%= config.keywords %>"
/>
<meta name="keywords" content="<%= page.keywords %>,<%= config.keywords %>" />
<% } else if (config.keywords){ %>
<meta name="keywords" content="<%= config.keywords %>" />
<% } %> <% if (page.description){ %>
@ -18,10 +16,7 @@
<% } else if (config.description){ %>
<meta name="description" content="<%= config.description %>" />
<% } %>
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>
<% if (title){ %><%= title %> | <% } %> <%= config.title %>
</title>
@ -30,5 +25,9 @@
<% } %>
<%- css('css/style') %> <% if (theme.fancybox){ %> <%-
css('fancybox/jquery.fancybox.min') %> <% } %> <%- js('/js/pace.min.js') %>
</head>
<%- partial('google-analytics') %>
<%- partial('baidu-analytics') %>
</head>
</html>