Server-side enrichment
A PrestaShop module can add your business data to each dataLayer product, on the server, with the actionKixellTagEnrichItems hook.
Use this hook when the data to add comes from your database or from another module: margin, stock, supplier, customer score. For a PrestaShop attribute group or custom field, the DataLayer item enrichment tab of the Google Tag Manager tile is enough, with no code: see Google Tag Manager. The hook has been available since version 4.4.2 of the module.
How it works #
- Kixell Tag builds the products (
items) of an e-commerce event. - It calls the hook with these products and the name of the GA4 event.
- Your module adds public properties to the objects it receives. It returns nothing.
- Kixell Tag keeps each added, non-null property: it goes into the dataLayer product, all the way to GA4.
The hook call #
Hook::exec('actionKixellTagEnrichItems', [
'items' => $items, // KDataLayerItem[]: change them in place
'event' => $event, // GA4 event: view_item, add_to_cart, purchase…
'id_shop' => $id_shop, // int
'id_cart' => $id_cart, // int, 0 with no cart
'id_order' => $id_order, // string|null: only on purchase
]);
| Parameter | Type | Content |
|---|---|---|
items |
KDataLayerItem[] |
The event's products. Change them in place, by adding public properties |
event |
string |
The current GA4 event. Only enrich the ones you need |
id_shop |
int |
The current shop, useful in multistore |
id_cart |
int |
The visitor's cart, 0 if they have none. On purchase, the order's cart |
id_order |
string|null |
On purchase only: the order ID, or several separated by a comma if the cart led to several orders |
Events passed #
| Event | When |
|---|---|
view_item_list |
When list pages and the home page load, then for the products loaded later in a list |
view_item |
When a product page loads |
select_item |
On a click on a product in a list |
add_to_cart, remove_from_cart |
When a product is added to or removed from the cart |
up_quantity_from_cart, down_quantity_from_cart |
When a quantity changes in the cart |
view_cart |
When the cart page loads |
begin_checkout, checkout_address, checkout_shipping, checkout_payment |
When each checkout step loads |
purchase |
At the order confirmation |
add_shipping_info, add_payment_info and purchase_groups do not go through the hook: they reuse the products of their page, already enriched.
Rules #
- Add a public property to each product, for example
$item->margin = 12.5;. - A property left at
nullis removed before sending. - To find the product in your database, read
item_id_productanditem_id_variant. The other fields are listed in The e-commerce dataLayer. - Return at once (
return) for the events you do not handle: no product is looped over, at no cost. - Wrap your code in a
try/catch: an exception must never break the dataLayer build. - Do not add any personal data: the dataLayer products go to your platforms.
The hook runs on the server, but its data only reaches your tags through the dataLayer, in line with consent.
The full code of a demo module is in Example module (kixenrichdemo).
Missing or wrong information? Tell the support team