Promote a story while it is pulling readers in
A story the morning meeting put twelfth in its section has been drawing readers for the last few minutes, most of them arriving from social. The homepage still shows the order from the meeting, and the next look at the dashboard comes after the surge has passed. The slot this story needs is the one above it, and it needs it now.
views_5m- Page views of this article in the last five minutes
sessions_5m- Separate visits that opened it in the last five minutes
arriving_from_5m- Where most of those readers came from
Moves an article up within its section block when its separate visits in the last five minutes pass the threshold the desk set for that block, and leaves the lead slot to editorial.
from datetime import timedelta
from snowplow_signals import (
Attribute, AttributeKey, AtomicProperty, EntityProperty, Event, StreamAttributeGroup,
)
page_view = Event(name="page_view", vendor="com.snowplowanalytics.snowplow", version="1-0-0")
article = AttributeKey(
name="article",
property=EntityProperty(vendor="com.example", name="article", major_version=1, path="id"),
)
views_5m = Attribute(
name="views_5m",
type="int32",
events=[page_view],
aggregation="counter",
period=timedelta(minutes=5),
default_value=0,
)
sessions_5m = Attribute(
name="sessions_5m",
type="int32",
events=[page_view],
aggregation="approx_count_distinct",
property=AtomicProperty(name="domain_sessionid"),
period=timedelta(minutes=5),
)
arriving_from_5m = Attribute(
name="arriving_from_5m",
type="string",
events=[page_view],
aggregation="most_frequent",
property=AtomicProperty(name="refr_medium"),
period=timedelta(minutes=5),
)
# Keyed on the article, not the reader, so the homepage asks about a story.
homepage_rising = StreamAttributeGroup(
name="homepage_rising",
version=1,
attribute_key=article,
owner="you@example.com",
attributes=[views_5m, sessions_5m, arriving_from_5m],
)// In the code that renders the homepage, for each story in a section block
const story = await signals.getServiceAttributes({
name: "homepage_rising",
attribute_key: "article",
identifier: articleId,
});
// { views_5m: 112, sessions_5m: 104, arriving_from_5m: "social" }
if (story.sessions_5m >= block.promoteAt) {
homepage.promote({ article: articleId, within: block.section });
}