# 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:

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

let analytics = crowne("YOUR_SITE_ID");
```

It sends a page view now, on each in-app navigation, and when the browser restores a page from its back/forward cache. It sees in-app navigation through the Navigation API, or through the History API in browsers without it, so client-side routers need no setup.

## crowne(site, options?)

| Option     | Use                                                                                                           |
| ---------- | ------------------------------------------------------------------------------------------------------------- |
| `endpoint` | Where events go. Default: `https://in.crowne.io/v1/events`. Set it for a [custom domain](./custom-domain.md). |
| `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`.                                               |

Behind a [first-party proxy](./proxy.md), which adds the site id itself, give only the options: `crowne({ endpoint: "/api/event" })`.

## track(name, props?)

Sends a [custom event](./events.md):

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

## pageview(url?)

Sends a page view, for the current address or for `url`. Use it with `manual` when your router shows a page:

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

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