Setting up Google Analytics in Jekyll when theme includes no head.html

我的梦境 提交于 2019-12-06 06:29:06

If you create that file, as the tutorial suggests, then you can use it everywhere, (in your layout for example) so every time you include it, it gets rendered.

Create the file _includes/head.html with the analytics content.

Then in your layout include it where you want it to appear like:

{% include head.html %}

Then you can place all your code that goes in your head there, so you have a cleaner layout

side note

I prefer to have the analytics code following Google recommendation immediately after the opening <body> tag. So my default layout looks like:

<!DOCTYPE html>
<html>

  {% include head.html %}

  <body>
    {% include ganalytics.html %}
    {% include header.html %}

      {{ content }}

    {% include footer.html %}

  </body>

</html>

and _includes/ganalytics.html just contain the analytics code.

Simple add analytics marker in _layouts/default.html head tag. No need to add a head include.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!