forked from Setono/SyliusAnalyticsPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeginCheckoutSubscriber.php
48 lines (38 loc) · 1.15 KB
/
BeginCheckoutSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace Setono\SyliusAnalyticsPlugin\EventListener;
use Setono\TagBag\Tag\GtagEvent;
use Setono\TagBag\Tag\GtagEventInterface;
use Setono\TagBag\Tag\GtagLibrary;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
final class BeginCheckoutSubscriber extends TagSubscriber
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => 'track',
];
}
public function track(RequestEvent $event): void
{
$request = $event->getRequest();
if (!$event->isMasterRequest() || !$this->isShopContext($request)) {
return;
}
if (!$request->attributes->has('_route')) {
return;
}
$route = $request->attributes->get('_route');
if ('sylius_shop_checkout_start' !== $route) {
return;
}
if (!$this->hasProperties()) {
return;
}
$this->tagBag->addTag(
(new GtagEvent(GtagEventInterface::EVENT_BEGIN_CHECKOUT))
->addDependency(GtagLibrary::NAME)
);
}
}