Skip to content

Commit 8aea5f5

Browse files
committed
chore: analytics package readme
1 parent 1c36d78 commit 8aea5f5

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎packages/analytics/README.md‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# @segmento/analytics
2+
3+
Referral impression tracking for the [Segmento](https://segmento.tech) SDK. Reads the referral code from the URL, stores it in a session cookie, and fires a single impression event per session.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @segmento/analytics
9+
```
10+
11+
## Usage
12+
13+
### Script tag (no bundler)
14+
15+
Add this at the end of your `<body>`. The script runs automatically on load.
16+
17+
```html
18+
<script src="https://cdn.jsdelivr.net/npm/@segmento/analytics@latest/dist/script.js"></script>
19+
```
20+
21+
To use a custom API base URL (e.g. staging):
22+
23+
```html
24+
<script
25+
src="https://cdn.jsdelivr.net/npm/@segmento/analytics@latest/dist/script.js"
26+
data-api-url="https://staging.segmento.tech/manager-api"
27+
></script>
28+
```
29+
30+
### ES module
31+
32+
Call once at page load.
33+
34+
```ts
35+
import { segmentoAnalytics } from "@segmento/analytics";
36+
37+
segmentoAnalytics();
38+
```
39+
40+
With options:
41+
42+
```ts
43+
segmentoAnalytics({ baseUrl: "https://staging.segmento.tech/manager-api" });
44+
```
45+
46+
## Behaviour
47+
48+
1. Reads the `?ref=` query parameter from the current URL.
49+
2. If present, stores it in a `sgm_ref` session cookie for use by `@segmento/lead`.
50+
3. Fires a `POST /redeem` impression to the Segmento API with the full page URL.
51+
4. Sets a `sgm_impression_sent` session cookie so the impression is only sent once per session.
52+
53+
The impression request is fire-and-forget — it never blocks the page.
54+
55+
## API
56+
57+
| Export | Description |
58+
|---|---|
59+
| `segmentoAnalytics(options?)` | Run analytics on page load |
60+
61+
### Options
62+
63+
| Option | Type | Description |
64+
|---|---|---|
65+
| `baseUrl` | `string` | Override the Segmento API base URL |
66+
| `fetchImpl` | `typeof fetch` | Override the fetch implementation |

0 commit comments

Comments
 (0)