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

# Introduction

> Install and integrate the core SDK into any webpage or browser environment.

The `@sleek/sdk` package provides the foundational JavaScript SDK for Sleek, supporting multiple bundling formats (IIFE, ESM, CJS). You can use it directly in web pages via script injection or install it via a package manager in modern frontend setups.

This guide walks you through installation, setup, and core usage of the SDK.

<Note>
  Before you start, ensure that you have your Sleek credentials on hand.
  [Contact support](mailto:support@onsleek.com) if you need help with your
  credentials.
</Note>

## Installation

<Note>
  If you're planning to use the SDK via script injection (IIFE), you do not need to install it via a package manager. Just follow the [IIFE Usage](#iife-usage) section.
</Note>

### Install via NPM (CJS / ESM)

The `@sleek/sdk` package is hosted on Sleek's private package repository.

#### Configure `.npmrc`

```bash theme={null}
@sleek:registry=https://npm.cloudsmith.io/sleek/sleek/
//npm.cloudsmith.io/sleek/sleek/:_authToken={YOUR_TOKEN_HERE}
```

Replace `{YOUR_TOKEN_HERE}` with your SDK access token.

#### Add to your project

```bash theme={null}
# Using npm
npm install @sleek/sdk

# Using pnpm
pnpm add @sleek/sdk
```

## IIFE Usage

If you're injecting the SDK into pages (e.g., via script tags), you can use the IIFE bundle directly.

### Download SDK package

```bash theme={null}
TOKEN="{YOUR_TOKEN_HERE}"; curl -s -L -H "Authorization: Bearer ${TOKEN}" "https://npm.cloudsmith.io/sleek/sleek/@sleek/sdk/latest" | jq -r '.dist.tarball' | xargs -I {} curl -s -L -H "Authorization: Bearer ${TOKEN}" {} | tar -xzvf -
```

This will extract the SDK files locally.

You will need the following files:

* `sdk.iife.js`: The main SDK file
* `f.js`: A supporting script required for the SDK to function properly in-page

### Inject into the Page

Make sure these files are injected into the page **before any other scripts**, ideally at the top of the `<head>`:

```html theme={null}
<script src="f.js"></script>
<script src="sdk.iife.js"></script>
<script>
  sleek.initializeSdk("YOUR_PUBLIC_API_KEY_HERE", {}, [
    (event) => {
      console.log("SDK event:", event);
    }
  ]);
  // Use SDK
  sleek.getSdk().startCouponAutoApply(["SAVE10"]);
</script>
```

The `sleek` object will be available on `globalThis`.

## Initialization

Call `initializeSdk` with your **public** Sleek API key to initialize the SDK:

```ts theme={null}
import { initializeSdk } from "@sleek/sdk";

initializeSdk("YOUR_PUBLIC_API_KEY_HERE", {
  // Optional configuration options
}, [(event) => {console.log("Received event", event);}]);
```

Once initialized, retrieve the SDK instance:

```ts theme={null}
import { getSdk } from "@sleek/sdk";

getSdk().startCouponAutoApply(["SAVE10"]);
```

## Core Features

The `@sleek/sdk` provides a tab/page-agnostic interface that powers:

* [Coupon auto-apply]()
* [Page classification]()
* [Product extraction]()
* [Order extraction]()

Refer to the [TypeDoc reference](/js-sdk-reference/type-doc) for full API documentation.

## Events

To listen for SDK events, pass an array of listener functions to `initializeSdk` as the third argument:

```ts theme={null}
initializeSdk("YOUR_PUBLIC_API_KEY_HERE", {}, [
  (event) => {
    console.log("SDK Event:", event);
  }
]);
```

Each listener receives an event of type [`SdkEvent`](/js-sdk-reference/type-doc).

## File Formats

| Format | File          | Use Case                               |
| ------ | ------------- | -------------------------------------- |
| IIFE   | `sdk.iife.js` | Script tag or runtime script injection |
| ESM    | `sdk.esm.js`  | Modern bundlers (Vite, Webpack, etc.)  |
| CJS    | `sdk.cjs.js`  | Node or CommonJS environments          |

## What's Next

Once you’ve installed and initialized the SDK, you can extend your integration with:

<CardGroup col={2}>
  <Card title="Enable coupon auto-apply" icon="robot" href="/js-sdk-reference/coupon-auto-apply">
    Learn how to enable coupon auto-apply.
  </Card>

  <Card title="Page classification" icon="shapes" href="/js-sdk-reference/page-classification">
    Learn how to enable page classification.
  </Card>

  <Card title="Product extraction" icon="pickaxe" href="/js-sdk-reference/extraction">
    Learn how to enable product extraction.
  </Card>

  <Card title="Order extraction" icon="cart-shopping" href="/js-sdk-reference/extraction">
    Learn how to enable order extraction.
  </Card>

  <Card title="View TypeDoc" icon="terminal" href="/js-sdk-reference/type-doc">
    Browse the reference TypeDoc for the SDK.
  </Card>
</CardGroup>

***

Need help? [Contact our support team](mailto:support@onsleek.com).
