Skip to main content

HTML Snippet SDK

Install the SDK

You can install the Statsig SDK by putting a script tag in the head of your HTML file:

<script src="https://cdn.jsdelivr.net/npm/@statsig/js-client@3/build/statsig-js-client+session-replay+web-analytics.min.js?apikey=YOUR_CLIENT_API_KEY">
</script>

Note that you need to replace YOUR_CLIENT_API_KEY with your actual client API key from the Project Settings > API Keys.

Initialize the SDK

The HTML snippet we provide wraps an instance of the statsig javascript sdk. Simply providing your client API key in the url is enough to auto initialize the SDK, as the installation step recommends.

However, you should likely move to a manual initialization if you need any of the following:

  • custom user properties
  • custom initialization options
  • check gates, configs, experiments, or log events

To manually initialize an instance of the sdk, remove the key parameter from the script tag, and do the following:

const { StatsigClient, runStatsigAutoCapture, runStatsigSessionReplay } = window.Statsig;

const client = new StatsigClient(
'<CLIENT-SDK-KEY>',
{ userID: 'a-user' }
);

runStatsigSessionReplay(client);
runStatsigAutoCapture(client);

await client.initializeAsync();

// check gates, configs, experiments, or log events

The StatsigClient instance you create is also available via window.Statsig, so you can reference it globally.

At this point, you have access to all of the methods available in the Javascript SDK via your instance of the StatsigClient. Refer to that documentation for initialization details and core methods.