> For the complete documentation index, see [llms.txt](https://docs.keewano.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keewano.com/sdks/web.md).

# Web SDK

Install the Keewano SDK in a web page — with a bundler, or with a script tag and no build step.

`@keewano/web-sdk` is the browser build. It runs inside your page, tracks the usual behaviour automatically, and posts events to the JSON ingestion API.

{% hint style="warning" %}
**Three things differ from the device SDKs:**

* The **consent gate is on by default** — nothing is sent until the page grants consent.
* `endpoint` is an **origin** here, not a full ingress base.
* **No SDK call can throw into your page.** Every `Keewano.*` method is wrapped; an internal failure is reported with `console.error` and never propagates.
  {% endhint %}

## 1. Install

### With a bundler

```bash
npm install @keewano/web-sdk
```

```typescript
import { Keewano } from '@keewano/web-sdk';

Keewano.init({ apiKey: 'your-project-api-key' });
```

There are no peer dependencies to add — the SDK uses the browser's own storage.

### Without a build step

The package ships an IIFE bundle at a fixed path, so any npm CDN can serve it. The bundle installs a lowercase `keewano` global with the same methods as the npm import:

```html
<script src="https://unpkg.com/@keewano/web-sdk@VERSION/dist/browser/keewano.iife.js"></script>
<script>
  keewano.init({ apiKey: 'your-project-api-key' });
</script>
```

{% hint style="danger" %}
**Always pin a `VERSION`.** Without it the URL resolves to whatever is newest, so a future release would start running on your pages without you deploying anything.
{% endhint %}

That tag loads the bundle **synchronously**, so the global exists by the time the next script runs.

To load it asynchronously instead, paste the command-queue stub before the async tag — it defines `keewano` up front, so calls made while the bundle is still in flight are queued and replayed in order once it arrives. Copy the stub verbatim from the [`@keewano/web-sdk` package readme](https://www.npmjs.com/package/@keewano/web-sdk); it freezes into your HTML with the paste and cannot be hotfixed later.

{% hint style="warning" %}
Do not write your own `<script async>` tag without that stub. Any `keewano.*` call the page makes before the bundle lands would hit an undefined global.
{% endhint %}

## 2. Consent — collected and held by default

On the web, `requirePlayerConsent` defaults to **`true`** — the opposite of the device SDKs. A fresh origin boots **Pending**: events are collected and held in browser storage from the first moment, and nothing is sent.

```typescript
Keewano.setUserConsent(true);  // grant: the held data ships, delivery continues
Keewano.setUserConsent(false); // deny: everything held is deleted, nothing is sent
```

* **Grant** — the decision is recorded, the send loop wakes immediately so held data ships now rather than waiting out the idle window, and delivery stays open for the session.
* **Withdrawal** — in-memory buffers are cleared and every queued batch file is deleted right away, not at the next tick. The loop keeps running and keeps dropping whatever is reported afterwards, so nothing accumulates behind a denied gate.

Wire the call to your consent banner. It is async, resolves once the decision is recorded, and needs `init` to have been issued first.

## 3. Report your own events

```typescript
Keewano.reportButtonClick('Play');
```

For events specific to your product beyond the built-in set, see [Custom Events Codegen](https://docs.keewano.com/sdks/custom-events-codegen.md) — use the `web` target.

***

## Full documentation

The SDK's own browser guide covers what this page summarises, plus Content Security Policy, supported browsers, multi-tab behaviour, page-close handling, storage lifetime, and limits:

|                                                                                                      |                                     |
| ---------------------------------------------------------------------------------------------------- | ----------------------------------- |
| [Browser (Web SDK)](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/web.md)                 | The full browser guide              |
| [Configuration](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/configuration.md)           | Every `init` option                 |
| [Automatic Tracking](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/automatic-tracking.md) | What is captured with no extra code |
| [Event Types](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/event-types.md)               | The full map of events              |
| [Privacy](https://github.com/Keewano/TypeScript-SDK/blob/main/docs/privacy.md)                       | Consent gate and opt-out            |

Package: [`@keewano/web-sdk`](https://www.npmjs.com/package/@keewano/web-sdk) · Source: [github.com/Keewano/TypeScript-SDK](https://github.com/Keewano/TypeScript-SDK)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keewano.com/sdks/web.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
