Feature Flags, Toggles & A/B Testing

Everything you need for turbocharging your modern product development

.NET Server SDK

These docs are for using our .NET SDK in a multi-user, server side context. For client side and single-user contexts, try our server .NET SDK

This SDK is written in C#, and is open source and hosted on github.

The Basics

Get started in a few quick steps.

  1. Create a free account on statsig.com
  2. Install the SDK
  3. Initialize and use the SDK

Step 1 - Create a free account on www.statsig.com

You could skip this for now, but you will need an SDK Key and some Feature Gates or Dynamic Configs to use with the SDK in just a minute.

Step 2 - Install the SDK

The package is hosted on Nuget. You can either install it from your Visual Studio’s Nuget package manager, or through .NET CLI:

dotnet add package Statsig --version 0.1.2

Step 3 - Initialize and use the SDK

Initialize the SDK using a Server Secret Key from the statsig console:

using Statsig;
using Statsig.Server;

private double _subPrice

await Statsig.initialize('<secret>')

// Now you can check gates, get configs, log events for your users.
// e.g. if you are running a promotion that offers all users with a @statsig.com email a discounted price on your monthly subscription service,
// 1. you can first use check_gate to see if they are eligible
var user = new StatsigUser {'email' => 'jkw@statsig.com'};
if (await Statsig.CheckGate(user, 'has_statsig_email'))
{
  // 2. then get the discounted price from dynamic config
  var priceConfigs = await Statsig.GetConfig(user, "special_item_prices");
  _subPrice = priceConfigs.Get<double>("monthly_sub_price", 0.99);
}

...
// 3. log the conversion event - 'purchase_made' - once they make the purchase
StatsigServer.LogEvent(user, "purchase_made", 1, new Dictionary<string, string>(){ { "price", _subPrice.ToString() } });


// 4. shut down the SDK when your application is closing
StatsigServer.Shutdown();

Most SDK APIs run synchronously, so why are GetConfig and CheckGate asynchronous?

The main reason is that older versions of the SDK might not know how to interpret new types of gate conditions. In such cases the SDK will make an asynchronous call to our servers to fetch the result of a check. This can be resolved by upgrading the SDK, and we will warn you if this happens.

For more details, read our blog post about SDK evaluations. If you have any questions, please ask them in our Feedback Repository.

More Information

For more information, see our SDK documentation on github.