Custom Code in Jekyll

Hi all, is there a universal way of adding custom code to a Jekyll based site? I have a Matamo based analytics running and curious about how to count my Jekyll sites on it.

It would have been nice to know if you want to add JS code or Ruby code. And a link to the docs to what you want to add.

I dug around and found that you need a JS snippet added to your head tag.

You also seem to need a self hosted mysql database to collect the data.

Anyway adding a JS snippet to Jekyll has a pattern.

Based on Minima, I would create _includes/analytics.html and drop your matomo script tag in there.

Then in _layouts/default.html or _includes.head.html you would add it.

<head>

{% include matomo.html %}

</head>

See latest minima

head.html

And google-analytics.html

You can use a pattern from those two files to read a key as

{{ site.manomo }}

After setting in your config

manomo: abc-123abc

Assuming you have some site-specific account ID like GA has

Then maybe you want to share your solution on github as a repo which has

  • README.md
  • LICENSE
  • _includes/analytics.html

And no other files.

Then you can make it easy for others to find and use your solution.

Note I would avoid making your project into an installable gem as it won’t be allowed on GH Pages which I suspect is the majority of Jekyll sites. But if you did, you could make a .rb or maybe .html file which does this and can be installed using a Gemfile

Thanks Michael,

I’ll see if that works!

1 Like