Offer the section newsletter on the third story in it
A reader opened a politics story, then a second, and is now on their third this visit. A site-wide prompt that fires on a page count shows them the general newsletter here, and the general newsletter is not what they came for. Three stories in, they have told you what they read. The ask that fits is the politics newsletter, on this page, before they leave.
top_section_session- The section they have read most this visit
stories_by_section_session- How many stories they opened in each section this visit
Shows the newsletter for the section a reader has read most once they open a third story in it this visit, and names the section in the prompt.
from datetime import timedelta
from snowplow_signals import Attribute, EntityProperty, Event, StreamAttributeGroup, domain_sessionid
page_view = Event(name="page_view", vendor="com.snowplowanalytics.snowplow", version="1-0-0")
section = EntityProperty(vendor="com.example", name="article", major_version=1, path="section")
top_section_session = Attribute(
name="top_section_session",
type="string",
events=[page_view],
aggregation="most_frequent",
property=section,
ttl=timedelta(hours=2),
)
stories_by_section_session = Attribute(
name="stories_by_section_session",
type="dict",
events=[page_view],
aggregation="category_count",
property=section,
ttl=timedelta(hours=2),
)
signup_section = StreamAttributeGroup(
name="signup_section",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[top_section_session, stories_by_section_session],
)// In the code that renders the article page
const reader = await signals.getServiceAttributes({
name: "signup_section",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { top_section_session: "politics", stories_by_section_session: { politics: 3, business: 1 } }
const inSection = reader.stories_by_section_session[reader.top_section_session] ?? 0;
if (inSection >= 3) {
newsletterPrompt.show({
list: reader.top_section_session,
headline: `Get our ${reader.top_section_session} coverage by email`,
});
}