Skip to content
9 changes: 6 additions & 3 deletions code_samples/recommendations/EventMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Tracking;

use Ibexa\Contracts\ConnectorRaptor\Tracking\EventContext;
use Ibexa\Contracts\ConnectorRaptor\Tracking\EventMapperInterface;
use Ibexa\Contracts\ConnectorRaptor\Tracking\EventType;
use Ibexa\Contracts\ConnectorRaptor\Tracking\ServerSideTrackingDispatcherInterface;
Expand All @@ -15,10 +16,12 @@ public function __construct(
) {
}

public function trackProductView(ProductInterface $product, string $url): void
public function trackProductView(ProductInterface $product): void
{
// Map product to VisitEventData automatically
$eventData = $this->eventMapper->map(EventType::VISIT, $product);
// Map product to VisitEventData automatically, override its category
$eventData = $this->eventMapper->map(EventType::VISIT, $product, [
EventContext::CATEGORY_IDENTIFIER => 'electronics',
]);

// Send tracking event
$this->trackingDispatcher->dispatch($eventData);
Expand Down
Loading
Loading