You are here

public function EventTrackerService::checkoutStep in Commerce Google Tag Manager 8.2

Same name and namespace in other branches
  1. 8 src/EventTrackerService.php \Drupal\commerce_google_tag_manager\EventTrackerService::checkoutStep()

Track a checkout step.

Parameters

int $step_index: The index of the checkout step (1-based).

\Drupal\commerce_order\Entity\OrderInterface $order: The commerce order representing the cart.

File

src/EventTrackerService.php, line 224

Class

EventTrackerService
Track different events from Google's Enhanced Ecommerce.

Namespace

Drupal\commerce_google_tag_manager

Code

public function checkoutStep($step_index, OrderInterface $order) {
  $data = [
    'event' => self::EVENT_CHECKOUT,
    'ecommerce' => [
      'checkout' => [
        'actionField' => [
          'step' => $step_index,
        ],
        'products' => $this
          ->buildProductsFromOrderItems($order
          ->getItems()),
      ],
    ],
  ];
  $this->eventStorage
    ->addEvent($data);

  // Throw an event to add possible checkout step options by event listeners.
  $event = new TrackCheckoutStepEvent($step_index, $order);
  $this->eventDispatcher
    ->dispatch(EnhancedEcommerceEvents::TRACK_CHECKOUT_STEP, $event);
}