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
-
Add the ID to
_config.yml:_config.yml onyxmetric_site_id: "YOUR_SITE_ID" -
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 servebuilds out of your data; the ID check skips builds with no ID. -
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:
<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 buildGitHub 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.jsreturns200and 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 serveand a plainjekyll builduse thedevelopmentenvironment, so the guard removes the tag. Build withJEKYLL_ENV=production. - Config not applied: Jekyll reads
_config.ymlonce at startup, so restartjekyll serveafter addingonyxmetric_site_id.
Next steps
- Track custom events such as signups, purchases, and clicks.
- Identify users to tie sessions to accounts.
- Proxy the script through your own domain to get past ad blockers.
- Script attributes let you skip or mask URLs and tag events.