You are here

public function KernelEventsSubscriber::onFinishRequest in Commerce Google Tag Manager 8.2

Same name and namespace in other branches
  1. 8 src/EventSubscriber/KernelEventsSubscriber.php \Drupal\commerce_google_tag_manager\EventSubscriber\KernelEventsSubscriber::onFinishRequest()

Tracks an Enhanced Ecommerce checkout event.

Parameters

\Symfony\Component\HttpKernel\Event\FinishRequestEvent $event: The request.

File

src/EventSubscriber/KernelEventsSubscriber.php, line 72

Class

KernelEventsSubscriber
Event handler for Kernel events.

Namespace

Drupal\commerce_google_tag_manager\EventSubscriber

Code

public function onFinishRequest(FinishRequestEvent $event) {
  if (!$this
    ->shouldTrackCheckout($event)) {
    return;
  }

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $this->routeMatch
    ->getParameter('commerce_order');
  if (!$order) {
    return;
  }
  $checkoutStepIndex = $this
    ->getCheckoutStepIndex($order);
  if ($checkoutStepIndex) {
    $this->eventTracker
      ->checkoutStep($checkoutStepIndex, $order);
  }
}