open-index/open-npm huggingface dataset:
npm package: @getcandle/web-sdk
Description: This is the web SDK for [Candle](https://getcandle.app). It allows you to record user sessions on your website and analyze them in your Candle dashboard.
Author: Nick Elsbree
Latest version: 0.0.25

# Candle Web SDK

This is the web SDK for [Candle](https://getcandle.app). It allows you to record user sessions on your website and analyze them in your Candle dashboard.

## Installation

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

## Usage

```ts
import { init, setUser, trackEvent } from "@getcandle/web-sdk";

// Initialize the SDK and begin recording.
init({
  token: process.env.NEXT_PUBLIC_CANDLE_API_KEY,
  // The network requests config is optional (everything is enabled by default).
  networkRequests: {
    enabled: true,
    recordHeaders: true,
    recordRequestBody: true,
    recordResponseBody: true,
  },
  // The user config is optional, and can be set later using the setUser function.
  user: {
    id: "123",
    name: "John Doe",
    email: "john.doe@example.com",
  },
  // The release key allows you to specify the version of your application that the session belongs to.
  release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
});

// Set the user for the session. This can only be called after the SDK has been initialized.
setUser({
  id: "123",
  name: "John Doe",
  email: "john.doe@example.com",
});

// Track a custom event.
trackEvent("Add to Cart", {
  product_id: 578,
  product_name: "Vintage Three Wolf Moon Tee",
  value: 2500,
});
```

## Contributing

1. Clone the repo
1. Build changes with `yarn build-dev`.
1. To test your changes in a local version of another website, you can run `yarn link` in the root of this repo, then `yarn link @getcandle/web-sdk` in the repo of the local codebase you want to test it in. Follow the [Usage instructions](#usage) above to install your changed version of this SDK on the site. 
1. To publish changes, increment the version of the package in package.json, run `yarn build-prod`, and then run `yarn publish`.

*Troubleshooting Note*
If you are trying to import your local version of the package into a Next.js project using Turbopack for builds, you may get a 'module not found' error. Try building your project with webpack instead if that happens.