Add to Cart
Reports that the user added a product to the cart.
Required for e-commerce sections.
Parameters
- name: Human-readable name, not used to identify an event type
- properties: A container for the event properties as specified in the following table:
Property | Description | Type |
---|---|---|
dyType | Must be "add-to-cart-v1". | String |
value | The total monetary value of the event (item or items added that triggered the event only). Note that this is not all the items in the cart. See the code example that follows after this table (productId "item-34454", quantity 2, itemPrice 59.13: Value is 118.26. The other item in the cart is not included.) | Float (dollars.cents). Numbers are rounded to the nearest 0.01. Numbers smaller than 0.005 are rounded down to 0. |
currency Optional, but required for multi-currency sites | The currency used for the value | String List of supported currencies |
productId | The SKU exactly as it appears in the product feed | String |
quantity | The total number of items that were added to cart | Number |
cart Optional, but recommended | The cart's current state, including the last item added. Products are ordered from the first added to the cart to the most recent. Note: Pass the updated cart with the newly added product to ensure that the cart state is fully in sync with your system. This is important mainly for triggered email and push notifications. | Object See the cart property table that follows for details. |
Cart object properties:
Property | Description | Type |
---|---|---|
productId | SKU exactly as it appears in the product feed | String |
quantity | Number of items | Number |
itemPrice | The price of the item added | Float in the format: dollars.cents |
Example: Implementation via script
DY.API("event", {
name: "Add to Cart",
properties: {
dyType: "add-to-cart-v1",
value: 118.26,
currency: "any supported currency code",
productId: "item-34454",
quantity: 2,
size: "XL",
cart: [{
productId: "sku-4324-bg",
quantity: 2,
itemPrice: 12.34,
},
{
productId: "item-34454",
quantity: 2,
itemPrice: 59.13
}
]
}
});
Example: Implementation via Experience API (server-side)
"events":[
{
name: "Add to Cart",
properties: {
dyType: "add-to-cart-v1",
value: 198.00,
productId: "p-tv78615a",
quantity: 2,
cart: [
{
productId: "p-cr91275g",
quantity: 1,
itemPrice: 49.95
},
{
productId: "p-tv78615a",
quantity: 2,
itemPrice: 99.00,
}
]
}
}
]> 👍 Required for e-commerce sections.
### Parameters
- **name:** Human-readable name, not used to identify an event type
- **properties:** A container for the event properties as specified in the following table:
[block:parameters]
{
"data": {
"h-0": "Property",
"h-1": "Description",
"h-2": "Type",
"0-0": "**dyType**",
"0-1": "Must be \"add-to-cart-v1\".",
"0-2": "String",
"1-0": "**value**",
"1-1": "The total monetary value of the event (item or items added that triggered the event only).<br><span style=\"color:gray; font-size:0.8em;\">Note that this is not all the items in the cart. See the code example that follows after this table (productId \"item-34454\", quantity 2, itemPrice 59.13: Value is 118.26. The other item in the cart is not included.)</span>",
"1-2": "Float (dollars.cents). \n<br><span style=\"color:gray; font-size:0.8em;\">Numbers are rounded to the nearest 0.01. Numbers smaller than 0.005 are rounded down to 0.</span>",
"2-0": "**currency \n**<br><span style=\"color:gray; font-size:0.8em;\">Optional, but required for multi-currency sites</span>",
"2-1": "The currency used for the value",
"2-2": "String<br><span style=\"font-size:0.8em;\">[List of supported currencies](https://support.dynamicyield.com/hc/en-us/articles/360022558254#h_01F248KMJV1VWADRC2H7WYFWCZ)</span>",
"3-0": "**productId**",
"3-1": "The SKU exactly as it appears in the product feed",
"3-2": "String",
"4-0": "**quantity**",
"4-1": "The total number of items that were added to cart",
"4-2": "Number",
"5-0": "**cart**<br><span style=\"color:gray; font-size:0.8em;\">Optional, but recommended</span>",
"5-1": "The cart's current state, including the last item added. Products are ordered from the first added to the cart to the most recent. \n \n**Note:** _Pass the updated cart with the newly added product to ensure that the cart state is fully in sync with your system. This is important mainly for triggered email and push notifications._",
"5-2": "Object \n \nSee the cart property table that follows for details."
},
"cols": 3,
"rows": 6,
"align": [
"left",
"left",
"left"
]
}
[/block]
**Cart object properties:**
| Property | Description | Type |
| :------------ | :-------------------------------------------- | :--------------------------------- |
| **productId** | SKU exactly as it appears in the product feed | String |
| **quantity** | Number of items | Number |
| **itemPrice** | The price of the item added | Float in the format: dollars.cents |
**Example: Implementation via script **
```javascript
DY.API("event", {
name: "Add to Cart",
properties: {
dyType: "add-to-cart-v1",
value: 118.26,
currency: "any supported currency code",
productId: "item-34454",
quantity: 2,
size: "XL",
cart: [{
productId: "sku-4324-bg",
quantity: 2,
itemPrice: 12.34,
},
{
productId: "item-34454",
quantity: 2,
itemPrice: 59.13
}
]
}
});
```
**Example: Implementation via Experience API (server-side)**
```json
"events":[
{
name: "Add to Cart",
properties: {
dyType: "add-to-cart-v1",
value: 198.00,
productId: "p-tv78615a",
quantity: 2,
cart: [
{
productId: "p-cr91275g",
quantity: 1,
itemPrice: 49.95
},
{
productId: "p-tv78615a",
quantity: 2,
itemPrice: 99.00,
}
]
}
}
]
```
Go to the API reference for the Events endpoint to learn more.
Updated 10 months ago