Mastering the DataLayer

The dataLayer is the single source of truth for your analytics implementation. It decouples your marketing tags from the underlying application code, allowing you to scale without breaking your tags.

What is a DataLayer?

Think of it as a virtual layer that sits between your website and your tag manager (like Google Tag Manager). Whenever a user performs an action—like adding an item to their cart—your website "pushes" information about that action into the dataLayer.

Try it yourself!

Use the interactive simulator below to see exactly how these payloads look when they are pushed. Click the buttons on the left to trigger common e-commerce events.

DataLayer Simulator
Trigger Event
Trigger an event to see the payload
## Common Event Types ### `view_item` Fires when a user views a product details page. It should contain the product name, ID, price, and category. ### `add_to_cart` Crucial for tracking intent. This event triggers when a user adds a product to their shopping bag. ### `purchase` The most important event. It requires a `transaction_id` and the total `value` of the order. --- > [!TIP] > Always ensure your currency codes and values are formatted correctly as strings (for ISO 4217 codes) and numbers (for values) to avoid GA4 processing issues.