vendor/pimcore/customer-management-framework-bundle/src/Targeting/EventListener/SegmentTrackedListener.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace CustomerManagementFrameworkBundle\Targeting\EventListener;
  16. use CustomerManagementFrameworkBundle\ActionTrigger\Event\SegmentTracked;
  17. use Pimcore\Analytics\Piwik\Tracker;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. class SegmentTrackedListener implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var Tracker
  23.      */
  24.     private $piwikTracker;
  25.     public function __construct(Tracker $piwikTracker)
  26.     {
  27.         $this->piwikTracker $piwikTracker;
  28.     }
  29.     /**
  30.      * @inheritDoc
  31.      */
  32.     public static function getSubscribedEvents()
  33.     {
  34.         return [
  35.             SegmentTracked::EVENT_NAME => 'onSegmentTracked'
  36.         ];
  37.     }
  38.     public function onSegmentTracked(SegmentTracked $event)
  39.     {
  40.         $this->piwikTracker->addCodePart(sprintf(
  41.             "_paq.push(['trackEvent', 'CMF.SegmentTracked', '%d', '%d']);",
  42.             $event->getSegment()->getId(),
  43.             $event->getCount()
  44.         ));
  45.     }
  46. }