Documentation menuStatic site generators: Zola

Static site generators

Add Loogika to Zola

A Zola site has a base Tera template that the pages extend, and it is usually templates/base.html. The Loogika tag goes in the head of that template, while config.toml holds the site ID in its [extra] section. Every template can read that section as config.extra.

Last updated .

What do you need before you start?

Open Site Settings in Loogika and copy the script tag from the Tracking Script tab. The tag contains your site ID, a 12-character string that the example below shows as YOUR_SITE_ID:

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

How do you add Loogika to Zola?

You add one config value and one block in the base template.

  1. Open config.toml and give the [extra] section a line with the site ID.
  2. In templates/base.html, place the tag in the head element and wrap it in the mode check below.
  3. Run zola build and deploy the generated public folder.
[extra]
loogika_site_id = "YOUR_SITE_ID"

The template reads the value from config.extra and prints the tag during a build:

<head>
  ...
  {% if config.mode == "build" %}
    <script src="https://app.loogika.com/api/script.js?siteId={{ config.extra.loogika_site_id }}" defer></script>
  {% endif %}
</head>

The config.mode check leaves the tag out when you run zola serve. Your own visits during local development are then not counted.

What if a theme owns base.html?

Copy the file from themes/<theme>/templates/base.html into your own templates folder and edit the copy. A template in your site overrides the theme template with the same name. You can then update the theme without losing the tag.

How do you check that Loogika is installed?

Open the deployed site in a new tab and visit a few pages. The pageviews reach the Loogika dashboard within a few seconds.

If the dashboard shows nothing, open the page source and look for script.js?siteId=. When the tag is present, look in the Network tab of your browser for requests to /api/track with status 200. More causes are listed on the script troubleshooting page.

Why is the tag missing from a Zola page?

CauseFix
You look at the local previewzola serve sets config.mode to serve, and the check removes the tag. Look at the output of zola build
Zola does not know config.modeThe value is missing in older Zola releases. Upgrade Zola, or remove the if block and accept pageviews from local development
The template does not extend the base templateAdd the tag separately to such a template, for example a section template with a head element of its own or a custom 404.html