Nudge the shopper on the page while the cart sits idle
A shopper has three items in the cart and has spent the last ten minutes in another category without touching it. The recovery email is written for the shopper who has gone, so it waits for the visit to end and lands beside everything else in the inbox. This shopper is still on the site. The nudge belongs in the header, next to the cart, while they can see it.
cart_value_session- Value of what has been added to the cart this visit
seconds_since_cart_change- Seconds since the cart was last added to or taken from
cart_adds_session- Items added to the cart this visit
Shows a line beside the cart icon once a cart above the value your team sets has gone untouched for ten minutes, and tells your messaging tool the visit is still going so the recovery email waits.
from datetime import timedelta
from snowplow_signals import (
Attribute, Event, EventProperty, StreamAttributeGroup, domain_sessionid,
)
add_to_cart = Event(name="add_to_cart", vendor="com.example", version="1-0-0")
remove_from_cart = Event(name="remove_from_cart", vendor="com.example", version="1-0-0")
cart_value_session = Attribute(
name="cart_value_session",
type="double",
events=[add_to_cart],
aggregation="sum",
property=EventProperty(vendor="com.example", name="add_to_cart", major_version=1, path="price"),
default_value=0,
)
seconds_since_cart_change = Attribute(
name="seconds_since_cart_change",
type="double",
events=[add_to_cart, remove_from_cart],
aggregation="time_since_last",
time_unit="s",
)
cart_adds_session = Attribute(
name="cart_adds_session",
type="int32",
events=[add_to_cart],
aggregation="counter",
default_value=0,
)
# Most shoppers are anonymous, so this group keys on the visit.
shop_cart_idle = StreamAttributeGroup(
name="shop_cart_idle",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[cart_value_session, seconds_since_cart_change, cart_adds_session],
)// In the code that renders the storefront header
const cart = await signals.getServiceAttributes({
name: "shop_cart_idle",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { cart_value_session: 142.5, seconds_since_cart_change: 640, cart_adds_session: 3 }
if (cart.cart_adds_session > 0 && cart.cart_value_session >= rules.nudgeAt && cart.seconds_since_cart_change >= 600) {
header.show({
beside: "cart",
text: `${cart.cart_adds_session} items are waiting in your cart`,
});
}