Cart analysis: Use object arrays to drive behavioral insights
Amplitude Academy
Analyze Product Purchases with Cart Analysis
Learn to use object arrays to analyze product purchases.
Get startedThe cart analysis feature lets you analyze data sent as object arrays. This is useful for behavioral insights into e-commerce transaction and shopping cart flows. You can analyze search results or cart events in the aggregate (for example, total order volume or co-occurrence), or segment your analyses by dimensions such as brand, category, price, or SKU.
After setup, you can access and analyze these object arrays from within your chart.
Common use cases include:
- Product performance (volume) by attribute (SKU, category, brand).
- Conversion rates by product type (or another attribute).
- Top-performing product combinations that reveal opportunities for cross-selling.
- Revenue and business outcomes performance by item or product.
- Average basket size or item count.
Cart Analysis is available for Amplitude's Event Segmentation and Funnel Analysis charts.
Terms and concepts
Here's a brief overview of the most important ideas behind cart analysis:
- Object array: A data format that stores a collection of distinct objects under a single name. In an Amplitude context, the array itself acts as an event or user property, while the objects it contains are item-specific attributes or properties. In the example below,
productsis the object array that holds two distinct objects.
{
"products": [
{
"product_id": 1,
"sku": "45360-32",
"name": "Special Facial Soap",
"category": "beauty",
"price": 12.6
},
{
"product_id": 5,
"sku": "47738-11",
"name": "Fancy Hairbrush",
"category": "beauty",
"price": 18.9
}
]
}
- Parent property: The top-level event or user property that contains an array of objects. In the example above, this is
products. - Child property (or item property): The nested attributes within the array of objects. Amplitude splits these out for its analyses. In the example above,
skuandpriceare two examples of child properties. Child properties are limited to one level of nesting. - Sibling property: Two or more child properties tied to the same parent event or user property. In the example above,
skuandpriceare sibling properties. - Property splitting: The processing method Amplitude uses to split out nested child properties from parent properties in your data, after ingestion. The property splitting process preserves the parent properties.
Child property limits
Child properties count toward your Event Property limit of 2000.
For advanced cart analysis operations on arrays of data, you can also use parallel operators in derived properties. These operators let you perform calculations like sums, products, and comparisons across sibling properties within the same parent array.
Set up property splitting
Enable property splitting before you use object arrays for cart analysis. Complete the process in Amplitude Data.
Only project managers and admins can enable splitting. Portfolio projects don't support splitting.
Amplitude recommends that you enable both the amplitude.Revenue() and product array tracking methods to get the most information possible.
To enable property splitting, follow these steps:
- Open Amplitude Data.
- Find the event or user property you want to use as a parent property and select it. (In the example above, this is
products.)
If you use Amplitude Data, you may need to add the event you want to track to your tracking plan.
- In the property drawer, set
TypetoArrayand setItem typetoAny. The Splitting tab appears on the right. - If Amplitude has seen or ingested the property at least once before, Amplitude shows a preview of what the splitting process delivers. Click Start Splitting to begin.
To stop splitting, go to the Splitting tab and click Stop Splitting.
This change takes effect for any net new data ingestion. Data persists for previously split events.
Send the cart object array
You have two options for sending the cart object array. The first is to use either the set() or append() method with the Identify API.
const identifyEvent = new amplitude.Identify();
// can use either set() or append()
identifyEvent.append("products", [
{
product_id: 123,
sku: "41245",
name: "Sunscreen",
},
]);
amplitude.identify(identifyEvent);
The second option is to send it as event properties.
const myCartObjectArray = {
products: [
{
product_id: 123,
sku: "41245",
name: "Sunscreen",
},
],
};
amplitude.logEvent("Product Viewed", (event_properties = myCartObjectArray));
For more information, refer to the Identify API.
Use object arrays in your Event Segmentation and Funnel Analysis charts
You can access the object arrays the property splitting process generates from within your chart events, like any other event or user property.
These arrays appear in the event and user property dropdowns and are marked by {:}.
Lookup properties based on child (cart) properties
If you create a lookup property that maps from a child (cart) property, the lookup property appears in chart dropdowns under its parent property, not in the main property list. To find it, first select the parent cart property (marked with {:}), then look for the lookup property as a nested option in the second-level dropdown. This also applies to any filters or group-by selections that use the lookup property.
Filters
As with standard event and user properties, you can apply conditions to filter your results. Filters work a little differently for object arrays.
Cross-property filters (default): These filters reference all items or objects within the array. This is also called "mix and match" semantics. To apply cross-property filters, apply two separate clauses with + Filter by on the same event.
Parallel filters: These filters reference the same item or object within the array. To apply parallel filters, add two or more
containsclauses on the same item or object.
You can only apply parallel semantics on sibling properties.
Item match: Tells Amplitude Analytics to respect filter conditions when displaying group-by values (for example, only electronics items).
Collection match: Tells Amplitude Analytics to reference all objects in the event when displaying group-by values (for example, all items in purchases containing electronics).
Examples of queries using object arrays for cart analysis
Object arrays are highly flexible and capable of complex queries. The following examples may help you develop your own queries:
- Purchases containing an electronics product.
- Purchases containing an electronics product, where the price is greater than or equal to $24.99.
- Compare purchases containing seasonal products to purchases containing beauty products.
- Sum the price of electronics products in any purchases that contain at least one electronics product.
Was this helpful?