Backends
Craft CMS
Craft CMS 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. It is a lighter alternative to Google Analytics for Craft CMS, with live visitors, goals and revenue attribution in one script.
Add the script
Set the site ID
Copy the ID from Settings in the dashboard and add it to
.envon your production server:CRAFT_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> {% if craft.app.env == 'production' and getenv('STICKYBEAK_SITE_ID') %} <script defer data-site="{{ getenv('STICKYBEAK_SITE_ID') }}" data-domain="example.com" src="https://app.usestickybeak.com/_cfw/s.js" ></script> {% endif %}craft.app.envis whateverCRAFT_ENVIRONMENTsays.
Live Preview shows your templates in an iframe, which Stickybeak doesn't count. Editors previewing entries won't show up.
Check it's working
Publish first, then follow Verify your install.
Track goals
- Clicks: add
data-goalto links and buttons in your templates. - Forms: with Freeform, Formie or a hand-built form, send people to a thank-you page after submitting.
See Custom goals.
Track purchases
After payment, Commerce sends the customer to the URL in your payment form's redirect input, with the order number in it (for example shop/checkout/complete?number={number}).
{% set order = craft.orders().number(craft.app.request.getQueryParam('number')).one() %}
{% if order and order.isCompleted %}
{% js %}
window.stickybeak("purchase", {
revenue: {{ order.totalPrice|number_format(2, '.', '') }},
currency: "{{ order.currency|e('js') }}",
order_id: "{{ order.number|e('js') }}"
});
{% endjs %}
{% endif %}
e('js') escapes values for a JavaScript string.
See Revenue.
If it isn't working
- Live Preview uses an iframe and is not counted. Check
CRAFT_ENVIRONMENT=productionand the server’s.env.
See Troubleshooting.