Show the join prompt on the booking that earns the points
A traveler booked a flight in March and is back in October, two passengers picked, on the confirmation step of a second trip. A join prompt that shows on arrival reached this traveler on their first visit, when they had no idea whether they would fly with you again, and the no they gave then cost them nothing. The reason to join arrives now, as the points this booking would earn, and the prompt belongs on this step with that number in it.
bookings_1y- Bookings completed on this browser in the last year
visits_30d- Separate visits in the last 30 days
Shows the join prompt at the confirmation step once a traveler has a completed booking in the last year, and fills in the points this booking would earn from your program's own rules. The step stays clear of the prompt for a traveler booking their first trip.
from datetime import timedelta
from snowplow_signals import (
Attribute, AtomicProperty, Event, StreamAttributeGroup, domain_userid,
)
page_view = Event(name="page_view", vendor="com.snowplowanalytics.snowplow", version="1-0-0")
booking_completed = Event(name="booking_completed", vendor="com.example", version="1-0-0")
bookings_1y = Attribute(
name="bookings_1y",
type="int32",
events=[booking_completed],
aggregation="counter",
period=timedelta(days=365),
default_value=0,
)
visits_30d = Attribute(
name="visits_30d",
type="int32",
events=[page_view],
aggregation="approx_count_distinct",
property=AtomicProperty(name="domain_sessionid"),
period=timedelta(days=30),
)
# Travelers book without an account, so this group keys on the browser.
trip_loyalty_second_trip = StreamAttributeGroup(
name="trip_loyalty_second_trip",
version=1,
attribute_key=domain_userid,
owner="you@example.com",
attributes=[bookings_1y, visits_30d],
)// In the code that renders the confirmation step
const traveler = await signals.getServiceAttributes({
name: "trip_loyalty_second_trip",
attribute_key: "domain_userid",
identifier: domainUserId,
});
// { bookings_1y: 1, visits_30d: 3 }
if (traveler.bookings_1y >= 1) {
confirmation.show({
prompt: "join",
points: loyalty.pointsFor(booking),
headline: "Join now and this trip earns points",
});
}