Static site generators
Add Loogika to Jekyll
Each Jekyll page is built from a layout, and in most sites that layout is _layouts/default.html. You add the Loogika tag to the head of that layout, either through an include file or by pasting it in. A production check keeps the tag out of local builds.
Last updated .
What do you need before you start?
Copy the script tag for your site from Site Settings in Loogika. It sits under the Tracking Script tab and carries your 12-character site ID where the example says YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
How do you add Loogika with an include file?
An include file keeps the site ID in _config.yml and the tag in one place that any layout can reuse.
- Add the site ID to
_config.ymlas shown below. - Create the file
_includes/loogika-analytics.htmlwith the include code. Create the_includesfolder if it does not exist. - Include the file from the head element of
_layouts/default.html.
loogika_site_id: "YOUR_SITE_ID"
The include file prints the tag only in a production build that has a site ID:
{% if jekyll.environment == "production" and site.loogika_site_id %}
<script src="https://app.loogika.com/api/script.js?siteId={{ site.loogika_site_id }}" defer></script>
{% endif %}
The layout pulls the file in with one line:
<head>
...
{% include loogika-analytics.html %}
</head>
Can you paste the tag straight into the layout?
Yes. Open _layouts/default.html and paste the tag inside the head element. Wrap it in the production check, so visits to a local jekyll serve preview are not counted.
<head>
...
{% if jekyll.environment == "production" %}
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
{% endif %}
</head>
How do you build Jekyll for production?
Set the JEKYLL_ENV variable to production when you build, then deploy the generated _site folder. Without the variable, Jekyll builds in the development environment and the check removes the tag.
JEKYLL_ENV=production jekyll build
When GitHub Pages builds the site itself, it sets jekyll.environment to production. A site that GitHub Pages builds for you needs no extra configuration.
How do you check that Loogika is installed?
Load the live site in a fresh browser tab and visit a few pages. The Loogika dashboard shows the pageviews within a few seconds.
If the dashboard stays empty, open the page source and look for script.js?siteId=. The script troubleshooting page explains what to check when the tag is on the page but no data arrives.
Why is the tag missing from a Jekyll page?
| Cause | Fix |
|---|---|
| The build ran in the development environment | jekyll serve and a plain jekyll build set jekyll.environment to development. Set JEKYLL_ENV=production for the build and inspect the result |
| Jekyll has not read the new config value | Jekyll reads _config.yml once at startup. Restart jekyll serve after you add loogika_site_id |