Backends

Symfony
Symfony 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
Add a Twig global
Copy the ID from Settings in the dashboard and set it as
STICKYBEAK_SITE_IDin production (a real environment variable, or.env.prod.local).twig: globals: stickybeak_site_id: '%env(default::STICKYBEAK_SITE_ID)%'Add it to your base template
Put this inside
<head>, before</head>:<script>window.stickybeak = window.stickybeak || function () { (window.stickybeak.q = window.stickybeak.q || []).push(arguments); };</script> {% if app.environment == 'prod' and stickybeak_site_id %} <script defer data-site="{{ stickybeak_site_id }}" data-domain="example.com" src="https://app.usestickybeak.com/_cfw/s.js" ></script> {% endif %}
Check it's working
Deploy first.
See Verify your install.
Track goals
Give any button or link a data-goal attribute. See Custom goals.
<a href="{{ path('pricing') }}" data-goal="view_pricing">Pricing</a>
Fire a goal after a redirect
In the controller, add the goal as a flash message of its own type, then redirect:
$this->addFlash('stickybeak_goal', ['name' => 'signup', 'props' => ['plan' => $user->getPlan()]]);
return $this->redirectToRoute('app_dashboard');
Read that type in base.html.twig, below the queue line. Reading flashes removes them, so a refresh doesn't fire the goal again.
{% set js_flags = constant('JSON_HEX_TAG') b-or constant('JSON_HEX_AMP') b-or constant('JSON_HEX_APOS') b-or constant('JSON_HEX_QUOT') %}
{% for goal in app.flashes('stickybeak_goal') %}
<script>window.stickybeak({{ goal.name|json_encode(js_flags)|raw }}, {{ (goal.props ?? {})|json_encode(js_flags)|raw }});</script>
{% endfor %}
If your layout prints every flash with {% for label, messages in app.flashes %}, it will print the goal too (and use it up).
Track purchases
$this->addFlash('stickybeak_goal', [
'name' => 'purchase',
'props' => ['revenue' => $order->getTotal(), 'currency' => $order->getCurrency(), 'order_id' => $order->getReference()],
]);
See Revenue.
Page changes
With Turbo Drive, normal visits that push a different path are counted with no extra code.
If it isn't working
- Do not render the Stickybeak flash as a visible message; read it first or restrict the displayed flash types.
See Troubleshooting.