Add Google Analytics to Jekyll
-
Sign up for new Google Analytics account using this link.
-
Paste the Google Analytics tracking code into a new file named
_includes/analytics.html
file under your Jekyll project. This step enables the tracking code template for use for all available Jekyll pages.
_includes/
├── analytics.html
- Insert
{% include analytics.html %}
after{% include head.html %}
line in the_layouts/default.html
file. This step ensures that the tracking code template will be included in all generated Jekyll pages.
-
Run
jekyll build
to generate the Jekyll site using the Google analytics template. You will notice that Google Analytics tracking code is included in the generated pages. For example,_site/index.html
. -
Otherwise, run
jekyll serve
orbundle exec jekyll serve
command to serve and test your site locally atlocalhost:4000
.
Credits
Read Michael Lee’s post or Jekyll documentation on further customizing Google analytics for Jekyll for use only in production environment.