Exponea Event
Exponea Event Service
Description
- Purpose: Provides a privacy-compliant analytics integration with Exponea, focused on tracking product views and cart interactions in an e-commerce platform.
- Functionality Includes:
- Data transformation of product and trolley structures.
- Tracking user interactions such as product views and cart updates.
- Conditional tracking based on cookie consent.
- Tracking is only executed client-side, never on the server.
Utility Functions
transformProductData(productData: Product)- Description: Transforms a product object into a format compatible with Exponea's view_item tracking event.
- Includes Data Fields:
id,name,brand,category,currency,price,image.- Category hierarchy (level 1β3).
- Out-of-stock delivery status.
- User's current language and page URL.
transformProductDataV2(productData: Product, quantity: number = 1)- Description:
- A variant of the transformer used for cart-level analytics, providing more granular pricing and quantity details.
- Includes Data Fields:
item_id,title,brand,category,channel,delivery_method.item_price,item_price_exc_tax,discount_value,quantity.total_price,trolley_channel, andslug.
- Description:
Event Tracking Function
trackExponeaEvent(eventName, eventData, debug = false)- Description: Generic wrapper for sending events to Exponea, with built-in cookie consent checks and event-specific data handling.
- Parameters:
eventName (string)β Name of the event (e.g., "view_item", "cart_update").eventData (object)β Payload to be sent; transformed if needed.debug (boolean)β Optional flag to log the event payload in the console.
- Behavior:
- Checks if Analytical cookies are accepted via OneTrust.
- Executes only in browser environment.
- Automatically transforms product data for "
view_item" events. - Logs warnings if tracking is attempted on the server or if Exponea is unavailable.
Trolley Tracking Function
postTrolleyUpdate(actionType: string, line: TrolleyLineItem)- Description: Collects cart metrics and sends a "cart_update" event to Exponea with a breakdown of items, prices, and totals.
- Steps:
- Dynamically imports the trolley store to access the user's current cart.
- Uses transformProductDataV2 to shape the updated product line.
- Aggregates cart-wide metrics:
total_price,total_tax,total_quantityproduct_listfor minimal item summary
- Creates a full tracking object via computed(), including:
- Cart metadata:
currency,discount,promo code, delivery mode - Action type: e.g.,
add,remove,update - Detailed item information
- Cart metadata:
- Sends the event using trackExponeaEvent("
cart_update",data).
- Parameters:
actionType: Describes the userβs cart action (e.g., add, remove).line: The individual product line in the trolley being updated.
Conclusion
- Provides a robust and privacy-aware integration with Exponea for e-commerce behavior tracking.
- Ensures data is well-structured and consistent with analytics needs.
- Adheres to client-side execution only, safeguarding SSR environments.
- Built with modularity and type safety in mind using TypeScript.