Offer the fit guide while all three sizes are still in the cart
A shopper has added the same dress in small, medium and large. Two of them are coming back, and the store finds out when the returns land in the warehouse, after the shipping has been paid both ways. The shopper is not sure which size fits, and right now they are on the cart page with the question still open. The fit guide, or the size other shoppers kept, answers it before the order exists.
cart_skus_session- Every product and size variant added to the cart this visit
size_guide_views_session- Times the size guide was opened this visit
Shows the fit guide beside the cart line, or the size most kept by other shoppers if your merchandising rule prefers it, when one product sits in the cart in two or more sizes and the shopper has not opened the guide yet.
from datetime import timedelta
from snowplow_signals import (
Attribute, AtomicProperty, Criteria, Criterion, EntityProperty, Event, StreamAttributeGroup, domain_sessionid,
)
page_view = Event(name="page_view", vendor="com.snowplowanalytics.snowplow", version="1-0-0")
add_to_cart = Event(name="add_to_cart", vendor="com.example", version="1-0-0")
cart_skus_session = Attribute(
name="cart_skus_session",
type="string_list",
events=[add_to_cart],
aggregation="unique_list",
property=EntityProperty(vendor="com.example", name="product", major_version=1, path="sku"),
ttl=timedelta(hours=6),
)
size_guide_views_session = Attribute(
name="size_guide_views_session",
type="int32",
events=[page_view],
aggregation="counter",
criteria=Criteria(all=[
Criterion.like(AtomicProperty(name="page_url"), "%/size-guide%"),
]),
ttl=timedelta(hours=6),
default_value=0,
)
# Keyed on the visit, so the cart page asks about this session's cart.
shop_sizing_cart = StreamAttributeGroup(
name="shop_sizing_cart",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[cart_skus_session, size_guide_views_session],
)// In the code that renders the cart page, for each product in the cart
const cart = await signals.getServiceAttributes({
name: "shop_sizing_cart",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { cart_skus_session: ["dress-2041-s", "dress-2041-m", "dress-2041-l"], size_guide_views_session: 0 }
const sizes = cart.cart_skus_session
.filter((sku) => catalog.productOf(sku) === product.id)
.map(catalog.sizeOf);
if (sizes.length >= 2 && cart.size_guide_views_session === 0) {
cartLine.show({
prompt: "fit_guide",
product: product.id,
sizes,
});
}