GamebeastDocs
Dashboard
JavaScript SDKAPI Reference

Cohorts

This API is used to check membership in cohorts defined on the Gamebeast dashboard, from the browser and from servers.

For more information about Cohorts, visit the User Cohorts Guide.

const gamebeastCohorts = gamebeast.cohorts;

Membership is recomputed by the backend, so treat it as eventually consistent rather than real-time. Results are cached for a minute, and the endpoint is limited to 60 requests per minute per API key, so the SDK shares requests where it can.

Client methods

Client

isMember(cohortName)

Promise<boolean>return type

Checks whether the current user is in the named cohort. Resolves false when the cohort doesn't exist or the check fails (both are logged). It never rejects. Concurrent checks for the same cohort share one request.

cohortNamestring

The name of the cohort.

Usage

if (await gamebeastCohorts.isMember("High Spenders")) {
  showVipOffer();
}

Server methods

Server

Checks for the same cohort that arrive within a few milliseconds are combined into one request, so checking many users at once doesn't use up the rate limit.

isMember(cohortName, distinctId)

Promise<boolean>return type

Checks whether a user is in the named cohort. Resolves false when the cohort doesn't exist or the check fails. It never rejects.

cohortNamestring

The name of the cohort.

distinctIdstring

The user to check.

Usage

const isVip = await gamebeastCohorts.isMember("High Spenders", user.id);

getMembership(cohortName, distinctIds)

Promise<Map<string, boolean>>return type

Checks many users at once. Users in a cohort that doesn't exist resolve to false. Unlike isMember, this rejects with a GamebeastError when the check fails, so a failure can't be mistaken for "not a member".

cohortNamestring

The name of the cohort.

distinctIdsstring[]

The users to check.

Usage

const membership = await gamebeastCohorts.getMembership("High Spenders", userIds);
const vips = userIds.filter((id) => membership.get(id));

On this page