Quick-start
Installation
Refer to the installation page for installation steps.
Flagship Usage
Start SDK
Step 1: Start the SDK by calling the start method of the Fs class, in the most appropriate location for your application.
using Flagship.Main;
// Step 1: start the SDK
Fs.Start("<ENV_ID>", "<API_KEY>");
This starts the SDK in DECISION-API. More options are available in the SDK configuration.
Good to know
Your apiKey and environmentId can be found in your Flagship account under Parameters > Environment & Security.
Create a visitor
Step 2: Create a visitor using the newVisitor method from the Fs instance. The visitor instance allows you to set relevant data for Flagship to make a decision, including: Visitor ID, Visitor Context, GDPR Consent, and Authentication status.
For example, if you want to enable a specific feature for all your VIP
visitors, you'll need to add this data as an attribute into the visitor context (key-value pair): isVIP: true
. Based on your targeting criteria defined in your use-case (isVIP === true
), Flagship will make the decision and show your feature to visitors that have isVIP
in their context and for which isVIP
is equal to true
.
using Flagship.Main;
//Step 2: Create a visitor
var visitor = Fs.NewVisitor("<VISITOR_ID>", true)
.SetContext(new Dictionary<string, object>(){["isVip"] = true})
.Build();
Getting Flags
Steps 3, 4, and 5 involve fetching flags from Flagship, retrieving your flag, and reading your flag's value.
First, fetch flags from the Flagship platform using the fetchFlags method. You can ensure that your flags are fetched and ready to be used by using an await
statement, a then
function, or an event listener
.
Then, use the getFlag method of the visitor instance to retrieve a specific flag object based on the key provided. This object includes methods to retrieve the flag value, access flag metadata, expose the flag, verify the flag's existence, and get the flag status.
//Step 3: Fetch flag from the Flagship platform
await visitor.FetchFlags();
/* Step 4: Retrieves a flag named "displayVipFeature",
*/
var flag = visitor.GetFlag("displayVipFeature");
//Step 5: get the flag value and if the flag does not exist, it returns the default value "false"
var flagValue = flag.GetValue(false);
Console.WriteLine($"Flag {flagValue}");
Good to know
- By default, the SDK assumes that the visitor has been exposed to the flag when
flag.GetValue
is called, so it sends the flag exposure hit to flagship server. However, this behavior can be changed. Click here for more details.
Tracking hits
Step 6: Send hits to Flagship using the sendHit method of the visitor instance. These hits help validate your objectives (KPIs) set up in your campaign.
// ... other code
await visitor.SendHit(new Event(EventCategory.ACTION_TRACKING, "add-to-cart"));
Updated 5 months ago