public function CommerceEventsSubscriber::trackProductView in Commerce Google Tag Manager 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/CommerceEventsSubscriber.php \Drupal\commerce_google_tag_manager\EventSubscriber\CommerceEventsSubscriber::trackProductView()
Track the "productView" event.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The event to view the product.
File
- src/
EventSubscriber/ CommerceEventsSubscriber.php, line 77
Class
- CommerceEventsSubscriber
- Event handler for commerce related events.
Namespace
Drupal\commerce_google_tag_manager\EventSubscriberCode
public function trackProductView(GetResponseEvent $event) {
$product = $this->routeMatch
->getParameter('commerce_product');
if ($event
->getRequest()
->getMethod() === 'GET' && !empty($product) && $this->routeMatch
->getRouteName() === 'entity.commerce_product.canonical') {
$default_variation = $product
->getDefaultVariation();
if ($default_variation) {
$this->eventTracker
->productDetailViews([
$default_variation,
]);
}
}
}