You are here

public function EventTrackerService::productClick in Commerce Google Tag Manager 8

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

Track a "product click" event.

Parameters

array $product_variations: A commerce product variation that was clicked.

string $list: An optional name of a list.

File

src/EventTrackerService.php, line 151

Class

EventTrackerService
Track different events from Google's Enhanced Ecommerce.

Namespace

Drupal\commerce_google_tag_manager

Code

public function productClick(array $product_variations, $list = '') {
  $data = [
    'event' => self::EVENT_PRODUCT_CLICK,
    'ecommerce' => [
      'click' => [
        'actionField' => [
          'list' => $list,
        ],
        'products' => $this
          ->buildProductsFromProductVariations($product_variations),
      ],
    ],
  ];
  $this->eventStorage
    ->addEvent($data);
}