Build Your First Feature
Walk through creating a feature gate, targeting audiences, and rolling out your first feature with the JavaScript SDK.
A feature gate controls who sees a new feature and rolls it out gradually without deploying code. This tutorial creates a feature gate, targets mobile platforms and internal testers, then checks it live with the JavaScript SDK in your browser console.
A feature gate is a Boolean feature flag that returns true or false for each user. In Statsig, Feature Flag is the umbrella term for any configuration you change without deploying code, including feature gates and Dynamic Configs.
Create a feature gate
Navigate to the Feature Gates page and click Create. In the Create New Feature Gate dialog, enter a name and an optional description, keep User ID as the ID type, set a target application, and click Create.
Statsig generates the gate ID from the name and shows it under the name field. Your code checks the gate by that ID. Enter
mobile registrationto get the gate IDmobile_registrationthat this tutorial uses, and confirm the Gate ID before you click Create.
Target mobile platforms
New gates return
falseuntil you add a rule. Click Add New Rule and give the rule a name. Set Criteria to Operating System, set Operator to Any of (Case Insensitive), and select Android and iOS. Set Pass to 100%, then save your changes. If your project requires reviews, click Submit for Review.
Add an internal testing rule
Add a second rule for your team. Click Add New Rule, set Criteria to Email and Operator to Contains any of, and enter your company domain. Set Pass to 100% and save your changes. Employees can now use the feature on any device.

Generate a client API key
Go to Project Settings → API Keys and copy the Client API key. Keep server secret keys on backends only, and use console API keys for programmatic configuration work.
Load the JavaScript SDK
Statsig supports many platforms. Refer to Client SDKs for alternatives. This walkthrough uses the browser SDK so you can experiment directly in DevTools.
Paste the snippet below into the browser console on any site to load the SDK from jsDelivr:
jsconst script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/@statsig/js-client@3/build/statsig-js-client+session-replay+web-analytics.min.js'; document.head.appendChild(script);
Initialize and check the gate
Replace
YOUR_SDK_KEYwith the client key from Step 4 and run:jsconst client = new window.Statsig.StatsigClient('YOUR_SDK_KEY', {}); await client.initializeAsync();Then call:
jsclient.checkGate('mobile_registration');You should see
falsebecause the current session isn’t mobile and doesn’t use the employee email domain.Simulate a mobile environment
Enable the mobile device toolbar in Chrome DevTools and then re-evaluate the user to pick up the new environment and re-check the gate:
jsawait client.updateUserAsync({}); client.checkGate('mobile_registration');The gate should now return
truefor the mobile profile.
Test the employee backdoor
Switch DevTools back to the desktop view and update the user with a company email:
jsawait client.updateUserAsync({ email: 'teammate@statsig.com' }); client.checkGate('mobile_registration');The gate passes again because of the email rule.

Flush exposures and inspect diagnostics
jsclient.flush();Open the gate’s Diagnostics tab. The Exposure Stream table lists each check, including the failing desktop check, the mobile pass, and the employee pass.

Use the gate in production
Wrap feature logic in a gate check so only targeted users see the experience:
if (client.checkGate('mobile_registration')) {
show(mobileRegistrationPage);
} else {
show(oldRegistrationPage);
}
Your feature gate is ready for production.
Was this helpful?
For AI agents: a documentation index is available at /llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.