Content management systems
Add Loogika to Statamic
A layout surrounds every Statamic template, and a new install uses resources/views/layout.antlers.html as its default. Add the Loogika tag to the head of that layout, and the script loads on every page without changes to single templates.
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 Statamic layout?
Open resources/views/layout.antlers.html, add the tag before </head> and save. A layout with the tag in place looks like this:
<!doctype html>
<html lang="{{ site:short_locale }}">
<head>
<meta charset="utf-8">
<title>{{ title }} | {{ site:name }}</title>
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body>
{{ template_content }}
</body>
</html>
Statamic prints each template in the place of {{ template_content }}. Every template that goes through the layout therefore includes the script.
If your views use Blade, neither the tag nor its position changes. The layout file is then layout.blade.php.
What if an entry uses another layout?
Add the tag to that layout file as well. An entry or a collection can set a different layout field, and pages with that layout skip the default one.
With several layouts, a partial saves you from repeating the tag. Put the tag in resources/views/partials/loogika.antlers.html and write {{ partial:loogika }} in the head of each layout.
Where do you store the site ID outside version control?
Put the site ID in your .env file as LOOGIKA_SITE_ID. Then add a loogika entry with a site_id key to config/services.php, and let it read that variable. The layout prints the value with {{ config:services:loogika:site_id }} 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. Loogika's dashboard shows those pageviews within a few seconds. If nothing arrives, look for script.js?siteId= in the page source.
Why do cached Statamic pages miss the tag?
Static caching keeps the old head. With half or full static caching turned on in config/statamic/static_caching.php, Statamic serves stored pages. Run php please static:clear after you edit the layout.
Does Live Preview count as visits?
Yes. In the control panel, Live Preview shows your entry inside an iframe. The iframe loads the real URL of the entry and adds a token query parameter. Loogika counts that preview like any other visit, so read your numbers from the live site and not while you edit.
The Statamic control panel itself is never tracked. The pages under /cp use the views of Statamic, so the Loogika tag does not run there.