# npm package

Use the `crowne` package when your app has a bundler. The client ships in your bundle, so the page loads no third-party script.

```sh
npm install crowne
```

Start the client once, when the app starts. It sends a page view now, on each in-app navigation, and when the browser restores a page from its back/forward cache.

```ts
import { crowne } from "crowne/browser";

let analytics = crowne("YOUR_SITE_ID");

analytics.track("signup", { plan: "pro" });
```

## Options

| Option     | Use                                                               |
| ---------- | ----------------------------------------------------------------- |
| `endpoint` | Where events go. Default: `https://in.crowne.io/v1/events`.       |
| `hash`     | Count `#hash` changes as page views, for apps that route by hash. |
| `manual`   | Send no page views on its own. Call `pageview()` yourself.        |
| `fetch`    | The `fetch` function to send with. Default: the global `fetch`.   |

## Page views by hand

Set `manual`, then call `pageview()` when your router shows a page. Give it a URL to count a different address than the current one.

```js
let analytics = crowne("YOUR_SITE_ID", { manual: true });

analytics.pageview();
analytics.pageview("https://example.com/checkout/done");
```

## Send events to your endpoint

Set `endpoint` to your [custom domain](./custom-domain.md) or to a [proxy path](./proxy.md) on your site. Then no request from the page goes to a crowne host. With a proxy path, this is the strongest setup against [ad blockers](./blockers.md).

```js
let analytics = crowne("YOUR_SITE_ID", { endpoint: "/api/event" });
```
