Content management systems
Add Loogika to Kirby
Kirby keeps its templates as plain PHP files in site/templates and puts the markup that templates share in site/snippets. Add the Loogika tag to the file that holds your head element. In the Starterkit that file is site/snippets/header.php, and in a Plainkit project you create it yourself.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
How do you add Loogika to the Kirby Starterkit?
Add the tag to the shared header snippet. The Starterkit renders the document head from one snippet, and every template includes it with <?php snippet('header') ?>.
- Open
site/snippets/header.php. - Add the tag before
</head>, as shown below. - Save the file. The script now loads in each template that calls
snippet('header').
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $site->title() ?> | <?= $page->title() ?></title>
<?= css(['assets/css/index.css', '@auto']) ?>
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
How do you add Loogika to a Plainkit project?
Add the tag in the place where you build your <head>. The Plainkit has no document structure yet. Its site/templates/default.php holds only a heading with the page title.
The usual pattern in Kirby is a header snippet that each template includes. Create site/snippets/header.php with the tag in the head:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?= $page->title() ?></title>
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body>
Then include the header snippet at the top of site/templates/default.php and of every other template:
<?php snippet('header') ?>
<h1><?= $page->title() ?></h1>
<?php snippet('footer') ?>
Where can you store the site ID outside the snippet?
Store the site ID as an option in site/config/config.php, for example under the name loogika.siteId. Read the option in the snippet with <?= option('loogika.siteId') ?> in place of the ID.
How do you check that Loogika is installed?
Load your site in a fresh browser tab and visit a few pages. The pageviews appear in the Loogika dashboard within a few seconds. If nothing arrives, open the page source and look for script.js?siteId=.
Why does Kirby not show the tag on every page?
Check the page cache and look for a second header snippet.
- Page cache. If
cache.pages.activeis turned on insite/config/config.php, cached pages keep the old head. Empty thesite/cache/folder after you edit the snippet. - Another header snippet. Some templates include a header of their own, such as
snippet('header-landing'). That snippet needs the tag too.
Does Loogika track the Kirby Panel?
No. The Panel at /panel runs as an app of its own, and it never renders your templates. The time you spend editing there never shows up in Loogika.