Skip to content

Latest commit

 

History

History
72 lines (49 loc) · 5.79 KB

File metadata and controls

72 lines (49 loc) · 5.79 KB
description Tracking with PHP API.
month_change true

Tracking with PHP API

You can interact directly with the Raptor connector's service using the PHP API for advanced tracking usage.

Advanced usage – direct interaction with the service

The ServerSideTrackingDispatcherInterface::dispatch() method allows to send tracking data from the server side. It can be used in controllers, event subscribers, or any other part of the application. This method receives an EventDataInterface. For more information, see the available events in the tracking event namespace.

Mapping event data

The recommended method is EventMapperInterface::map(). This method receives an EventType case, a data depending on the event type (a ProductInterface, a Content, or a string), and a context's associative array that uses EventContext constants as keys.

For more information, see the same arguments of the Twig function ibexa_tracking_track_event.

Event type Data class Context keys
EventType::VISIT ProductInterface (optional) EventContext::CATEGORY_IDENTIFIER,
(optional) EventContext::WEBSITE_ID
EventType::CONTENT_VISIT Content (optional) EventContext::WEBSITE_ID
EventType::BUY ProductInterface EventContext::SUBTOTAL,
EventContext::CURRENCY,
EventContext::QUANTITY,
(optional) EventContext::CATEGORY_IDENTIFIER,
(optional) EventContext::WEBSITE_ID
EventType::BASKET ProductInterface EventContext::BASKET_CONTENT,
EventContext::BASKET_ID,
(optional) EventContext::CATEGORY_IDENTIFIER,
(optional) EventContext::QUANTITY,
(optional) EventContext::WEBSITE_ID
EventType::ITEM_CLICK string (product code) EventContext::MODULE_NAME,
EventContext::REDIRECT_URL
EventType::PAGEVIEW string (URL) EventContext::URL (required),
(optional) EventContext::WEBSITE_ID

Check the following example:

[[= include_file('code_samples/recommendations/EventMapper.php', 4, 8) =]]//…

[[= include_file('code_samples/recommendations/EventMapper.php', 20, 27, remove_indent=True) =]]

Manual EventData creation

Manual creation of EventData allows precise control over the events sent to the service. It enables you to define custom event parameters, track specific user interactions, and tailor data collection to advanced use cases.

Check the following example:

[[= include_file('code_samples/recommendations/EventData.php', 4, 6) =]]// …

[[= include_file('code_samples/recommendations/EventData.php', 17, 26, remove_indent=True) =]]

categoryPath parameter sets the category path for recommendations and needs to be composed manually following the specified format and rules:

  • format: CategoryId#CategoryName;CategoryId#CategoryName, for example, 25#Electronics;26#Smartphones
  • if CategoryName is missing, repeat the ID, for example, 25#25;26#26
  • if CategoryId is missing, use the CategoryName, for example, Electronics;Smartphones

For more information, see the available events in the tracking event namespace.

Example - event subscriber

If you need to track events automatically based on application events, you can use an event subscriber. It reacts to specific events in the application and triggers tracking logic without the need to add it manually in templates.

[[= include_file('code_samples/recommendations/EventSubscriber.php') =]]

You can also use [[= product_name =]] events, for example CreateOrderEvent from Order management events. For more information, see Event reference.