---
**📚 Main Documentation:** [Hoko API Documentation (llms.txt)](https://hoko.to/docs/llms.txt)
This is an individual endpoint documentation file. For the complete API reference, see the main documentation above.
---
# Browser attribution script (analytics.js)
Persist the clickId from short-link redirects using analytics.js and send it to conversion endpoints.
**Category:** Conversion Tracking
## Overview

The browser attribution script (`/analytics.js`) captures the `hoko_id` query parameter that Hoko appends to destination URLs and stores it as a cookie. This gives you a persistent clickId that you can send later when tracking leads or sales.

## What it does

- Reads `hoko_id` from the current page URL
- Stores it in a cookie named `hoko_id` for 90 days
- Replaces the existing `hoko_id` cookie when the current page URL contains a new `hoko_id`
- Does not send any network requests

> **Info: Lightweight by design**
> The script only writes the cookie. It does not call any tracking endpoints automatically.

## Add the script

Include the script on pages where users land after clicking a Hoko short link.

```html
<script src="https://hoko.to/analytics.js" defer></script>
```

## Read the cookie and send events

Read the `hoko_id` cookie and pass it as `clickId` to conversion tracking endpoints.

```javascript
const clickId = document.cookie
	.split('; ')
	.find((row) => row.startsWith('hoko_id='))
	?.split('=')[1];

await fetch('https://hoko.to/api/track/lead', {
	method: 'POST',
	headers: {
		Authorization: 'Bearer <API_KEY>',
		'Content-Type': 'application/json'
	},
	body: JSON.stringify({
		clickId: clickId ?? '',
		eventName: 'Sign up',
		customerExternalId: 'customer_123',
		customerName: 'John Doe'
	})
});
```

## When it runs

The script runs when the browser loads it. It must execute on the same domain where you want the cookie to be stored.

---

**Back to main documentation:** [Hoko API Documentation (llms.txt)](https://hoko.to/docs/llms.txt)