Backends

Kirby
Kirby analytics with Stickybeak starts by adding its script to your rendered pages; this guide shows you where it belongs and how to track page views, goals and purchase revenue.
Add the script
Set the site ID for your live domain
Kirby loads
site/config/config.{host}.phpon top ofconfig.phpwhen the request is for that host.<?php return [ 'stickybeak.site' => 'YOUR_SITE_ID', ];If you serve from
www.example.com, name the fileconfig.www.example.com.php.Add it to your header snippet
Put this before
</head>:<script>window.stickybeak = window.stickybeak || function () { (window.stickybeak.q = window.stickybeak.q || []).push(arguments); };</script> <?php if ($stickybeakSite = option('stickybeak.site')): ?> <script defer data-site="<?= esc($stickybeakSite, 'attr') ?>" data-domain="example.com" src="https://app.usestickybeak.com/_cfw/s.js" ></script> <?php endif ?>
Check it's working
Publish first, then follow Verify your install.
Track goals
Add data-goal to links and buttons in your templates and snippets. See Custom goals.
<a href="<?= url('pricing') ?>" data-goal="view_pricing">Pricing</a>
Fire a goal after a redirect
When a controller handles a form and redirects, put the goal in Kirby's session:
<?php
return function ($kirby) {
if ($kirby->request()->is('POST') && csrf(get('csrf'))) {
// ...validate and send the message...
$kirby->session()->set('stickybeak_goal', ['name' => 'contact_form', 'props' => []]);
go('contact/thanks');
}
return [];
};
Then take it out of the session in the template of the page you redirect to, after the header snippet.
<?php if ($goal = $kirby->session()->pull('stickybeak_goal')): ?>
<script>window.stickybeak(<?= json_encode($goal['name'], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>, <?= json_encode((object) $goal['props'], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>);</script>
<?php endif ?>
For a sale (from Kirby Merx or your own checkout), use the name purchase with revenue, currency and order_id props. See Revenue.
Track purchases
Render window.stickybeak("purchase", { revenue, currency, order_id }) on the checkout confirmation page.
See Revenue.
If it isn't working
- The host-specific config filename must exactly match the hostname. Keep session reads off cached pages.
See Troubleshooting.