Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

如何添加百度统计 #46

Closed
ghost opened this issue Jun 28, 2018 · 2 comments
Closed

如何添加百度统计 #46

ghost opened this issue Jun 28, 2018 · 2 comments
Labels
discussion Any questions about this theme.

Comments

@ghost
Copy link

ghost commented Jun 28, 2018

由于网上的文章都是针对某个主题,所以它不适合我。我也曾效仿你的其他作品从而进行设置,可惜依然不行。
想请问一下对于该主题如何添加百度统计?就像Google统计那样,可以在主题配置文件中通过“id”进行一键设置。

@ppoffice
Copy link
Owner

ppoffice commented Jun 28, 2018

@taiyuanhang
流程简述

  1. 在/layout/plugins/目录下新建插件文件,如baidu-analytics.ejs
  2. 将百度统计代码复制到其中,并注意用<%= get_config('plugins.baidu-analytics.tracking_id') %>函数替换掉自己的ID。函数中的plugins.baidu-analytics.tracking_id为配置项名称,可以自定义,但要与下面步骤中的配置文件保持一致
  3. 在主题配置文件中添加相应的配置,如
    plugins:
        baidu-analytics:
            tracking_id: xxxxx...

函数说明

  1. has_config(config_name): 检测主题配置文件中是否存在某配置项
  2. get_config(config_name): 获取配置项的值

具体实现可以参照 https://github.com/ppoffice/hexo-theme-minos/blob/master/layout/plugins/google-analytics.ejs

@ppoffice ppoffice added the discussion Any questions about this theme. label Jun 28, 2018
@ghost
Copy link
Author

ghost commented Jun 29, 2018

@ppoffice 已解决,谢谢。

@ghost ghost closed this as completed Jun 29, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
discussion Any questions about this theme.
Projects
None yet
Development

No branches or pull requests

1 participant