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
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.
cohortNamestringThe name of the cohort.
Usage
if (await gamebeastCohorts.isMember("High Spenders")) {
showVipOffer();
}Server methods
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.
cohortNamestringThe name of the cohort.
distinctIdstringThe 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".
cohortNamestringThe 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));