Purchase
Reports that the user completed a purchase.
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 "purchase-v1". | String |
value | The total monetary value of the event (the total cart purchased, not just the item that triggered the event); in the actual payment currency. | 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 |
uniqueTransactionId Optional, but recommended | When this value is passed it ensures that only one purchase is recorded for the transaction ID, even if duplicate events are reported. | String Maximum of 64 characters |
cart | The cart's absolute current state. Products are ordered from the first added to the cart to the most recent. | 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: "Purchase", // Human-readable name, not used to identify an event type
properties: {
uniqueTransactionId: "123456", // Will remove redundant events. Must be a string. Max 64 characters.
dyType: "purchase-v1", // Identifies this event as a purchase
value: 90.55, // Total cart value in actual payment currency, as float (dollars dot cents)
currency: "any supported currency code", // Optional non-default currency used
cart: [
// itemPrice is per quantity of one, and in the same format as the total "value":
// float of dollars.cents in the payment currency (which is only defined once above)
{
productId: "item-34454", // SKU exactly as in the product feed!
quantity: 1,
itemPrice: 65.87,
size: "XL" // Size is *optional and a customer-specific string*
}, {
productId: "sku-4324-bg",
quantity: 2,
itemPrice: 12.34,
size: "M"
}
]
}
});
Example: Implementation via Experience API (server-side)
"events":[{
name: "Purchase",
properties: {
dyType: "purchase-v1",
value: 349.80,
uniqueTransactionId: "exampleTransactionId",
cart: [
{
productId: "p-tv78615a",
quantity: 1,
itemPrice: 249.90,
},
{
productId: "p-cr91275g",
quantity: 2,
itemPrice: 49.95
}
]
}
} ]
Go to the API reference for the Events endpoint to learn more.
Updated 7 months ago