@tell-rs/browser 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -0
- package/dist/index.cjs +1291 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +1268 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @tell-rs/browser
|
|
2
|
+
|
|
3
|
+
Tell SDK for browsers — analytics events, structured logging, automatic sessions, and privacy controls.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
# npm
|
|
9
|
+
npm install @tell-rs/browser
|
|
10
|
+
|
|
11
|
+
# yarn
|
|
12
|
+
yarn add @tell-rs/browser
|
|
13
|
+
|
|
14
|
+
# pnpm
|
|
15
|
+
pnpm add @tell-rs/browser
|
|
16
|
+
|
|
17
|
+
# bun
|
|
18
|
+
bun add @tell-rs/browser
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import tell from "@tell-rs/browser";
|
|
25
|
+
|
|
26
|
+
tell.configure("your-api-key");
|
|
27
|
+
|
|
28
|
+
// Track an event
|
|
29
|
+
tell.track("Button Clicked", { button: "signup" });
|
|
30
|
+
|
|
31
|
+
// Identify a user (persisted to localStorage)
|
|
32
|
+
tell.identify("user_123", { name: "Alice" });
|
|
33
|
+
|
|
34
|
+
// Structured logging
|
|
35
|
+
tell.logInfo("Checkout started", "commerce");
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Events called before `configure()` are automatically queued and replayed.
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
### `tell.configure(apiKey, options?)`
|
|
43
|
+
|
|
44
|
+
Initialize the SDK. Call once on page load.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
tell.configure("your-api-key", {
|
|
48
|
+
// All options below are optional:
|
|
49
|
+
endpoint: "https://collect.tell.app", // default
|
|
50
|
+
batchSize: 20, // events per batch
|
|
51
|
+
flushInterval: 5_000, // ms between auto-flushes
|
|
52
|
+
maxRetries: 5, // retry attempts on failure
|
|
53
|
+
closeTimeout: 5_000, // ms to wait on close()
|
|
54
|
+
networkTimeout: 10_000, // ms per HTTP request
|
|
55
|
+
logLevel: "error", // "error" | "warn" | "info" | "debug"
|
|
56
|
+
disabled: false, // disable all tracking
|
|
57
|
+
maxQueueSize: 1000, // max queued items
|
|
58
|
+
sessionTimeout: 1_800_000, // 30 min session timeout
|
|
59
|
+
persistence: "localStorage", // "localStorage" | "memory"
|
|
60
|
+
respectDoNotTrack: false, // honor browser DNT setting
|
|
61
|
+
botDetection: true, // auto-disable for bots
|
|
62
|
+
onError: (err) => console.error(err),
|
|
63
|
+
beforeSend: (event) => event, // transform/filter events
|
|
64
|
+
beforeSendLog: (log) => log, // transform/filter logs
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Events
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
tell.track(eventName, properties?)
|
|
72
|
+
tell.identify(userId, traits?)
|
|
73
|
+
tell.group(groupId, properties?)
|
|
74
|
+
tell.revenue(amount, currency, orderId, properties?)
|
|
75
|
+
tell.alias(previousId, userId)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
No `userId` parameter on `track`, `group`, or `revenue` — the browser SDK uses an implicit user ID set by `identify()` and falls back to an anonymous device ID.
|
|
79
|
+
|
|
80
|
+
### Logging
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
tell.log(level, message, service?, data?)
|
|
84
|
+
|
|
85
|
+
// Convenience methods
|
|
86
|
+
tell.logError(message, service?, data?)
|
|
87
|
+
tell.logWarning(message, service?, data?)
|
|
88
|
+
tell.logInfo(message, service?, data?)
|
|
89
|
+
tell.logDebug(message, service?, data?)
|
|
90
|
+
// ... and logEmergency, logAlert, logCritical, logNotice, logTrace
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Privacy
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
tell.optOut() // stop tracking, persisted
|
|
97
|
+
tell.optIn() // resume tracking
|
|
98
|
+
tell.isOptedOut() // check status
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Super Properties
|
|
102
|
+
|
|
103
|
+
Properties automatically attached to every event:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
tell.register({ app_version: "1.2.0" })
|
|
107
|
+
tell.unregister("app_version")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Lifecycle
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
tell.enable() // re-enable after disable()
|
|
114
|
+
tell.disable() // pause tracking
|
|
115
|
+
tell.reset() // clear user, device, session (e.g. on logout)
|
|
116
|
+
await tell.flush() // flush pending events
|
|
117
|
+
await tell.close() // flush + shut down
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Config Presets
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import tell, { development, production } from "@tell-rs/browser";
|
|
124
|
+
|
|
125
|
+
tell.configure("your-api-key", development()); // localhost, debug logging
|
|
126
|
+
tell.configure("your-api-key", production()); // defaults, error-only logging
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Features
|
|
130
|
+
|
|
131
|
+
- **Automatic sessions** — rotated on 30-min inactivity or tab hidden/visible
|
|
132
|
+
- **Pre-init queue** — events called before `configure()` are buffered and replayed
|
|
133
|
+
- **sendBeacon flush** — events are flushed via `navigator.sendBeacon` on page unload
|
|
134
|
+
- **Bot detection** — auto-disables for headless browsers and bots
|
|
135
|
+
- **localStorage persistence** — device ID, user ID, session, and super properties survive page reloads
|
|
136
|
+
- **Do Not Track** — optional respect for `navigator.doNotTrack`
|
|
137
|
+
|
|
138
|
+
## Framework Integrations
|
|
139
|
+
|
|
140
|
+
For React, Next.js, and Vue, use the dedicated packages:
|
|
141
|
+
|
|
142
|
+
- [`@tell-rs/react`](https://www.npmjs.com/package/@tell-rs/react) — React provider and hooks
|
|
143
|
+
- [`@tell-rs/nextjs`](https://www.npmjs.com/package/@tell-rs/nextjs) — Next.js auto page tracking
|
|
144
|
+
- [`@tell-rs/vue`](https://www.npmjs.com/package/@tell-rs/vue) — Vue plugin and composable
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT
|