Event tracking
Learn how to track events for analysis and personalization.
Events track user interactions with your application, such as button clicks, content views, purchases, and more. They feed the personalization engine and help you measure how users interact with your application and track conversions.
The following sections provide examples of how you can use the Symfony SDK to track these events in your application.
Basic usage
To track an event, call the track method with the event name and its properties. Because tracking runs in the browser, you invoke it from your templates with the croct Twig filter, which runs the snippet once the SDK has loaded.
For example, to track a conversion when a user places an order:
{% extends 'base.html.twig' %}
{% block body %} <button id="place-order">Place order</button>
{% apply croct %} const button = document.getElementById('place-order');
button.addEventListener('click', () => { croct.track('goalCompleted', {goalId: 'paymentApproved'}); }); {% endapply %}{% endblock %}For the events worth tracking and their payloads, see the recommended events, and the Events reference for the complete list.