hexo在linux一键包,Linux下使用 github+hexo 搭建个人博客06-next主题接入数据统计

c4012d0c15be7e4a78b95b001dfe2727.png

前言

之前说了 next 主题的优化和接入评论系统。让我们完成了自己所需的页面风格和排版,也可让访问用户在每篇博文评论,完成博主和访问用户的交互。

本章我们继续讲解其他重要功能。

既然是一个网站,那么我们就需要收集网站访问数据,提供流量趋势、来源分析、转化跟踪、页面热力图、访问流等多种统计分析服务;这时我们就需要引入——百度统计。

上述的统计只能在百度统计中查看,但我想在自己的网站页面直接就能看一些简单的数据。比如:网站访问人数,访问次数,每篇文章访问次数,网站总字数,每篇文章字数,阅读时长估算等。那么我们就可以引入不蒜子统计,字数统计,阅读次数统计了。具体那就参见下文了。

百度统计

需要在百度统计进行注册,并拿到脚本的 ID。

09406d4e97a5794a118c5db0aff472c0.png

之后在主题配置文件中修改。

1

2

3

4

5[root@iZ28xbsfvc4Z next]# pwd # 主题目录

/app/softinsall/hexo/themes/next

[root@iZ28xbsfvc4Z next]# vim _config.yml

# Baidu Analytics ID

baidu_analytics: 983XXXXXXXXXXXXXXXXXXXXXXXXXX2

访问报告查看

过半小时或一小时左右可在百度统计查看报告。

097fc30dae28d43de08894d82f4f9e5b.png

不蒜子统计

编辑主题配置文件中的 busuanzi_count 的配置项。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21[root@iZ28xbsfvc4Z next]# pwd # 主题目录

/app/softinsall/hexo/themes/next

[root@iZ28xbsfvc4Z next]# vim _config.yml

# Show PV/UV of the website/page with busuanzi.

# Get more information on http://ibruce.info/2015/04/04/busuanzi/

busuanzi_count:

# count values only if the other configs are false

enable: true

# custom uv span for the whole site

site_uv: true

site_uv_header: 本站访客数

site_uv_footer: 人次

# custom pv span for the whole site

site_pv: true

site_pv_header: 本站总访问量

site_pv_footer: 次

# custom pv span for one page only

# 每篇博文阅读次数,使用 leancloud 统计。原因是在「首页」中,leancloud 统计也能看阅读次数,而不蒜子则不行。

page_pv: false

page_pv_header: 本文总阅读量

page_pv_footer: 次

不蒜子域名修改

因七牛强制过期『dn-lbstatics.qbox.me』域名,与客服沟通无果,只能更换域名到『busuanzi.ibruce.info』!

修改如下:

1

2

3

4

5

6

7[root@iZ28xbsfvc4Z next]# pwd # 主题目录

/app/softinsall/hexo/themes/next

[root@iZ28xbsfvc4Z next]# vim layout/_third-party/analytics/busuanzi-counter.swig

{% if theme.busuanzi_count.enable %}

………………

浏览器访问

页面底部

58e7dc6bfe43014571b56341d5b6bb46.png

阅读次数统计

在 LeanCloud 中创建 Class

在之前的评论系统中,已经讲解了 LeanCloud 账号的创建、应用创建、获取App ID 和 App Key 已经安全加固。这里仅对阅读次数的 Class 创建做讲解。

数据栏中,_开头的都是系统预定义好的表。

为了区分,新建一张表来保存数据。为了保证对NexT主题的修改兼容,新建Class名字必须为Counter。

为了避免权限问题导致 次数统计显示不正常,选择无限制,创建Class。

c23a07b5fa05ea7e7e1dbc4f96536b60.png

主题配置修改

在主题配置文件中修改:

1

2

3

4

5

6

7

8

9[root@iZ28xbsfvc4Z next]# pwd # 主题目录

/app/softinsall/hexo/themes/next

[root@iZ28xbsfvc4Z next]# vim _config.yml

# Show number of visitors to each article.

# You can visit https://leancloud.cn get AppID and AppKey.

leancloud_visitors:

enable: true

app_id: h7YmXXXXXXXXXXXXXX

app_key: VhTGXXXXXXXXXX

浏览器访问

文章标题

9af880634a55f8ce7cbdbcaea73149c4.png

字数统计

用于统计文章的字数以及分析出阅读时间。

安装 wordcount 插件

需要安装的插件

1

2

3[root@iZ28xbsfvc4Z hexo]# pwd # 站点目录

/app/softinsall/hexo

[root@iZ28xbsfvc4Z hexo]# npm install hexo-wordcount --save

主题配置修改

在主题配置文件中修改。

1

2

3

4

5

6

7

8

9

10

11

12

13

14[root@iZ28xbsfvc4Z next]# pwd # 主题目录

/app/softinsall/hexo/themes/next

[root@iZ28xbsfvc4Z next]# vim _config.yml

# Post wordcount display settings

# Dependencies: https://github.com/willin/hexo-wordcount

post_wordcount:

item_text: true # 文本显示

wordcount: true # 单篇 字数统计

min2read: true # 单篇 阅读时长

totalcount: true # 网站 字数统计

# 该post_wordcount的所有设置另起一行显示

separated_meta: true

[root@iZ28xbsfvc4Z next]# vim languages/zh-Hans.yml # 从英文改为中文

totalcount: 本站总字数

浏览器访问

文章标题

d6be501af64c588fd0a8c9e644fbd9fd.png

页面底部

d5da89b8deda4e2bf57946adefda5148.png

推荐阅读

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值