Example module (kixenrichdemo)

The kixenrichdemo module is a minimal, working example of item enrichment via the actionKixellTagEnrichItems hook. You can reuse it as a starting point.

1. Register the hook

On installation, the module subscribes to the hook:

public function install()
{
    return parent::install() && $this->registerHook('actionKixellTagEnrichItems');
}

2. Implement the hook

The method enriches the items for list pages, product pages and the purchase funnel, and returns early for other events. You can thus enrich view_item_list, view_item and select_item as well as cart and order events:

public function hookActionKixellTagEnrichItems(array $params)
{
    try {
        $event = isset($params['event']) ? $params['event'] : null;
        if (empty($event)) {
            return;
        }

        $enriched_events = [
            'view_item_list',
            'view_item',
            'select_item',
            'add_to_cart',
            'remove_from_cart',
            'view_cart',
            'begin_checkout',
            'checkout_address',
            'checkout_shipping',
            'checkout_payment',
            'purchase',
        ];

        if (!in_array($event, $enriched_events, true)) {
            return; // event not handled: no item is iterated
        }

        if (empty($params['items']) || !is_array($params['items'])) {
            return;
        }

        $id_cart = isset($params['id_cart']) ? $params['id_cart'] : null;
        $id_order = isset($params['id_order']) ? $params['id_order'] : null;

        foreach ($params['items'] as $item) {
            if (!is_object($item)) {
                continue;
            }
            // Any non-null public property added here ends up in the GA4 item.
            $item->enrich_id_product = isset($item->item_id_product) ? $item->item_id_product : null;
            $item->enrich_id_variant = isset($item->item_id_variant) ? $item->item_id_variant : null;
            $item->enrich_id_cart    = $id_cart;
            $item->enrich_id_order   = $id_order;
            $item->enrich_label      = $event;
        }
    } catch (Exception $e) {
        // Never let an exception break the dataLayer build.
    }
}

3. Check that the hook fires

The demo module logs each call in a daily file kixenrichdemo-YYYY-MM-DD.log, which lets you confirm the hook is indeed called and inspect what it receives:

14:22:01 event=add_to_cart items=1 id_shop=1 id_cart=42 id_order=-
14:23:17 event=purchase items=3 id_shop=1 id_cart=42 id_order=KX-100245

You can then check the result in the browser's dataLayer: the added fields (enrich_id_product, enrich_label, …) appear within each item of the relevant event.

Replace with your business data

In the loop, replace the example fields with your own business data — for example vehicle, circuit, surface, texture… from your database:

$item->vehicle = $this->getVehicle((int) $item->item_id_product);
$item->circuit = $this->getCircuit((int) $item->item_id_product);
$item->surface = $this->getSurface((int) $item->item_id_product);
$item->texture = $this->getTexture((int) $item->item_id_product);

These values will be available in Google Tag Manager and usable in your tags and audiences.