Offer address lookup to a shopper the form keeps rejecting
A shopper has been on the address step for four minutes and the form has rejected it three times, each time on the postal code. From the outside this looks like a shopper taking their time. A recovery message sent after they leave arrives after the problem, and the problem was the form. What they need now is an address lookup, or a guest checkout that asks for less.
current_step- The checkout step the shopper is on now
seconds_on_step- Seconds since the shopper reached this step
address_errors_session- Validation errors on the address step this visit
Swaps in address lookup once a shopper on the address step has had two errors, and offers guest checkout when the time on the step passes the limit your team set.
from snowplow_signals import (
Attribute, Criteria, Criterion, Event, EventProperty, StreamAttributeGroup, domain_sessionid,
)
checkout_step = Event(name="checkout_step", vendor="com.example", version="1-0-0")
checkout_error = Event(name="checkout_error", vendor="com.example", version="1-0-0")
current_step = Attribute(
name="current_step",
type="string",
events=[checkout_step],
aggregation="last",
property=EventProperty(vendor="com.example", name="checkout_step", major_version=1, path="step"),
)
seconds_on_step = Attribute(
name="seconds_on_step",
type="double",
events=[checkout_step],
aggregation="time_since_last",
time_unit="s",
)
address_errors_session = Attribute(
name="address_errors_session",
type="int32",
events=[checkout_error],
aggregation="counter",
criteria=Criteria(all=[
Criterion.eq(EventProperty(vendor="com.example", name="checkout_error", major_version=1, path="step"), "address"),
]),
default_value=0,
)
# Keyed on the visit, so the error count starts again when the shopper comes back another day.
shop_checkout_address = StreamAttributeGroup(
name="shop_checkout_address",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[current_step, seconds_on_step, address_errors_session],
)// In the code that renders the checkout
const shopper = await signals.getServiceAttributes({
name: "shop_checkout_address",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { current_step: "address", seconds_on_step: 243, address_errors_session: 3 }
if (shopper.current_step === "address" && shopper.address_errors_session >= 2) {
checkout.show({ help: "address_lookup" });
}
if (shopper.current_step === "address" && shopper.seconds_on_step > checkout.stallAfter) {
checkout.show({ help: "guest_checkout" });
}