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

# Track custom events and identify visitors

> Send Datasite custom events and manual page views, associate sessions with stable user IDs, and control persistent visitor identity.

Datasite's browser API records meaningful product actions, manual page views, and stable application identities. Do not send secrets or unnecessary personal data.

## Track an event

```js theme={null}
await datasite.track('signup-button');
```

Add properties when they explain the action:

```js theme={null}
await datasite.track('checkout-completed', {
  plan: 'pro',
  seats: 4,
  couponApplied: true,
});
```

Event names longer than 50 characters are truncated. Numbers keep up to four decimal places, strings have a maximum stored length of 500 characters, arrays become strings, and an object can contain up to 50 properties.

> [!WARNING]
>
> Do not send passwords, authentication tokens, payment card data, private messages, or other sensitive values in event properties.

## Track a manual page view

Disable automatic tracking before sending manual page views:

```html theme={null}
<script defer src="https://app.datasite.sh/script.js"
  data-website-id="YOUR_WEBSITE_ID"
  data-auto-track="false"></script>
```

```js theme={null}
await datasite.track();
```

You can override page properties:

```js theme={null}
await datasite.track({
  website: 'YOUR_WEBSITE_ID',
  url: '/account/billing',
  title: 'Billing',
});
```

## Identify a signed-in user

```js theme={null}
await datasite.identify('user-123', {
  plan: 'pro',
  accountType: 'company',
});
```

Use a stable ID that does not expose an email address or another unnecessary personal value. Supplied properties become available as session or user properties for filtering and analysis.

## Opt out or opt in

```js theme={null}
datasite.optOut();
datasite.optIn();
```

Opting out deletes the persistent visitor identifier and stops sending `visitor_id`. The current session can still send page views and events. Opting back in creates a new identifier.

```js theme={null}
const visitorId = datasite.getVisitorId();
```

`getVisitorId()` returns `null` when persistent identity is disabled.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.