You are here

function hook_commerce_google_analytics_items_alter in Commerce Google Analytics 8

Alter all items array data for Ecommerce Tracking.

Parameters

array $item: An item array for Ecommerce Tracking to be altered.

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.

array $context: An array with the following keys:

  • transaction: transaction array.
  • order: The order.

See also

\Drupal\commerce_google_analytics\EventSubscriber\SendOrderAnalyticsSubscriber::buildGaPushParams()

1 invocation of hook_commerce_google_analytics_items_alter()
SendOrderAnalyticsSubscriber::buildGaPushParams in src/EventSubscriber/SendOrderAnalyticsSubscriber.php
Builds the Ecommerce Tracking data array needed by GA Push API for a given order.

File

./commerce_google_analytics.api.php, line 67
Hooks provided by the Commerce Google Analytics module.

Code

function hook_commerce_google_analytics_items_alter(array &$items, array $context) {

  // Remove the items.
  $items = [];

  /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
  $order = $context['order'];
  foreach ($order
    ->getItems() as $order_item) {

    // Rebuild the items with custom data.
    // ...
  }
}