- React
- JS snippet
- Python
- Node
- +24 more SDKs
1
Install Statsig packages
Copy
Ask AI
npm install @statsig/react-bindings
2
Wrap child components
Next, update your app’s default function (Usually App.tsx or Layout.tsx) so that the StatsigProvider wraps around all child components.
Copy
Ask AI
import { StatsigProvider } from "@statsig/react-bindings";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<StatsigProvider
sdkKey={"client-MY-STATSIG-CLIENT-KEY"}
user={{ userID: "quickstart-user" }}
loadingComponent={<div>Loading...</div>}>
{children}
</StatsigProvider>
);
}
This example assumes you’re using client-side React, if you’re Server-Side Rendering, you’d be better served by our Next.js docs.
3
Add client key
Create a client API key in the Statsig console Settings. Copy and paste it to replace
<REPLACE_WITH_YOUR_CLIENT_KEY> in the code snippet from the previous step.4
Basic Usage
- Check a Gate
- Get an Experiment Value
- Log an Event
First, create a gate on the Feature Gates page in console, then check it in-code:
Copy
Ask AI
const { client } = useStatsigClient();
return (
<div>Gate is {client.checkGate('check_user') ? 'passing' : 'failing'}.</div>
);
First, create an Experiment on the Experiments page in console
Copy
Ask AI
const { client } = useStatsigClient();
const experiment = client.getExperiment('my_experiment_name');
return (
<div>Headline Parameter: {experiment.get('my_experiment_parameter_name', 'fallback_value')}.</div>
);
You can use Events to power metrics in your experiment or gates. Events don’t need to be set up in console first, just add to your code:
Copy
Ask AI
const { client } = useStatsigClient();
return <button onClick={() => client.logEvent("button_click")}>Click Me</button>
Next steps
Congratulations! You’ve successfully set up the Statsig SDK in React. Continue on to the tutorials, or jump in to the full Next.js or React SDK libraries.1
Paste the code snippet
In the
<head> section of your website, paste the following code snippet:Copy
Ask AI
<script src="https://cdn.jsdelivr.net/npm/@statsig/js-client@3/build/statsig-js-client+session-replay+web-analytics.min.js?apikey=<REPLACE_WITH_YOUR_CLIENT_KEY>"></script>
2
Add client key
Create a client API key in the Statsig console Settings. Copy and paste it to replace
<REPLACE_WITH_YOUR_CLIENT_KEY> in the code snippet from the previous step.3
Basic usage
- Check a Gate
- Get an Experiment Value
- Log an Event
First, create a gate on the Feature Gates page in console, then check it in-code:
Copy
Ask AI
window.Statsig.instance().checkGate("my_feature_gate_name");
You’ll want to wait for the SDK to initialize before checking a gate to ensure it has fresh values, one way to accomplish this is waiting for the “values_updated” event.
First, create an Experiment on the Experiments page in console
Copy
Ask AI
window.Statsig.instance().getExperiment("my_experiment_name").get('my_experiment_parameter_name');
You’ll want to wait for the SDK to initialize before getting an experiment to ensure it has fresh values, one way to accomplish this is waiting for the “values_updated” event.
You can use Events to power metrics in your experiment or gates. Events don’t need to be set up in console first, just add to your code:
Copy
Ask AI
window.Statsig.instance().logEvent("my_checkout_event_name", "event_value_item_1234", {"event_metadata": "my_metadata"})
Next steps
Congratulations! You’ve set up the Statsig JavaScript snippet. You can now start:- Start recording events
- Watch session replays
- Run experiments
- Use feature flags
1
Install the Statsig package
Copy
Ask AI
pip install statsig-python-core
2
Initialize the Statsig SDK
Copy
Ask AI
from statsig_python_core import Statsig, StatsigOptions
options = StatsigOptions()
options.environment = "development"
statsig = Statsig("<REPLACE_WITH_YOUR_SERVER_SECRET_KEY>", options)
statsig.initialize().wait()
statsig.shutdown().wait()
3
Add server secret key
Create a server secret key in the Statsig console Settings. Copy and paste it to replace
<REPLACE_WITH_YOUR_SERVER_SECRET_KEY> in the code snippet from the previous step.4
Basic Usage
- Check a Gate
- Get an Experiment Value
- Log an Event
First, create a gate on the Feature Gates page in console, then check it in-code:
Copy
Ask AI
user_object = StatsigUser(user_id="123", email="testuser@statsig.com") //add any number of other attributes
gate_value = statsig.check_gate(user_object, "my_feature_gate_name"):
First, create an Experiment on the Experiments page in console
Copy
Ask AI
user_object = StatsigUser(user_id="123", email="testuser@statsig.com"
my_experiment_object = statsig.get_experiment(user_object, "my_experiment_name")
my_experiment_parameter_value = my_experiment_object.get_string('my_experiment_parameter_name')
You can use Events to power metrics in your experiment or gates. Events don’t need to be set up in console first, just add to your code:
Copy
Ask AI
user_object = StatsigUser(user_id="123", email="testuser@statsig.com"
statsig.log_event(
user=user_object,
event_name="my_checkout_event_name",
value="SKU_12345"
)
Next steps
Congratulations! You’ve set up the Statsig SDK in Python. Continue on to our tutorials, or jump in to the full Python SDK Reference.1
Install the Statsig package
Copy
Ask AI
npm i @statsig/statsig-node-core
2
Copy
Ask AI
// Basic initialization
const statsig = new Statsig("<REPLACE_WITH_YOUR_SERVER_SECRET_KEY>");
await statsig.initialize();
// or with StatsigOptions
const options: StatsigOptions = { environment: "staging" };
const statsigWithOptions = new Statsig("secret-key", options);
await statsigWithOptions.initialize();
3
Add server secret key
Create a server secret key in the Statsig console Settings. Copy and paste it to replace
<REPLACE_WITH_YOUR_SERVER_SECRET_KEY> in the code snippet from the previous step.4
Basic Usage
- Check a Gate
- Get an Experiment Value
- Log an Event
First, create a gate on the Feature Gates page in console, then check it in-code:
Copy
Ask AI
const userObject = new StatsigUser({ userID: "123", email="testuser@statsig.com" });
const is_gate_enabled = statsig.checkGate(userObject, "my_feature_gate_name"):
First, create an Experiment on the Experiments page in console
Copy
Ask AI
const userObject = new StatsigUser({ userID: "123", email="testuser@statsig.com" });
const myExperimentObject = statsig.getExperiment(userObject, "my_experiment_name")
const myExperimentParameterValue = myExperimentObject.getValue('my_experiment_parameter_name')
You can use Events to power metrics in your experiment or gates. Events don’t need to be set up in console first, just add to your code:
Copy
Ask AI
userObject = StatsigUser(user_id="123", email="testuser@statsig.com"
statsig.logEvent(
userObject,
"my_checkout_event_name",
"SKU_12345" //value for the event
);
Next steps
Congratulations! You’ve successfully set up the Statsig SDK in Node.js. Continue on to the tutorials, or jump in to the full Node.js SDK library.Explore SDKs
Statsig offers SDKs for a wide variety of platforms to suit any codebase or deployment preference:Client SDKs
JavaScript
Browser JavaScript
React
Client-Side React
React Native
Bare React Native SDK
Next.js
Next.js SSR, SSG & Client-Side
Angular
Angular bindings for Javascript SDK
Swift
iOS, MacOS, tvOS SDK
Android
Android Kotlin/Java SDK
.NET Client
Client SDK for .NET framework
Roku
Roku Brightscript SDK
Unity
Unity game engine SDK
Dart/Flutter
Flutter/Dart Mobile App SDK
C++ Client
C++ client-side SDK
Server Side SDKs
Node.js
Node.js server SDK
Java
Java server SDK
Python
Python server SDK
Go
Go server SDK
Ruby
Ruby server SDK
.NET Server
.NET server SDK
PHP
PHP server SDK
Rust
Rust server SDK
C++ Server
C++ server SDK