Recommendations Twig functions¶
The following Twig functions are supported while using Raptor connector:
ibexa_tracking_script() function¶
ibexa_tracking_script() Twig function allows you to embed main tracking script into the website.
It loads the initial script into window.raptor, enabling events tracking, for example, page visits, product views, or buys, from the front-end.
It can be overridden in multiple ways to support custom implementations and to render code snippet through Ibexa in Design Engine.
Tracking can be conditionally initialized depending on cookie consent logic. By default, the function returns the script for client-side use, while it can return nothing when used server-side.
This function accepts the following parameters:
| Parameter | Type | Default value | Remarks |
|---|---|---|---|
customerId |
string | From SiteAccess configuration | Raptor account ID. Can be overridden for custom customer IDs. |
hasConsented |
boolean | false | Controls loading of tracking based on user consent at render time. |
Default setup:
1 | |
1 | |
Without setting custom customerId parameter, the function renders the tracking script using the configured customerID from the connector configuration.
It can be overridden by providing a custom value if needed.
If hasConsented is set to true in the template, the tracking script is initialized automatically.
This value should be set if user consent for tracking cookies is already known at render time.
If hasConsented parameter is set to false, tracking should be enabled by dispatching a custom JavaScript event after consent is granted, for example through a custom script in layout.
When set dynamically, avoid enabling the HTTP cache for users without consent.
The recommended method to integrate the tracking script with custom front-end logic is to dispatch the enableTracking JavaScript event after tracking cookie consent is granted:
1 | |
Note
In Symfony's debug mode, the provided script outputs diagnostic information to the console. This output is not included in production environment.
ibexa_tracking_track_event() function¶
The ibexa_tracking_track_event() function is responsible for sending event data to the service, enabling tracking of user interactions and behaviors.
Tracking is handled through twig function that accept following parameters:
1 2 3 4 5 6 | |
- eventType - type: string, defines the type of tracking event to be sent, for example,
visit,contentvisit,buy,basket,itemclick - data (optional) - type: mixed, accepts the primary object associated with the event, such as a Product or Content, can be null if not required. For more information, check tracking event examples.
- context (optional)- type: array, additional event data, such as quantity, basket details, or custom parameters. For more information, see example usage.
- template (optional) - type: string, path to a custom Twig template used to render the tracking event, allows overriding the default tracking output
Tracking events¶
The following events are supported and can be triggered from Twig templates:
Product visit event¶
This event tracks product page visits by users. It's the most common e-commerce tracking event used to capture product views for analytics, recommendation models, and user behavior processing.
Required data:
- Product object - defines the product being tracked. It implements
ProductInterfaceso the system can read its information (for example, ID, price, category).
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Content visit event¶
This event tracks content page visits by users. It can used to check content views for analytics, personalization, and user behavior tracking.
- Content object - defines the content being tracked.
Basket event¶
This event tracks when a product is added to the shopping basket.
It catches user interest and helps with conversion tracking and product recommendations.
Required data:
- Product object - defines the product being added to the basket.
- Context array with basket information - provides optional data about the basket, like quantity or basket ID, to provide context for the event.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Simplified example with Twig filter:
1 2 3 4 5 6 7 8 | |
Simplified example with Twig filter:
1 2 3 4 5 6 7 8 | |
context parameter - example usage¶
You can use context parameter to add additional data.
During tracking, for products assigned to multiple categories, the system uses the first category.
In this case, context parameter allows to override the product category by passing a category identifier:
1 2 3 4 5 6 7 8 9 10 11 | |
For another example of context parameter usage, see Basket event.
Custom Templates¶
You can override the default tracking templates by providing a custom template path:
1 2 3 4 5 6 | |