Quick-start
Last updated
Was this helpful?
Was this helpful?
// ...import code
await Flagship.start("<ENV_ID>", "<API_KEY>");
const fsVisitor = Flagship.newVisitor({
visitorId: "<VISITOR_ID>",
hasConsented: true, // this is required
context: {
isVIP: true,
country: "NL",
loginProvider: "Google"
}
});// Retrieving flags with an 'await' statement
//...import code
// Step 1: start the SDK
await Flagship.start("your_env_id", "your_api_key");
//Step 2: Create a visitor
const visitor = Flagship.newVisitor({
visitorId: "your_visitor_id",
context: { isVip: true },
});
//Step 3: Fetch flag from the Flagship platform
await visitor.fetchFlags();
// Step 4: Retrieves a flag named "displayVipFeature"
const flag = visitor.getFlag("displayVipFeature");
//Step 5: Returns the flag value ,or if the flag does not exist, it returns the default value "false"
console.log("flag value", flag.getValue(false))// Retrieving flags with a 'then' function
//...import code
// Step 1: start the SDK
await Flagship.start("your_env_id", "your_api_key");
//Step 2: Create a visitor
const visitor = Flagship.newVisitor({
visitorId: "your_visitor_id",
context: { isVip: true },
});
//Step 3: Fetch flags from the Flagship platform
visitor.fetchFlags().then(()=>{
// Step 4: Retrieves a flag named "displayVipFeature"
const flag = visitor.getFlag("displayVipFeature");
//Step 5: Returns the flag value ,or if the flag does not exist, it returns the default value "false"
console.log("flag value", flag.getValue(false))
});// Retrieving flags with an event listener
//...import code
// Step 1: start the SDK
await Flagship.start("your_env_id", "your_api_key");
//Step 2: Create a visitor
const visitor = Flagship.newVisitor({
visitorId: "your_visitor_id",
context: { isVip: true },
});
visitor.on("ready", (error) => {
if (error) {
//do some stuff
return;
}
// Step 4: Retrieves a flag named "displayVipFeature"
const flag = visitor.getFlag("displayVipFeature");
//Step 5: Returns the flag value ,or if the flag does not exist, it returns the default value "false" */
console.log("flag value", flag.getValue(false))
});
//Step 3: Fetch flags from the Flagship platform
visitor.fetchFlags();import { HitType, EventCategory } from "@flagship.io/js-sdk";
// ... other code
visitor.sendHit({
type: HitType.EVENT,
category: EventCategory.USER_ENGAGEMENT,
action: "click",
label: "label",
value: 100,
});