Activity Feeds v3 is in beta — try it out!

Activity selectors

Activity selectors give you control over which data is shown in a feed. For example you can decide to show only popular activities, or activities that fit the current user’s interests.

Each activity selector selects the first 1000 activities that match its selection criteria.

This page details what kind of activity selectors are supported by the Stream API, and how can you configure them.

You can create custom feed groups or update the built-in groups with your own activity selector configuration.

Selector types

Current Feed Selector

Shows activities from the current feed. This is the selector used when reading a user feed.

Parameters

NameTypeDescriptionDefaultRequired
sortarray, see SortSort optionsNewest firstNo
filterobject, see FilterAdditional filter conditions-No
cutoff_windowstring, duration like 2h or 5dActivities older than this window won’t be selected7d (last 7 days)No

Scope

The feed we’re currently reading

Example

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Following Feed Selector

Shows activities from feeds the current feed follows. This is the selector used when reading a timeline feed.

Parameters

NameTypeDescriptionDefaultRequired
sortarray, see SortSort optionsNewest firstNo
filterobject, see FilterAdditional filter conditions-No
cutoff_windowstring, duration like 2h or 5dActivities older than this window won’t be selected7d (last 7 days)No

Scope

Feeds followed by the feed we’re currently reading

Example

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Selects popular activities from public and visible feeds.

Popularity is computed by the following formula:

activity.popularity = reactions + comments * 2 + bookmarks * 3 + shares * 3;

Parameters

NameTypeDescriptionDefaultRequired
sortarray, see SortSort optionsNewest firstNo
filterobject, see FilterAdditional filter conditions-No
cutoff_windowstring, duration like 2h or 5dActivities older than this window won’t be selected7d (last 7 days)No

Scope

Any feed with public or visible visibility level.

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Proximity Activity Selector

Shows activities based on geographic proximity

Parameters

NameTypeDescriptionDefaultRequired
sortarray, see SortSort optionsNewest firstNo
filterobject, see FilterAdditional filter conditions-No
cutoff_windowstring, duration like 2h or 5dActivities older than this window won’t be selected7d (last 7 days)No
min_popularitynumber (only positive numbers are accepted)Minimum popularity an activity should have to be selected0No

Scope

The feed we’re currently reading

Example

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Interest Activity Selector

Selects activities that match the logged-in user’s interests. Interests are automatically calculated for each user by Stream API based on which activities the user interacts with.

Interests are based on activity topics. Topics are stored in the interest_tags field of an activity. It can be computed automatically using activity processors or set when creating an activity.

Parameters

NameTypeDescriptionDefaultRequired
sortarray, see SortSort optionsNewest firstNo
filterobject, see FilterAdditional filter conditions-No
cutoff_windowstring, duration like 2h or 5dActivities older than this window won’t be selected7d (last 7 days)No
min_popularitynumber (only positive numbers are accepted)Minimum popularity an activity should have to be selected0No

Scope

Feeds that are visible to the logged-in user.

Examples

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Query Activity Selector

Selects activities using the provided filter query.

Parameters

NameTypeDescriptionDefaultRequired
sortarray, see SortSort optionsNewest firstNo
filterobject, see FilterAdditional filter conditions-No
cutoff_windowstring, duration like 2h or 5dActivities older than this window won’t be selected7d (last 7 days)No

Scope

Feeds that are visible to the logged-in user.

Example

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Selector parameters

Supported values for sort and filter objects.

Sort

The following sort options are available:

Fields:

  • created_at
  • popularity

Direction: 1 or -1

Filters

The following filter options are available for the current, popular, interest, proximity and query selectors:

nametypedescriptionsupported operationsexample
idstring or list of stringsThe ID of the activity$in, $eq{ id: { $in: [ 'abc', 'xyz' ] } }
activity_typestring or list of stringsThe type of the activity$in, $eq{ activity_type: { $in: [ 'abc', 'xyz' ] } }
user_idstring or list of stringsThe ID of the user who created the activity$in, $eq{ user_id: { $in: [ 'abc', 'xyz' ] } }
textstringThe text content of the activity$eq, $q, $autocomplete{ text: { $q: 'popularity' } }
search_dataobjectThe extra metadata for search indexing$contains, $path_exists{ search_data: { $contains: { 'category': 'sports', 'status': 'active' } } }
interest_tagslist of stringsTags for user interests$eq, $contains{ interest_tags: { $in: [ 'sports', 'music' ] } }
filter_tagslist of stringsTags for filtering$eq, $contains{ filter_tags: { $in: [ 'categoryA', 'categoryB' ] } }
created_atstring, must be formatted as an RFC3339 timestampThe time the activity was created$eq, $gt, $lt, $gte, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
popularitynumberThe popularity score of the activity$eq, $ne, $gt, $lt, $gte, $lte{ popularity: { $gte: 70 } }
nearobjectIndicates the GEO point to search nearby activities$eq{ near: { $eq: { lat: 40.0, lng: -74.0, distance: 200 } } }
within_boundsobjectIndicates the GEO bounds to search for activities within$eq{ within_bounds: { $eq: { ne_lat: 40.0, ne_lng: -115.0, sw_lat: 32.0, sw_lng: -125.0 } } }

The following filter options are available for the following selector:

nametypedescriptionsupported operationsexample
idstring or list of stringsThe ID of the activity$in, $eq{ id: { $in: [ 'abc', 'xyz' ] } }
filter_tagslist of stringsTags for filtering$eq, $contains{ filter_tags: { $in: [ 'categoryA', 'categoryB' ] } }

Combining selectors

You can combine multiple selectors. The example below will include:

  • popular activities from public and visible feeds
  • activities from feeds the user follows
  • activities from feeds the user has access to, and match the user’s interest

Each activity selector selects the first 1000 activities that match its selection criteria. We suggest taking adventage of the different config options for the selectors to make sure that the selectors return the most relevant activities. When combining selectors, every selector runs independently, so in this case 3 * 1000 activities can be selected.

Once selectors run, ranking is applied to the activities that are returned by the selectors. Even if you have multiple selectors, ranking only runs once.

create_response = self.client.feeds.create_feed_group(
    id= feed_group_id,
    default_visibility= "public",
)

Experimenting with selectors

Feed groups let you define what activities should be included in the feed and the ranking to sort these activities.

By default all feeds in the given group will have the same settings. However, you might want to experiment with different selectors and rankings. Feed views let you do that by overriding the group’s default settings.

Note that any write operation to feed groups/views can take up to 30 seconds to propagate to all API nodes.

© Getstream.io, Inc. All Rights Reserved.