---
title: HTML Snippet
description: Add Statsig to web pages with an HTML script tag
product: general
token_estimate: 693
---
# HTML Snippet

> For AI agents: a documentation index is available at [/llms.txt](/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

- **Repository:** [js-client-sdk](https://github.com/statsig-io/js-client-sdk)

## Set up the SDK

1. **Install the SDK**

   Install the Statsig SDK by adding a script tag to the head of your HTML file:

   ```js
   <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"
     crossorigin="anonymous"
   >
   </script>
   ```

   Replace `YOUR_CLIENT_API_KEY` with your actual client API key from [Project Settings > API Keys](https://console.statsig.com/api_keys).
2. **Initialize the SDK**

   The HTML snippet wraps an instance of the Statsig JavaScript SDK. Providing your client API key in the URL auto-initializes the SDK, as shown in the installation step.

   Move to 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:

   ```js
   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
   ```

   You can also access the `StatsigClient` instance you create through `window.Statsig`, so you can reference it globally.

   Your `StatsigClient` instance provides access to all methods in the [JavaScript SDK](https://docs.statsig.com/client/javascript-sdk). Go to that documentation for initialization details and core methods.

#### Can I customize the initialization logic

Yes. Remove the client API key from the URL. The HTML snippet is the JavaScript SDK. Providing an API key in the URL auto-initializes an instance. To skip auto-initialization, omit the key and create your own instance. Go to the [JavaScript SDK Getting Started Guide](https://docs.statsig.com/client/javascript-sdk#getting-started) for details.

Creating an instance using the HTML snippet differs from installing through npm:

```js
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
```

