Backends
CodeIgniter
CodeIgniter 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
Copy the ID from Settings in the dashboard and add it to the
.envfile on your production server:CI_ENVIRONMENT = production STICKYBEAK_SITE_ID = YOUR_SITE_IDAdd it to your layout
Put this before
</head>:<script>window.stickybeak = window.stickybeak || function () { (window.stickybeak.q = window.stickybeak.q || []).push(arguments); };</script> <?php if (ENVIRONMENT === 'production' && env('STICKYBEAK_SITE_ID')): ?> <script defer data-site="<?= esc(env('STICKYBEAK_SITE_ID'), '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
Give any button or link a data-goal attribute. See Custom goals.
<a href="<?= site_url('pricing') ?>" data-goal="view_pricing">Pricing</a>
Fire a goal after a redirect
Attach the goal as flashdata on the redirect:
return redirect()->to('/welcome')->with('stickybeak_goal', [
'name' => 'signup',
'props' => ['plan' => $plan],
]);
<?php $goal = session()->getFlashdata('stickybeak_goal'); ?>
<?php if ($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 ?>
Track purchases
return redirect()->to('/order/thanks')->with('stickybeak_goal', [
'name' => 'purchase',
'props' => ['revenue' => $order['total'], 'currency' => 'USD', 'order_id' => (string) $order['id']],
]);
See Revenue.
If it isn't working
- Check
CI_ENVIRONMENTandSTICKYBEAK_SITE_IDin the server’s.env.
See Troubleshooting.