add_to_cart Event
The add_to_cart
event is a core ecommerce tracking event. It captures a moment when a user adds a product to their shopping cart. This data is essential for understanding shopping behavior, funnel performance, and dynamic remarketing.
The add_to_cart model
The event model defines all properties needed to describe a user action of adding a product to the cart. This includes user and session identifiers, product-level metadata, pricing details, and optional hashed user data for privacy-safe matching.
Properties
- Name
event
- Type
- string
- Description
Must be set to
add_to_cart
.
- Name
user_id
- Type
- string
- Description
Unique identifier for the user performing the action.
- Name
session_id
- Type
- string
- Description
Unique identifier for the user's current session.
- Name
ecommerce.currency
- Type
- string
- Description
Currency code (ISO 4217), e.g.,
USD
.
- Name
ecommerce.value
- Type
- float
- Description
Total value of the added items (after discount).
- Name
ecommerce.tax
- Type
- float
- Description
Tax value applied to the items.
- Name
ecommerce.items
- Type
- array
- Description
Array of item objects that were added to the cart.
- Name
ecommerce.items[].item_id
- Type
- string
- Description
SKU or product ID.
- Name
ecommerce.items[].item_name
- Type
- string
- Description
Product name.
- Name
ecommerce.items[].item_brand
- Type
- string
- Description
Brand or manufacturer name.
- Name
ecommerce.items[].item_category
- Type
- string
- Description
Main category the product belongs to.
- Name
ecommerce.items[].item_variant
- Type
- string
- Description
Specific variant info such as color, size, or edition.
- Name
ecommerce.items[].price
- Type
- float
- Description
Original item price.
- Name
ecommerce.items[].discount
- Type
- float
- Description
Discount applied to the item.
- Name
ecommerce.items[].tax
- Type
- float
- Description
Tax on this specific item.
- Name
ecommerce.items[].quantity
- Type
- int
- Description
Number of units added.
- Name
user_data.external_id
- Type
- string
- Description
Optional external user identifier for cross-system mapping.
- Name
user_data.email_hash
- Type
- string
- Description
Hashed email (SHA-256, lowercase, trimmed).
- Name
user_data.phone_hash
- Type
- string
- Description
Hashed phone (SHA-256, lowercase, trimmed).
Push event to the dataLayer
Here is an example of how to structure and push the add_to_cart
event to the dataLayer:
dataLayer.push example
dataLayer.push({
event: 'add_to_cart',
user_id: '12345678-abcd-1234-efgh-1234567890ab',
session_id: 'abcd1234-efgh-5678-ijkl-0987654321zx',
ecommerce: {
currency: 'USD',
value: 49.99,
tax: 4.00,
items: [
{
item_id: 'SKU-00123',
item_name: 'GlowMaster Smart Lamp',
item_brand: 'LumaTech',
item_category: 'Home & Living',
item_variant: 'Matte Black',
price: 59.99,
discount: 10.00,
tax: 4.00,
quantity: 1
}
]
},
user_data: {
external_id: '12345678-abcd-1234-efgh-1234567890ab',
email_hash: 'abc123examplehashedemail0987',
phone_hash: 'def456examplehashedphone6543'
}
});
Best Practices
- Fire this event immediately upon item addition, not on confirmation.
- Ensure hashes use SHA-256 and are pre-processed (trimmed + lowercase).
- Always include
currency
andvalue
fields. - Use GTM's Custom Event trigger to listen for
add_to_cart
events.
Use Cases
This add_to_cart
implementation supports:
- Funnel and drop-off tracking
- Product-level conversion optimization
- Dynamic remarketing campaigns
- Cross-channel audience segmentation
Let us know if you'd like to add server-side examples, GTM setup steps, or Pixel integrations!