Give the code to the shopper who keeps coming back to the price
A shopper has opened the same jacket three times this visit, scrolled to the price each time and left the page without adding it. The site-wide code went out in this morning's email to everyone, before anyone could tell this shopper from the one who bought on the first look. The third return to the price is the moment to make the offer. The rules can only make it then if they see it while the shopper is still on the product page.
product_views_session- How many times they opened each product this visit
adds_session- Items added to the cart this visit
Shows a code on the product page once a shopper has opened the same product three times this visit with nothing in the cart, and keeps the site-wide banner closed for everyone who has not.
from snowplow_signals import (
Attribute, 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")
product_id = EntityProperty(vendor="com.example", name="product", major_version=1, path="id")
product_views_session = Attribute(
name="product_views_session",
type="dict",
events=[page_view],
aggregation="category_count",
property=product_id,
)
adds_session = Attribute(
name="adds_session",
type="int32",
events=[add_to_cart],
aggregation="counter",
default_value=0,
)
# Keyed on the visit, so the count resets when the shopper comes back another day.
shop_offers_hesitating = StreamAttributeGroup(
name="shop_offers_hesitating",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[product_views_session, adds_session],
)// In the code that renders the product page
const shopper = await signals.getServiceAttributes({
name: "shop_offers_hesitating",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { product_views_session: { "sku-4471": 3, "sku-2210": 1 }, adds_session: 0 }
const looks = shopper.product_views_session[productId] ?? 0;
if (looks >= 3 && shopper.adds_session === 0) {
offers.show({ kind: "code", product: productId, placement: "price" });
}