@qurvo/sdk-browser 0.0.1 → 0.0.2
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 +158 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @qurvo/sdk-browser
|
|
2
|
+
|
|
3
|
+
Browser SDK for [Qurvo](https://qurvo.ru) analytics. Lightweight client-side event tracking with automatic pageview capture, user identification, and reliable event delivery.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @qurvo/sdk-browser
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @qurvo/sdk-browser
|
|
11
|
+
# or
|
|
12
|
+
yarn add @qurvo/sdk-browser
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { qurvo } from '@qurvo/sdk-browser';
|
|
19
|
+
|
|
20
|
+
// Initialize with your project API key
|
|
21
|
+
qurvo.init({
|
|
22
|
+
apiKey: 'qk_your_api_key',
|
|
23
|
+
endpoint: 'https://ingest.yourapp.com',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Track custom events
|
|
27
|
+
qurvo.track('button_click', { button: 'signup', page: '/pricing' });
|
|
28
|
+
|
|
29
|
+
// Identify a user after login
|
|
30
|
+
qurvo.identify('user-123', { email: 'jane@example.com', plan: 'pro' });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
That's it. The SDK automatically tracks pageviews, collects browser context, and batches events for efficient delivery.
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
qurvo.init({
|
|
39
|
+
apiKey: 'qk_...', // Required. Your project API key
|
|
40
|
+
endpoint: 'https://...', // Ingest API URL (default: http://localhost:3001)
|
|
41
|
+
autocapture: true, // Auto-track page navigation (default: true)
|
|
42
|
+
flushInterval: 10000, // Batch send interval in ms (default: 10000)
|
|
43
|
+
flushSize: 10, // Send batch when queue reaches this size (default: 10)
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
### `qurvo.init(config)`
|
|
50
|
+
|
|
51
|
+
Initializes the SDK. Must be called before any other method. Safe to call multiple times (subsequent calls are ignored).
|
|
52
|
+
|
|
53
|
+
When `autocapture` is enabled (default), the SDK automatically:
|
|
54
|
+
- Tracks an initial `$pageview` event
|
|
55
|
+
- Monitors `history.pushState` and `popstate` for SPA navigation
|
|
56
|
+
- Sends a `$pageleave` event and flushes the queue on page unload
|
|
57
|
+
|
|
58
|
+
### `qurvo.track(event, properties?)`
|
|
59
|
+
|
|
60
|
+
Track a custom event.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
qurvo.track('purchase', {
|
|
64
|
+
product_id: 'prod_123',
|
|
65
|
+
amount: 49.99,
|
|
66
|
+
currency: 'USD',
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### `qurvo.identify(userId, userProperties?)`
|
|
71
|
+
|
|
72
|
+
Link the current anonymous user to a known user ID. Sends a `$identify` event that merges the anonymous session history with the identified user.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
qurvo.identify('user-123', {
|
|
76
|
+
email: 'jane@example.com',
|
|
77
|
+
name: 'Jane Doe',
|
|
78
|
+
plan: 'pro',
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### `qurvo.page(properties?)`
|
|
83
|
+
|
|
84
|
+
Manually track a pageview. Called automatically on initialization and SPA navigation when `autocapture` is enabled.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
qurvo.page({ section: 'docs' });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `qurvo.set(properties)`
|
|
91
|
+
|
|
92
|
+
Set user properties. Overwrites existing values.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
qurvo.set({ plan: 'enterprise', company: 'Acme Inc.' });
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `qurvo.setOnce(properties)`
|
|
99
|
+
|
|
100
|
+
Set user properties only if they haven't been set before. Useful for first-touch attribution.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
qurvo.setOnce({ referral_source: 'google', first_seen: new Date().toISOString() });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `qurvo.reset()`
|
|
107
|
+
|
|
108
|
+
Clear the current user identity and all stored IDs. Call this on logout.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
qurvo.reset();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Automatic Context
|
|
115
|
+
|
|
116
|
+
Every event includes browser context collected automatically:
|
|
117
|
+
|
|
118
|
+
| Field | Example |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `session_id` | `a1b2c3d4-...` (unique per tab) |
|
|
121
|
+
| `url` | `https://app.example.com/dashboard` |
|
|
122
|
+
| `referrer` | `https://google.com` |
|
|
123
|
+
| `page_title` | `Dashboard - My App` |
|
|
124
|
+
| `page_path` | `/dashboard` |
|
|
125
|
+
| `screen_width` | `1920` |
|
|
126
|
+
| `screen_height` | `1080` |
|
|
127
|
+
| `language` | `en-US` |
|
|
128
|
+
| `timezone` | `America/New_York` |
|
|
129
|
+
|
|
130
|
+
## How It Works
|
|
131
|
+
|
|
132
|
+
- **Anonymous ID** is generated on first visit and persisted in `localStorage`, so the same user is recognized across sessions.
|
|
133
|
+
- **Session ID** is stored in `sessionStorage`, giving each tab its own session that ends when the tab closes.
|
|
134
|
+
- **Event queue** batches events and sends them every 10 seconds or when the batch reaches 10 events.
|
|
135
|
+
- **Page unload** triggers a final flush using `keepalive` fetch to ensure no events are lost.
|
|
136
|
+
- **Retry with backoff** on network failures: 1s, 2s, 4s, 8s... up to 30s between retries.
|
|
137
|
+
|
|
138
|
+
## Special Events
|
|
139
|
+
|
|
140
|
+
| Event | Trigger |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `$pageview` | `init()`, SPA navigation (`pushState`, `popstate`) |
|
|
143
|
+
| `$pageleave` | Page visibility change (hidden) or `beforeunload` |
|
|
144
|
+
| `$identify` | `identify()` call |
|
|
145
|
+
| `$set` | `set()` call |
|
|
146
|
+
| `$set_once` | `setOnce()` call |
|
|
147
|
+
|
|
148
|
+
## TypeScript
|
|
149
|
+
|
|
150
|
+
The package ships with full TypeScript type definitions.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { qurvo, type BrowserSdkConfig } from '@qurvo/sdk-browser';
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qurvo/sdk-browser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Browser SDK for Qurvo analytics — event tracking, user identification, auto-capture",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@qurvo/sdk-core": "0.0.
|
|
15
|
+
"@qurvo/sdk-core": "0.0.2"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "^5.7.0",
|