crexperium-sdk 1.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/LICENSE +21 -0
- package/README.md +482 -0
- package/dist/browser.js +2 -0
- package/dist/browser.js.map +1 -0
- package/dist/client.d.ts +55 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/errors.d.ts +47 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13850 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +13823 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plugins/auto-page-view.d.ts +21 -0
- package/dist/plugins/auto-page-view.d.ts.map +1 -0
- package/dist/plugins/device-info.d.ts +30 -0
- package/dist/plugins/device-info.d.ts.map +1 -0
- package/dist/plugins/session-replay.d.ts +106 -0
- package/dist/plugins/visitor-id.d.ts +29 -0
- package/dist/plugins/visitor-id.d.ts.map +1 -0
- package/dist/resources/base.d.ts +20 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/contacts.d.ts +31 -0
- package/dist/resources/contacts.d.ts.map +1 -0
- package/dist/resources/deals.d.ts +31 -0
- package/dist/resources/deals.d.ts.map +1 -0
- package/dist/resources/events.d.ts +27 -0
- package/dist/resources/events.d.ts.map +1 -0
- package/dist/types/common.d.ts +20 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/contacts.d.ts +78 -0
- package/dist/types/contacts.d.ts.map +1 -0
- package/dist/types/deals.d.ts +71 -0
- package/dist/types/deals.d.ts.map +1 -0
- package/dist/types/events.d.ts +76 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/session-replay.d.ts +213 -0
- package/dist/utils/device.d.ts +25 -0
- package/dist/utils/device.d.ts.map +1 -0
- package/dist/utils/http.d.ts +53 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/storage.d.ts +23 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Crexperium
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
# Crexperium SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript SDK for Crexperium CRM. Track events, manage contacts, and handle deals with ease in both Node.js and browser environments.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Universal**: Works in Node.js and browsers
|
|
8
|
+
- 📦 **TypeScript**: Full TypeScript support with type definitions
|
|
9
|
+
- 🔄 **Auto-tracking**: Automatic page view tracking for browsers
|
|
10
|
+
- 🎬 **Session Replay**: Record and replay user sessions with rrweb
|
|
11
|
+
- 🎯 **Event Tracking**: Track custom events and user interactions
|
|
12
|
+
- 👤 **Contact Management**: Identify and manage contacts
|
|
13
|
+
- 💼 **Deal Management**: Create and manage sales pipeline deals
|
|
14
|
+
- 🔌 **Plugin System**: Extensible plugin architecture
|
|
15
|
+
- ⚡ **Retry Logic**: Automatic retry with exponential backoff
|
|
16
|
+
- 🛡️ **Error Handling**: Comprehensive error classes
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install crexperium-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### Node.js
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { CRMClient } from 'crexperium-sdk';
|
|
30
|
+
|
|
31
|
+
// Initialize the client
|
|
32
|
+
const client = new CRMClient({
|
|
33
|
+
apiToken: process.env.CRX_API_TOKEN,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Track an event
|
|
37
|
+
await client.events.track({
|
|
38
|
+
eventKey: 'purchase',
|
|
39
|
+
visitorId: 'user_123',
|
|
40
|
+
eventData: {
|
|
41
|
+
value: 99.99,
|
|
42
|
+
currency: 'USD',
|
|
43
|
+
productId: 'prod_456',
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Identify a contact
|
|
48
|
+
const { contact, created } = await client.contacts.identify({
|
|
49
|
+
externalId: 'user_123',
|
|
50
|
+
email: 'user@example.com',
|
|
51
|
+
firstName: 'John',
|
|
52
|
+
lastName: 'Doe',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Create a deal
|
|
56
|
+
const deal = await client.deals.create({
|
|
57
|
+
name: 'Enterprise Deal',
|
|
58
|
+
amount: 50000,
|
|
59
|
+
currency: 'USD',
|
|
60
|
+
contactEmail: 'user@example.com',
|
|
61
|
+
priority: 'HIGH',
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Browser (ES Module)
|
|
66
|
+
|
|
67
|
+
```html
|
|
68
|
+
<script type="module">
|
|
69
|
+
import { CRMClient } from 'https://cdn.jsdelivr.net/npm/crexperium-sdk/dist/index.mjs';
|
|
70
|
+
|
|
71
|
+
const client = new CRMClient({
|
|
72
|
+
apiToken: 'your-api-token',
|
|
73
|
+
autoPageView: true, // Automatically track page views
|
|
74
|
+
autoDeviceInfo: true, // Automatically collect device information
|
|
75
|
+
persistVisitorId: true, // Persist visitor ID in localStorage
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Track custom events
|
|
79
|
+
await client.events.track({
|
|
80
|
+
eventKey: 'button_click',
|
|
81
|
+
eventData: { button: 'signup' },
|
|
82
|
+
});
|
|
83
|
+
</script>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Browser (UMD via CDN)
|
|
87
|
+
|
|
88
|
+
```html
|
|
89
|
+
<script src="https://cdn.jsdelivr.net/npm/crexperium-sdk/dist/browser.js"></script>
|
|
90
|
+
<script>
|
|
91
|
+
const client = new Crexperium.CRMClient({
|
|
92
|
+
apiToken: 'your-api-token',
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// The client is now available globally
|
|
96
|
+
client.events.track({
|
|
97
|
+
eventKey: 'page_load',
|
|
98
|
+
pageUrl: window.location.href,
|
|
99
|
+
});
|
|
100
|
+
</script>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## API Reference
|
|
104
|
+
|
|
105
|
+
### Configuration
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface SDKConfig {
|
|
109
|
+
apiToken: string; // Required: Your API token
|
|
110
|
+
baseUrl?: string; // Optional: API base URL (default: https://crxperium.applikuapp.com)
|
|
111
|
+
timeout?: number; // Optional: Request timeout in ms (default: 30000)
|
|
112
|
+
maxRetries?: number; // Optional: Max retry attempts (default: 3)
|
|
113
|
+
retryDelay?: number; // Optional: Initial retry delay in ms (default: 1000)
|
|
114
|
+
|
|
115
|
+
// Browser-specific options
|
|
116
|
+
autoPageView?: boolean; // Optional: Auto-track page views (default: true)
|
|
117
|
+
autoDeviceInfo?: boolean; // Optional: Auto-collect device info (default: true)
|
|
118
|
+
persistVisitorId?: boolean; // Optional: Persist visitor ID (default: true)
|
|
119
|
+
visitorIdKey?: string; // Optional: localStorage key for visitor ID (default: 'crx_visitor_id')
|
|
120
|
+
|
|
121
|
+
// Session replay options
|
|
122
|
+
sessionReplay?: SessionReplayConfig; // Optional: Session replay configuration
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Events
|
|
127
|
+
|
|
128
|
+
#### Track a single event
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
await client.events.track({
|
|
132
|
+
eventKey: string; // Required: Event identifier
|
|
133
|
+
visitorId?: string; // Optional: Visitor ID
|
|
134
|
+
userProperties?: object; // Optional: User properties
|
|
135
|
+
eventData?: object; // Optional: Event data
|
|
136
|
+
pageUrl?: string; // Optional: Page URL
|
|
137
|
+
pageTitle?: string; // Optional: Page title
|
|
138
|
+
referrer?: string; // Optional: Referrer URL
|
|
139
|
+
userAgent?: string; // Optional: User agent
|
|
140
|
+
deviceType?: string; // Optional: Device type
|
|
141
|
+
browser?: string; // Optional: Browser name
|
|
142
|
+
os?: string; // Optional: Operating system
|
|
143
|
+
country?: string; // Optional: Country
|
|
144
|
+
city?: string; // Optional: City
|
|
145
|
+
eventTime?: Date | string; // Optional: Event timestamp
|
|
146
|
+
source?: 'web' | 'mobile' | 'server'; // Optional: Event source
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Track multiple events
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
await client.events.trackBatch([
|
|
154
|
+
{ eventKey: 'event1', eventData: { ... } },
|
|
155
|
+
{ eventKey: 'event2', eventData: { ... } },
|
|
156
|
+
// ... up to 100 events
|
|
157
|
+
]);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Get event statistics
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const stats = await client.events.stats(30); // Last 30 days
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Contacts
|
|
167
|
+
|
|
168
|
+
#### Identify a contact
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const { contact, created } = await client.contacts.identify({
|
|
172
|
+
externalId: string; // Required: External ID
|
|
173
|
+
email?: string;
|
|
174
|
+
firstName?: string;
|
|
175
|
+
lastName?: string;
|
|
176
|
+
phone?: string;
|
|
177
|
+
title?: string;
|
|
178
|
+
company?: string;
|
|
179
|
+
customFields?: object;
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### Create a contact
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const contact = await client.contacts.create({
|
|
187
|
+
email: 'user@example.com',
|
|
188
|
+
first_name: 'John',
|
|
189
|
+
last_name: 'Doe',
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Update a contact
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const updated = await client.contacts.update(contactId, {
|
|
197
|
+
first_name: 'Jane',
|
|
198
|
+
lead_score: 85,
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### List contacts
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const { results } = await client.contacts.list({
|
|
206
|
+
lifecycle_stage: 'LEAD',
|
|
207
|
+
limit: 50,
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Deals
|
|
212
|
+
|
|
213
|
+
#### Create a deal
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const deal = await client.deals.create({
|
|
217
|
+
name: 'Enterprise Deal',
|
|
218
|
+
amount: 50000,
|
|
219
|
+
currency: 'USD',
|
|
220
|
+
priority: 'HIGH',
|
|
221
|
+
contactEmail: 'user@example.com',
|
|
222
|
+
expectedCloseDate: new Date('2024-12-31'),
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Move deal stage
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
await client.deals.moveStage(dealId, newStageId);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### List deals
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const { results } = await client.deals.list({
|
|
236
|
+
status: 'OPEN',
|
|
237
|
+
priority: 'HIGH',
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Browser Plugins
|
|
242
|
+
|
|
243
|
+
### Visitor ID Plugin
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
// Get current visitor ID
|
|
247
|
+
const visitorId = client.visitorId?.getVisitorId();
|
|
248
|
+
|
|
249
|
+
// Set a custom visitor ID
|
|
250
|
+
client.visitorId?.setVisitorId('custom-visitor-id');
|
|
251
|
+
|
|
252
|
+
// Reset visitor ID (generate new one)
|
|
253
|
+
client.visitorId?.resetVisitorId();
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Device Info Plugin
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// Get device information
|
|
260
|
+
const deviceInfo = client.deviceInfo?.getDeviceInfo();
|
|
261
|
+
// Returns: { userAgent, deviceType, browser, os }
|
|
262
|
+
|
|
263
|
+
// Get specific device attributes
|
|
264
|
+
const deviceType = client.deviceInfo?.getDeviceType(); // 'desktop' | 'mobile' | 'tablet'
|
|
265
|
+
const browser = client.deviceInfo?.getBrowser(); // e.g., 'Chrome'
|
|
266
|
+
const os = client.deviceInfo?.getOS(); // e.g., 'Windows 10'
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Session Replay Plugin
|
|
270
|
+
|
|
271
|
+
The Session Replay plugin automatically records user sessions with DOM playback capabilities using rrweb. This powerful feature captures:
|
|
272
|
+
|
|
273
|
+
- 🎬 **DOM Recording**: Complete visual replay of user sessions
|
|
274
|
+
- 📊 **Console Logs**: Capture all console output (log, info, warn, error, debug)
|
|
275
|
+
- 🌐 **Network Requests**: Track all fetch/XHR requests with timing and status codes
|
|
276
|
+
- ⚠️ **Error Capture**: Automatic JavaScript error and unhandled rejection tracking
|
|
277
|
+
- ⚡ **Performance Metrics**: Navigation timing, Core Web Vitals (LCP, FID, CLS)
|
|
278
|
+
- 🔒 **PII Masking**: Automatic masking of emails, phone numbers, and credit cards
|
|
279
|
+
- 🎯 **Custom Events**: Log custom application events during the session
|
|
280
|
+
|
|
281
|
+
#### Basic Usage
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
const client = new CRMClient({
|
|
285
|
+
apiToken: 'your-api-token',
|
|
286
|
+
sessionReplay: {
|
|
287
|
+
enabled: true, // Enable session replay (default: true)
|
|
288
|
+
sampleRate: 1.0, // Record 100% of sessions (default: 1.0)
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// Session replay starts automatically
|
|
293
|
+
// The current session is available at:
|
|
294
|
+
const session = client.sessionReplay?.getSession();
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### Advanced Configuration
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
const client = new CRMClient({
|
|
301
|
+
apiToken: 'your-api-token',
|
|
302
|
+
sessionReplay: {
|
|
303
|
+
enabled: true,
|
|
304
|
+
sampleRate: 0.5, // Record 50% of sessions
|
|
305
|
+
|
|
306
|
+
// Recording options
|
|
307
|
+
recording: {
|
|
308
|
+
maskAllInputs: true, // Mask all input fields (default: true)
|
|
309
|
+
maskTextSelector: '[data-mask]', // CSS selector for elements to mask
|
|
310
|
+
blockSelector: '[data-block]', // CSS selector for elements to block completely
|
|
311
|
+
recordCanvas: false, // Record canvas elements (default: false)
|
|
312
|
+
collectFonts: false, // Collect fonts (default: false)
|
|
313
|
+
inlineStylesheet: true, // Inline stylesheets (default: true)
|
|
314
|
+
inlineImages: false, // Inline images (default: false)
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
// Buffering and flushing
|
|
318
|
+
buffering: {
|
|
319
|
+
flushInterval: 5000, // Flush every 5 seconds (default: 5000)
|
|
320
|
+
maxBufferSize: 100, // Max events before auto-flush (default: 100)
|
|
321
|
+
maxSessionDuration: 3600000, // Max 1 hour sessions (default: 3600000)
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
// Telemetry capture
|
|
325
|
+
telemetry: {
|
|
326
|
+
captureConsole: true, // Capture console logs (default: true)
|
|
327
|
+
captureNetwork: true, // Capture network requests (default: true)
|
|
328
|
+
captureErrors: true, // Capture JavaScript errors (default: true)
|
|
329
|
+
capturePerformance: true, // Capture performance metrics (default: true)
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// Privacy settings
|
|
333
|
+
privacy: {
|
|
334
|
+
maskEmails: true, // Auto-mask email addresses (default: true)
|
|
335
|
+
maskPhones: true, // Auto-mask phone numbers (default: true)
|
|
336
|
+
maskCreditCards: true, // Auto-mask credit card numbers (default: true)
|
|
337
|
+
customMaskPatterns: [
|
|
338
|
+
{
|
|
339
|
+
pattern: /secret-\d+/gi,
|
|
340
|
+
replacement: 'SECRET-****',
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### Log Custom Events
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// Log a custom event during the session
|
|
352
|
+
client.sessionReplay?.logCustomEvent({
|
|
353
|
+
name: 'checkout_started',
|
|
354
|
+
data: {
|
|
355
|
+
cartValue: 129.99,
|
|
356
|
+
itemCount: 3,
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### Privacy Controls
|
|
362
|
+
|
|
363
|
+
Use HTML data attributes to control what gets recorded:
|
|
364
|
+
|
|
365
|
+
```html
|
|
366
|
+
<!-- Mask sensitive text -->
|
|
367
|
+
<div data-mask>Sensitive information here</div>
|
|
368
|
+
|
|
369
|
+
<!-- Block element completely from recording -->
|
|
370
|
+
<div data-block>This won't be recorded at all</div>
|
|
371
|
+
|
|
372
|
+
<!-- Password inputs are automatically masked -->
|
|
373
|
+
<input type="password" />
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
#### Session Data Structure
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
interface SessionReplaySession {
|
|
380
|
+
sessionId: string; // Unique session ID
|
|
381
|
+
startTime: Date; // When session started
|
|
382
|
+
endTime?: Date; // When session ended (if ended)
|
|
383
|
+
duration?: number; // Session duration in ms
|
|
384
|
+
initialUrl: string; // Starting URL
|
|
385
|
+
referrer?: string; // Referrer URL
|
|
386
|
+
visitorId?: string; // Visitor ID
|
|
387
|
+
contactId?: string; // Contact ID (if identified)
|
|
388
|
+
deviceType?: string; // 'desktop' | 'mobile' | 'tablet'
|
|
389
|
+
browser?: string; // Browser name
|
|
390
|
+
os?: string; // Operating system
|
|
391
|
+
viewport?: { // Viewport dimensions
|
|
392
|
+
width: number;
|
|
393
|
+
height: number;
|
|
394
|
+
};
|
|
395
|
+
status: 'ACTIVE' | 'ENDED' | 'PROCESSING' | 'ERROR';
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
#### Best Practices
|
|
400
|
+
|
|
401
|
+
1. **Sampling**: For high-traffic sites, use `sampleRate` to record a percentage of sessions
|
|
402
|
+
2. **Privacy**: Always use `maskAllInputs: true` and configure PII masking appropriately
|
|
403
|
+
3. **Performance**: Sessions are buffered and flushed every 5 seconds to minimize performance impact
|
|
404
|
+
4. **Storage**: Small sessions (<50KB) are stored in PostgreSQL, larger sessions in S3
|
|
405
|
+
5. **GDPR/CCPA**: Implement proper consent mechanisms before enabling session replay
|
|
406
|
+
|
|
407
|
+
#### Session Lifecycle
|
|
408
|
+
|
|
409
|
+
1. **Start**: Session automatically starts when client initializes (if enabled)
|
|
410
|
+
2. **Recording**: DOM mutations, console logs, network requests, errors are captured
|
|
411
|
+
3. **Buffering**: Events are buffered locally
|
|
412
|
+
4. **Flushing**: Events are sent to backend every 5 seconds or when buffer reaches 100 events
|
|
413
|
+
5. **End**: Session ends automatically on page unload/hide
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
// Manually stop recording
|
|
417
|
+
await client.sessionReplay?.stop();
|
|
418
|
+
|
|
419
|
+
// Get current session
|
|
420
|
+
const session = client.sessionReplay?.getSession();
|
|
421
|
+
console.log('Session ID:', session?.sessionId);
|
|
422
|
+
console.log('Duration:', session?.duration, 'ms');
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Error Handling
|
|
426
|
+
|
|
427
|
+
The SDK provides specific error classes for different scenarios:
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
import {
|
|
431
|
+
CRMError,
|
|
432
|
+
AuthenticationError,
|
|
433
|
+
ResourceNotFoundError,
|
|
434
|
+
ValidationError,
|
|
435
|
+
RateLimitError,
|
|
436
|
+
ServerError,
|
|
437
|
+
NetworkError,
|
|
438
|
+
} from 'crexperium-sdk';
|
|
439
|
+
|
|
440
|
+
try {
|
|
441
|
+
await client.events.track({ eventKey: 'purchase' });
|
|
442
|
+
} catch (error) {
|
|
443
|
+
if (error instanceof AuthenticationError) {
|
|
444
|
+
console.error('Invalid API token');
|
|
445
|
+
} else if (error instanceof ValidationError) {
|
|
446
|
+
console.error('Validation errors:', error.errors);
|
|
447
|
+
} else if (error instanceof RateLimitError) {
|
|
448
|
+
console.error('Rate limit exceeded. Retry after:', error.retryAfter);
|
|
449
|
+
} else if (error instanceof NetworkError) {
|
|
450
|
+
console.error('Network error:', error.originalError);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
## TypeScript Support
|
|
456
|
+
|
|
457
|
+
The SDK is written in TypeScript and includes comprehensive type definitions:
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
import type {
|
|
461
|
+
Event,
|
|
462
|
+
Contact,
|
|
463
|
+
Deal,
|
|
464
|
+
TrackEventOptions,
|
|
465
|
+
IdentifyOptions,
|
|
466
|
+
CreateDealOptions,
|
|
467
|
+
} from 'crexperium-sdk';
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
## Contributing
|
|
471
|
+
|
|
472
|
+
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
473
|
+
|
|
474
|
+
## License
|
|
475
|
+
|
|
476
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
477
|
+
|
|
478
|
+
## Support
|
|
479
|
+
|
|
480
|
+
- Documentation: https://docs.crexperium.com
|
|
481
|
+
- GitHub Issues: https://github.com/crexperium/crexperium-sdk/issues
|
|
482
|
+
- Email: support@crexperium.com
|