Skip to content

Instantly share code, notes, and snippets.

@JD2455
Last active January 30, 2023 19:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JD2455/819b178bd43fc3da376eb2d6ddc55c3b to your computer and use it in GitHub Desktop.
Save JD2455/819b178bd43fc3da376eb2d6ddc55c3b to your computer and use it in GitHub Desktop.
import UpgradeClient from 'upgrade_client_lib';
function async SampleAplication() {
// construct upgrade client for student1
const userId = "student1";
// set host url
const hostUrl = 'http://development-upgrade-experiment-app.eba-gp6psjut.us-east-1.elasticbeanstalk.com';
// Two ways for initializing user
const upClient = new UpgradeClient(userId, hostUrl); // No network call will be done over here.
const upClient = new UpgradeClient(userId, hostUrl, token); // No network call will be done over here.
const groupMembership = {
class: ["class1", "class2"]
}
const workingGroup = {
class: "class1"
}
// Initialize user with Upgrade system
// There are multiple ways to initialize user
// We can set groupMemberShip and workingGroup for user later by invoking the function setGroupMembership and setWorkingGroup
await upClient.init(); // Network call. It will create a new user with the userId passed in the constructor if not created already
await upClient.init(groupMembership); // Network call. It will create a new user with groupMembership if not created already
await upClient.init(groupMembership, workingGroup); // Network call. It will create a new user with groupMembership and workingGroup if not created already
// Set alternative user ids for current user
const altUserIds = ['aliases1', 'aliases2', 'aliases3'];
await upClient.setAltUserIds(altUserIds); // Network call to set altUserIds for current user
// set group membership for client
await upClient.setGroupMembership(groupMembership); // Network call. It will create group on Upgrade
// set working group for client
await upClient.setWorkingGroup(workingGroup); // Network call. It will create working group on Upgrade
await upClient.getAllExperimentConditions('context'); // Network call. It will retrieve all assignments.
const experimentConditions = await upClient.getExperimentCondition('context', 'experimentPoint', 'experimentId'); // It will do network only if getAllExperimentConditions() is not called before this function
await upClient.markExperimentPoint('experimentPoint', 'conditionCode', 'experimentId'); // Network call. It will mark experiment point
await upClient.failedExperimentPoint('experimentPoint', 'Not implemented yet', 'experimentId'); // Network call
await upClient.getAllFeatureFlags(); // Network call. It will return all feature flags
// Feature flag key
const featureFlagKey = 'theme';
const flag = await upClient.getFeatureFlag(featureFlagKey); // No Network call.
await upClient.log(logData); // Network call. It will log data of user
await upClient.addMetrics(metrics); // Network call. It will add metrics in upgrade system
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment