> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usertick.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript SDK

> The widget's runtime, loaded by a script tag or the @usertick/snippet npm package, and its public methods and events.

The Usertick JavaScript SDK is the runtime that shows website surveys. The script tag and the `@usertick/snippet` npm package load the same runtime and expose the same methods.

> [card] [SDK reference](https://docs.usertick.com/developers/sdk/reference.md)
>
> Every method: init, on, off, show, hide, trigger, identify, logout, reset and destroy.

> [card] [SDK events](https://docs.usertick.com/developers/sdk/events.md)
>
> The open, close, submit and error events and the data each one carries.

> [card] [Install on your website](https://docs.usertick.com/installation/website.md)
>
> The script tag, platform guides and the install check.

> [card] [Install with npm](https://docs.usertick.com/installation/npm.md)
>
> The npm package, with React, Next.js, Vue and Angular examples.

## Load the SDK

```html Script tag theme={null}
<script async src="https://cdn.usertick.com/s/YOUR_SITE_ID.js"></script>
```

```ts npm theme={null}
import Usertick from "@usertick/snippet";

Usertick.init({ site_id: "YOUR_SITE_ID" });
```

Both use the site ID from **Settings → Sites**. The script tag starts the widget by itself, and the npm package starts it when `init` is called. With the script tag, the API is on `window.Usertick`; with the package, it is the default export.

## How the runtime behaves

* **Asynchronous.** The script tag loads with `async`, so the page never waits for it. When Usertick can't be reached, the page works as usual without the widget.
* **Isolated.** The widget renders inside a closed Shadow DOM, so the page's CSS and the widget's CSS don't affect each other.
* **Queued calls.** The script tag defines `Usertick` before the full runtime loads. Calls to `init`, `on`, `off`, `show`, `hide`, `identify`, `logout`, `reset` and `destroy` made in that time are queued and run in order once it loads. Events sent with `trigger` are kept for 10 seconds after the widget is ready.
* **Offline queue.** When a response can't be sent because of a network error, the runtime keeps it in the browser and retries in the background and on later page loads, for up to 7 days. For a survey with a closing date, a response given before the close is accepted only when it arrives within 3 days of it.
* **One runtime per page.** When the script tag and the npm package are both on a page, the second copy finds the first and stays idle.
* **Domain check.** The runtime shows surveys only on the domain of the site whose ID it carries, and on its subdomains.
* **Route changes.** The runtime follows client-side navigation in single page apps, so page rules are checked again after each route change.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.