public function EventTrackerService::productImpressions in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 src/EventTrackerService.php \Drupal\commerce_google_tag_manager\EventTrackerService::productImpressions()
Track product impressions.
Parameters
\Drupal\commerce_product\Entity\ProductVariationInterface[] $product_variations: The commerce product variation entities being viewed.
string $list: The name of the list showing the products.
File
- src/
EventTrackerService.php, line 104
Class
- EventTrackerService
- Track different events from Google's Enhanced Ecommerce.
Namespace
Drupal\commerce_google_tag_managerCode
public function productImpressions(array $product_variations, $list = '') {
$products_data = array_map(function ($product_variation) use ($list) {
return array_merge($this
->buildProductFromProductVariation($product_variation)
->toArray(), [
'list' => $list,
]);
}, $product_variations);
$data = [
'event' => self::EVENT_PRODUCT_IMPRESSIONS,
'ecommerce' => [
'impressions' => $products_data,
],
];
$this->eventStorage
->addEvent($data);
}