const myNotificationGrpup = await serverClient.feeds.createFeedGroup({
id: "myid",
// Group by activity type and day
aggregation: { format: '{{ type }}-{{ time.strftime("%Y-%m-%d") }}' },
// Enable notification tracking
notification: {
track_read: true,
track_seen: true,
},
});
Aggregation
Aggregated feeds are helpful if you want to group activities. Here are some examples of what you can achieve using aggregated feeds:
‘10 people started to follow you’
‘Julie and 14 others liked your photo’
This page shows what variables and syntax you can use to create aggregation expressions.
Creating aggregated feeds
You can create feed groups with aggregation using the API:
Reading aggregated feeds
When you insert an activity to an aggregated feed we apply the aggregation format. When reading the feed you can read the aggregated activities, together with the latest activities of that group.
Here is an example API response for reading an aggregated feed:
{
"aggregated_activities": [
{
"activities": [
/** latest non-aggregated activities of the group */
],
"activity_count": 3, // how many activities are there in the group?
"user_count": 2, // how many different users are in the group?
"group": "reaction-2025-07-30", // reaction activities for the given day
"score": 0, // score of the group, used when ranking is configured as well
"created_at": 1753883232814202000,
"updated_at": 1753883232814202000
}
],
"activities": [
/** non-aggregated activities of the feed */
]
}
Aggregation Format Syntax
It’s not possible to access all fields of an ActivityResponse
inside the aggregation context. Below you’ll find the list of supported fields:
type
: thetype
field of theactivity
(for example:follow
)time
: creation time of the activityuser_id
: the id of theuser
field of theactivity
custom
: thecustom
field of theactivity
, nested fields can be accessed with.
notation, for example:custom.topic
target_id
: Only defined for notification activities added with thecreate_notification_activity
flag. The id of the activity which triggered the notification (activity.notification_context.target.id
field)id
: the id of theactivity
(this is a unique field and turns off aggregation, you shouldn’t need to use this field in your aggregation expression)
Aggregation examples
Here are some common examples of aggregation formats:
Per user, activity type and id and day
target_id
is only defined for notification activities added with the create_notification_activity
flag.
{{ user_id }}_{{ type }}_{{ target_id }}_{{ time.strftime("%Y-%m-%d") }}
Example notifications:
- Eric liked your post “Great hike today…”
- Sara liked your post “Great hike today…”
Per custom data
Custom data can follow any format, in this example activity_id
refers to the activity the notification belongs to.
{{type}}_{{custom.activity_id}}
Example notifications:
- Eric liked your post “Great hike today…”
- Sara liked your post “Great hike today…”
Per user, activity type and day
{{ user_id }}_{{ type }}_{{ time.strftime("%Y-%m-%d") }}
Example notifications:
- You have a like from Eric
- You have 3 comments from Sara
Per activity type and day
{{ type }}_{{ time.strftime("%Y-%m-%d") }}
Example notifications:
- You have 2 new likes
Follows by user, everything else grouped by verb and day
{% if verb == 'follow' %}
{{ user_id }}_{{ type }}_{{ time.strftime("%Y-%m-%d") }}
{% else %}
{{ type }}_{{ time.strftime("%Y-%m-%d") }}
{% endif %}
Example notifications:
- Eric started to follow you
- Sara started to follow you
- You have 3 new likes
The aggregation rule uses the Jinja2 Template Syntax. Control structures like if
and else
are available, as well as these filters: int
, lower
and strftime
to format the time
variable. The options for strftime
are documented here. Please get in touch with support if you need help with your aggregation formula.
Notification Feeds
Most often the reason you want to enable aggregation on a feed is to create a notification feed. To fully support this use-case, we also should be able to track which notifications are seen or read by users. To achieve this you can turn on notification
tracking for feed groups.
Follow the Notification guide to learn more about notification feeds.