1. Go to this page and download the library: Download tourze/user-track-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Tourze\UserEventBundle\Event\UserInteractionEvent;
// This event will be automatically recorded
$event = new UserInteractionEvent($sender, $systemUser, 'user.login');
$eventDispatcher->dispatch($event);
use Tourze\UserEventBundle\Event\UserInteractionEvent;
use Tourze\UserTrackBundle\Event\TrackContextInterface;
class ProductViewEvent extends UserInteractionEvent implements TrackContextInterface
{
/** @var array<string, mixed> */
private array $trackParams = [];
public function __construct($user, $product)
{
parent::__construct($user, $systemUser, 'product.view');
$this->setTrackingParams([
'product_id' => $product->getId(),
'category' => $product->getCategory(),
'price' => $product->getPrice()
]);
}
/**
* @return array<string, mixed>
*/
public function getTrackingParams(): array
{
return $this->trackParams;
}
/**
* @param array<string, mixed> $params
*/
public function setTrackingParams(array $params): void
{
$this->trackParams = $params;
}
}
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Tourze\UserTrackBundle\Event\TrackLogReportEvent;
class TrackLogResponseEnricher implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
TrackLogReportEvent::class => 'onTrackLogReport',
];
}
public function onTrackLogReport(TrackLogReportEvent $event)
{
$result = $event->getResult();
$result['tracking_id'] = $event->getTrackLog()->getId();
$event->setResult($result);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.