Last active
January 30, 2023 19:11
-
-
Save JD2455/819b178bd43fc3da376eb2d6ddc55c3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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