await serverClient.feeds.createMembershipLevel({
id: uuidv4(),
name: "Premium",
description: "Weekly QA with me",
custom: {
// Lets you query membership levels by creator.id, useful if you want to scope membership levels to users
creator_id: creator.id,
},
// Lets you sort membership levels by priority
priority: 100,
// Users with this membership level can see activities with these tags
tags: ["premium"],
});
await serverClient.feeds.createMembershipLevel({
id: uuidv4(),
name: "Inner Circle",
description: `You can see new videos a week earlier, and weekly QA with me`,
// Users in this membership level can see premium and inner circle content as well
tags: ["premium", "inner-circle"],
priority: 200,
custom: {
creator_id: creator.id,
},
});
Membership levels
Membership levels let you create different tiers among a feed’s audience, and control which activities are available to which users. This gives users the option to post content that only premium members can see.
This page details how you can set up membership levels.
Create membership levels
Use server-side SDKs to create membership levels. You can define unified membership levels for your application, or scope them (for example, to specific users) using custom data.
Assign membership level to users
To assign a membership level to a user, you need to add them as a feed member, and set their membership level.
Users still have to follow the feed to see posts in their timelines. Membership levels are only used for authorization purposes.
await serverClient.feeds.updateFeedMembers({
feed_group_id: creatorFeed.group,
feed_id: creatorFeed.id,
operation: "upsert",
members: [
{
user_id: premiumFan.id,
membership_level: premiumMembershipLevel.id,
},
],
});
Create a premium activity
let privateActivity = try await feed.addActivity(
request: .init(
text: "Premium content",
type: "post",
visibility: .tag,
visibilityTag: "premium"
)
)
// Premium users can see full activity, others a preview
feed.addActivity({
type: "post",
text: "Premium content",
visibility: "tag",
visibility_tag: "premium",
});
// Premium users can see full activity, others a preview
client.feeds.addActivity({
feeds: ["user:1"],
type: "post",
text: "Premium content",
visibility: "tag",
visibility_tag: "premium",
user_id: "<user id>",
});
// Premium users can see full activity, others a preview
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Create tag-based visibility activity (premium content)
premiumActivity, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Fids: []string{"user:1"},
Type: getstream.PtrTo("post"),
Text: getstream.PtrTo("Premium content"),
Visibility: getstream.PtrTo("tag"),
VisibilityTag: getstream.PtrTo("premium"),
UserID: getstream.PtrTo("<user id>"),
Custom: map[string]interface{}{
"tier": "premium",
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Premium activity created: %+v", premiumActivity.Data)
log.Println("Premium users can see full activity, others a preview")
}
Users who don’t have access to the post will only see a preview:
- No attachments are shown
- The activity text is truncated (first 20 characters are shown, for example: “Behind the scenes of…”)
Query membership levels
await serverClient.feeds.queryMembershipLevels({
filter: {
custom: {
$contains: {
creator_id: creator.id,
},
},
},
sort: [{ field: "priority", direction: -1 }],
});
Filter options
| name | type | description | supported operations | example |
| ------------- | ------------------------------------------------- | ---------------------------------------------- | ----------------------------------- | ----------------------------------------------------- | --- |
| id
| string or list of strings | The ID of the membership level | $in
, $eq
| { id: { $in: [ 'abc', 'xyz' ] } }
|
| name
| string or list of strings | The name of the membership level | $in
, $eq
| { name: { $in: [ 'abc', 'xyz' ] } }
|
| description
| string or list of strings | The description of the membership level | $in
, $eq
| { description: { $in: [ 'abc', 'xyz' ] } }
|
| priority
| number | The priority of the membership level | $eq
, $gt
, $lt
, $gte
, $lte
| { priority: { $gte: 100 } }
|
| tags
| list of strings | Tags the membership level grants access to | $eq
, $in
, $contains
| { tags: { $in: [ 'premium', 'inner-circle' ] } }
|
| custom
| object | Custom data of the membership level | $contains
, $path_exists
| { custom: { $contains: {creator_id: '123' } } }
|
| created_at
| string, must be formatted as an RFC3339 timestamp | The time the membership level was created | $eq
, $gt
, $lt
, $gte
, $lte
| { created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
|
| updated_at
| string, must be formatted as an RFC3339 timestamp | The time the membership level was last updated | $eq
, $gt
, $lt
, $gte
, $lte
| { updated_at: { $gte: '2023-12-04T09:30:20.45Z' } }
| |
Sort options
Fields:
priority
created_at
updated_at
Direction: 1
or -1
Update membership levels
await serverClient.feeds.updateMembershipLevel({
id: premiumMembershipLevel.id,
name: "Premium",
description: "Weekly QA with me",
custom: {
creator_id: creator.id,
},
priority: 100,
tags: ["premium"],
});
Delete membership level
await serverClient.feeds.deleteMembershipLevel({
id: premiumMembershipLevel.id,
});
- I'm working with the Stream Feeds Go SDK and would like to ask questions about this documentation page: https://getstream.io/activity-feeds/docs/go-golang/membership-levels.md
- View as markdown
- Open in ChatGPT
- Open in Claude