vendor/elements/tracking-bundle/src/EventSubscriber/SessionBagSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace Elements\Bundle\TrackingBundle\EventSubscriber;
  3. use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\KernelEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class SessionBagSubscriber implements EventSubscriberInterface
  8. {
  9.     private $pimcoreVersion;
  10.     public function __construct($pimcoreVersion)
  11.     {
  12.         $this->pimcoreVersion $pimcoreVersion;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             //run after Symfony\Component\HttpKernel\EventListener\SessionListener
  18.             KernelEvents::REQUEST => ['onKernelRequest'127],
  19.         ];
  20.     }
  21.     /**
  22.      * @param KernelEvent $event
  23.      */
  24.     public function onKernelRequest(KernelEvent $event)
  25.     {
  26.         //this will only work in pimcore X -> see SessionGa4Configurator.php for pim 6
  27.         if ($this->pimcoreVersion >= 10) {
  28.             //for deprecation issues
  29.             if (method_exists($event'isMainRequest')) {
  30.                 $isMainRequest $event->isMainRequest();
  31.             } else {
  32.                 $isMainRequest $event->isMasterRequest();
  33.             }
  34.             if (!$isMainRequest) {return;}
  35.             $session $event->getRequest()->getSession();
  36.             $bag = new AttributeBag('_session_ga4');
  37.             $bag->setName('session_ga4');
  38.             $session->registerBag($bag);
  39.         }
  40.     }
  41. }