Google Analytics and Adsense in Hexo

This is the guideline to setup the Google Analuytics and Adsense in Hexo with Theme-NexT

Component version
hexo 4.2
hexo-theme-next 7.7

Google Analytics

Google Analysis
https://analytics.google.com/analytics/web/#/

Setup Google Analytics

  1. Register and activate the account of google analytics
  2. Steps forward as the guideline of GA, copy and paste the scirpt to hexo(look into the following steps)
  3. Uncomment the reference of header.swig in _config.yml of the theme, hexo-next
    1
    header: source/_data/header.swig
  4. Create the {HEXO_ROOT}/source/_data/post-body-end.swig
    1
    2
    3
    4
    5
    <!-- Google AdSense start -->

    <script data-ad-client="ca-pub-key" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

    <!-- Google AdSense end -->

Create a filter for another view of the property for WeChat(微信)

  1. Login your google analytics

  2. Navigate to #admin => #Account => #property => #View and create a new view,named as “My WeChat View”

  3. Create a new custom filter for “My WeChat View”

    wechat filter

Now you can monitor the traffic from WeChat in Google Analytics.

Google Adsense

Google adsense
https://www.google.com/adsense

Setup

  1. Register and activate the account of google adsense
  2. Navigate to the Ads by units(recommended), customize your style of ads and copy and paste the scirpt to hexo(look into the following steps)
    In-Article
  3. Uncomment the reference of post-body-end.swig in _config.yml of the theme, hexo-next
  4. Create the {HEXO_ROOT}/source/_data/post-body-end.swig
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    {# google adsense body #}
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
    style="display:block; text-align:center;"
    data-ad-layout="in-article"
    data-ad-format="fluid"
    data-ad-client="ca-pub-6391042540548664"
    data-ad-slot="7494260686"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    {# google adsense end #}

Google search Console

You can submit the sitemap.xml and RSS feed as the source of your site map
to be continues

Reference

创建和提交站点地图
https://support.google.com/webmasters/answer/183668?hl=zh-Hans
Google adsense
https://www.google.com/adsense
Google Analysis
https://analytics.google.com/analytics/web/#/
谷歌广告类型的说明
https://darylliu.github.io/archives/6a1f6623.html