Analytics and Sitemap Settings

How to use analytics and sitemap

Posted by MichaelChen on 2020-12-03
Estimated Reading Time 4 Minutes
Words 916 In Total
Viewed Times

Analytics and Sitemap Settings

Google Analytics Settings

代码(脚本)嵌入网站中

添加数据源流

  • image-20201203124646415

  • hexo-theme-livemylife 主题 head.ejs 文件中,已经添加了下面的 js 脚本。

    • 其他主题也可以在\themes\livemylife\layout\_partial中寻找对应的head文件
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-164526897-1"></script>
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-xxxxxx-xx');
    </script>
  • 直接修改 hexo-theme-livemylife 主题 _config.yml 配置文件 ga_track_id跟踪 ID

image-20201203124646415

Baidu Analytics Settings

  • 登录百度统计平台,添加 自有网站

    3

  • 获取代码(脚本)。

    4

  • hexo-theme-livemylife 主题 head.ejs 文件中,已经添加了下面的 js 脚本。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    <script>
    var _hmt = _hmt || [];
    (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?ba_track_id";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
    })();
    </script>
  • 直接修改 hexo-theme-livemylife 主题 _config.yml 配置文件 ba_track_id 为脚本中的 ba_track_id

    1
    ba_track_id: ba_track_id

Google Sitemap Settings

验证网站所有权

  • 先进入 google 站点平台,点击右上角的登录,如果还没有谷歌账号的要先注册一个谷歌账号。然后添加资源,这里选择网址前缀,输入博客首页,例如:https://v-vincen.life/

    5

  • 点击继续,验证网站所有权,使用HTML标记验证。

    6

  • 修改 hexo-theme-livemylife 主题的 head.ejs 文件。

    1
    <meta name="google-site-verification" content="X7_M3eeaLhvjhG34NuQBgu2gdyRlAtMB4utP5AgEBc" />
  • 把上面红框的内容复制下来,并粘贴到 head.ejs 文件中,通过验证。

安装 sitemap 插件

  • 在 hexo 根目录执行下面两个命令。

    1
    npm install hexo-generator-sitemap --save
  • 修改 hexo-theme-livemylife 主题 _config.yml 配置文件,url 换成自己的博客首页,并且需改 sitemap 配置。

    1
    2
    3
    4
    5
    6
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://v-vincen.life # Note: don't forget to modify the CNAME file to your url
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    1
    2
    3
    ## Sitemap
    sitemap:
    path: sitemap.xml
  • 执行 hexo g -d 命令,发现在根目录 public 文件夹下新增了 sitemap.xml 文件。

image-20201203124646415

提交谷歌站点地图

  • 接着进入谷歌站点,提交刚才验证网站的站点地图。

image-20201203124646415

  • 等待谷歌收录,最后谷歌搜索 `site:网站域名,看下网页是否被谷歌收录

Baidu Sitemap Settings

验证网站所有权
先进入 百度站点平台,「用户中心」-> 「站点管理」-> 「添加网站」,添加需要管理的网站地址。
image-20201203124646415

  • 验证有三种方式:文件、html标签、cname。这里采用的是 html 标签的形式,修改 hexo-theme-livemylife 主题的 head.ejs 文件。

    • 其他主题也可以在\themes\livemylife\layout\_partial中寻找对应的head文件
    1
    <meta name="baidu-site-verification" content="PpzM9WxOJU" />
  • 添加完相应的标签之后,上传到自己的博客之中,百度站点验证通过。

安装 baidu-sitemap 插件

  • 在 hexo 根目录执行下面两个命令。

    1
    npm install hexo-generator-baidu-sitemap --save
  • 修改 hexo-theme-livemylife 主题 _config.yml 配置文件,url 换成自己的博客首页,并且需改 Baidusitemap 配置。

    1
    2
    3
    4
    5
    6
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://v-vincen.life # Note: don't forget to modify the CNAME file to your url
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    1
    2
    3
    4
    5
    ## Baidusitemap
    baidusitemap:
    path: baidusitemap.xml

    baidu_push: true
  • 执行 hexo g -d 命令,发现在根目录 public 文件夹下新增了 baidusitemap.xml 文件。

百度站点收录

  • 「资源提交」-> 「普通收录」-> 「资源提交」-> 「sitemap」,填写数据文件地址,点击 「提交」。

    image-20201203124646415

  • 接下来要做的就是等待了,过上一两天就会在这里看到提取的 url 数量了。


If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !