GamebeastDocs
Dashboard
JavaScript SDKAPI Reference

Experiments

This API is used to read the current user's experiment assignments in the browser.

For more information about Experiments, visit the Experiments Guide.

const gamebeastExperiments = gamebeast.experiments;

Enrollment happens automatically: evaluating a configuration enrolls the user in its eligible experiments, and the values returned by Configs already include the assigned group's changes. You don't need this service to run an experiment. It reports which groups the current user is in, for display, analytics segmentation and debugging.

Types

interface ExperimentAssignment {
  experimentId: number;
  experimentName: string | null; // null until the experiment catalog has loaded.
  groupId: number;
  groupLabel: string | null; // null until the experiment catalog has loaded.
  configuration: string; // The ID of the configuration the experiment applies to.
  source: "weightedHash" | "roundRobin" | "manual";
}

assignments

readonly ExperimentAssignment[]return type

The current user's active assignments across every fetched configuration, ordered by experiment id. Empty until the first configuration has loaded, and cleared when the user changes with identify or resetIdentity.

Usage

for (const assignment of gamebeastExperiments.assignments) {
  console.log(`In group ${assignment.groupLabel} of ${assignment.experimentName}`);
}

onAssignmentsChanged(callback)

Unsubscribereturn type

Calls callback with the full list whenever it changes, including when experiment names finish loading.

callback(assignments: readonly ExperimentAssignment[]) => void

Called with the updated assignment list.

Usage

gamebeastExperiments.onAssignmentsChanged((assignments) => {
  analytics.setUserProperties({
    experiments: assignments.map((a) => `${a.experimentName}:${a.groupLabel}`),
  });
});

On this page