fast-psychiatrist-23708
02/11/2024, 12:40 AMconst { GrowthBook } = require("@growthbook/growthbook");
async function getABTestResult(growthbookId) {
const growthbook = new GrowthBook({
apiHost: "<https://cdn.growthbook.io>",
clientKey: "JS_CLIENT_KEY",
enableDevMode: true,
subscribeToChanges: true,
trackingCallback: (experiment, result) => {
// TODO: Use your real analytics tracking system
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.key
});
}
});
growthbook.setAttributes({
"id": growthbookId,
"loggedIn": true,
"country": "US"
});
// Wait for features to be available
try {
await growthbook.loadFeatures();
console.log("Features loaded successfully.");
} catch (error) {
console.error("Failed to load features:", error);
} // console: Features loaded successfully.
const value = growthbook.getFeatureValue(
"live_version",
"fallback"
);
console.log(value); // console: fallback
if (growthbook.isOn("my-feature")) {
console.log("Feature is enabled!")
} else {
console.log("ooff")
} // console: ooff
}