Open the chat with the order status
A shopper has reloaded the tracking page for one order four times in ten minutes, and now they open chat. The bot's usual opener asks how it can help, and the shopper types out what the tracking page showed them, then waits while the bot looks the order up. The refreshing was the question. The chat can open with the answer and the order number in it.
tracking_views_session- Times the order tracking page was opened this visit
last_tracking_url_session- The tracking page they opened last, which carries the order number
Opens the chat with the status of that order and the carrier's latest scan when the shopper has reloaded the tracking page three or more times this visit. The order number comes from the page they were on and the status comes from your order system.
from snowplow_signals import (
Attribute, AtomicProperty, Criteria, Criterion, Event, StreamAttributeGroup, domain_sessionid,
)
page_view = Event(name="page_view", vendor="com.snowplowanalytics.snowplow", version="1-0-0")
on_tracking = Criteria(all=[
Criterion.like(AtomicProperty(name="page_url"), "%/orders/%/track%"),
])
tracking_views_session = Attribute(
name="tracking_views_session",
type="int32",
events=[page_view],
aggregation="counter",
criteria=on_tracking,
default_value=0,
)
last_tracking_url_session = Attribute(
name="last_tracking_url_session",
type="string",
events=[page_view],
aggregation="last",
property=AtomicProperty(name="page_url"),
criteria=on_tracking,
)
# Keyed on the visit, so the chat widget asks about this session the moment it opens.
shop_support_tracking = StreamAttributeGroup(
name="shop_support_tracking",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[tracking_views_session, last_tracking_url_session],
)// In the handler that runs when the chat widget opens
const shopper = await signals.getServiceAttributes({
name: "shop_support_tracking",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { tracking_views_session: 4, last_tracking_url_session: "https://shop.example/orders/48213/track" }
if (shopper.tracking_views_session >= 3) {
const orderId = orderIdFromUrl(shopper.last_tracking_url_session);
bot.open({
intent: "order_status",
order: await orders.get(orderId),
});
}