OnyxMetric
Integration Guides

Jekyll

Add OnyxMetric analytics to your Jekyll site

Jekyll renders each page through a layout, typically _layouts/default.html. Put the tag in an include that the layout pulls in, or paste it into the layout itself.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Jekyll

  1. Add the ID to _config.yml:

    _config.yml
    onyxmetric_site_id: "YOUR_SITE_ID"
  2. Create _includes/onyxmetric-analytics.html:

    _includes/onyxmetric-analytics.html
    {% if jekyll.environment == "production" and site.onyxmetric_site_id %}
      <script src="https://app.onyxmetric.com/api/script.js?siteId={{ site.onyxmetric_site_id }}" async></script>
    {% endif %}

    The environment check keeps local jekyll serve builds out of your data; the ID check skips builds with no ID.

  3. Include it in the layout's <head>:

    _layouts/default.html
    <head>
      ...
      {% include onyxmetric-analytics.html %}
    </head>

Paste the tag inside <head> of _layouts/default.html, wrapped in a production check:

_layouts/default.html
<head>
  ...
  {% if jekyll.environment == "production" %}
    <script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
  {% endif %}
</head>

Build for production and deploy _site/:

JEKYLL_ENV=production jekyll build

GitHub Pages already sets the environment to production in its own build.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Troubleshooting

  • Tag missing: jekyll serve and a plain jekyll build use the development environment, so the guard removes the tag. Build with JEKYLL_ENV=production.
  • Config not applied: Jekyll reads _config.yml once at startup, so restart jekyll serve after adding onyxmetric_site_id.

Next steps

On this page