tracebck-sdk 0.1.0 → 0.2.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.
Files changed (2) hide show
  1. package/README.md +117 -24
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # tracebck-sdk
2
2
 
3
- Lightweight session recording SDK based on [rrweb](https://github.com/rrweb-io/rrweb).
3
+ Lightweight session recording SDK for [Tracebck](https://tracebck.dev). Captures user interactions, DOM changes, and network requests for replay.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,32 +14,20 @@ Or via CDN:
14
14
  <script src="https://unpkg.com/tracebck-sdk/dist/index.iife.js"></script>
15
15
  ```
16
16
 
17
- ## Usage
17
+ ## Quick Start
18
18
 
19
19
  ### ES Modules
20
20
 
21
21
  ```javascript
22
22
  import { init, startSession, stopSession } from 'tracebck-sdk';
23
23
 
24
- // Initialize with your API key
25
- init({
26
- apiKey: 'your-api-key',
27
- // endpoint: 'https://your-api.com/v1', // optional, uses default
28
- debug: false // optional
29
- });
24
+ init({ apiKey: 'sk_your_api_key' });
30
25
 
31
- // Start recording
32
26
  startSession({
33
- identifier: {
34
- type: 'userId', // or 'email', 'anonymous', etc.
35
- value: 'user-123'
36
- },
37
- metadata: {
38
- plan: 'premium' // optional custom metadata
39
- }
27
+ identifier: { type: 'userId', value: 'user-123' }
40
28
  });
41
29
 
42
- // Stop recording (call on logout or when done)
30
+ // When done (e.g. on logout)
43
31
  stopSession();
44
32
  ```
45
33
 
@@ -48,9 +36,7 @@ stopSession();
48
36
  ```html
49
37
  <script src="https://unpkg.com/tracebck-sdk/dist/index.iife.js"></script>
50
38
  <script>
51
- Tracebck.init({
52
- apiKey: 'your-api-key'
53
- });
39
+ Tracebck.init({ apiKey: 'sk_your_api_key' });
54
40
 
55
41
  Tracebck.startSession({
56
42
  identifier: { type: 'userId', value: 'user-123' }
@@ -58,14 +44,121 @@ stopSession();
58
44
  </script>
59
45
  ```
60
46
 
61
- ## Configuration Options
47
+ ## API
48
+
49
+ ### `init(config)`
50
+
51
+ Initializes the SDK. Must be called before `startSession()`.
52
+
53
+ ```javascript
54
+ init({
55
+ apiKey: 'sk_your_api_key',
56
+ maskAllInputs: true,
57
+ captureNetwork: true,
58
+ flushInterval: 5000,
59
+ options: { /* rrweb options */ }
60
+ });
61
+ ```
62
62
 
63
63
  | Option | Type | Default | Description |
64
64
  |--------|------|---------|-------------|
65
- | `apiKey` | string | required | Your API key |
66
- | `maskAllInputs` | boolean | `false` | Mask all input values for privacy |
67
- | `options` | object | `{}` | Additional rrweb options |
65
+ | `apiKey` | `string` | **required** | Your project API key |
66
+ | `maskAllInputs` | `boolean` | `false` | Replace all input values with `*` for privacy |
67
+ | `captureNetwork` | `boolean` | `true` | Capture fetch and XHR requests |
68
+ | `flushInterval` | `number` | `5000` | Interval in ms between event flushes |
69
+ | `options` | `object` | `{}` | Additional [rrweb options](#rrweb-options) |
70
+
71
+ ### `startSession(config)`
72
+
73
+ Creates a session and starts recording. If a session is already active, it will be stopped first.
74
+
75
+ ```javascript
76
+ startSession({
77
+ identifier: {
78
+ type: 'email',
79
+ value: 'user@example.com'
80
+ },
81
+ metadata: {
82
+ plan: 'premium',
83
+ company: 'Acme'
84
+ }
85
+ });
86
+ ```
87
+
88
+ | Option | Type | Required | Description |
89
+ |--------|------|----------|-------------|
90
+ | `identifier.type` | `string` | No | Identifier type (`'email'`, `'userId'`, etc.). Defaults to `'custom'` |
91
+ | `identifier.value` | `string` | **Yes** | Unique user identifier |
92
+ | `metadata` | `object` | No | Custom metadata attached to the session |
93
+
94
+ Browser metadata (URL, referrer, userAgent, language, resolution) is captured automatically.
95
+
96
+ ### `stopSession()`
97
+
98
+ Stops recording, flushes remaining events, and closes the session. Events are also flushed automatically when the user leaves or hides the page.
99
+
100
+ ## rrweb Options
101
+
102
+ Pass rrweb `record()` options via the `options` field in `init()` to customize recording behavior.
103
+
104
+ ### Privacy
105
+
106
+ Block elements entirely (rendered as grey placeholders in replay):
107
+
108
+ ```javascript
109
+ options: {
110
+ blockClass: 'no-record', // default: 'rr-block'
111
+ blockSelector: '.secret-panel'
112
+ }
113
+ ```
114
+
115
+ Mask text content (replaced with `*`):
116
+
117
+ ```javascript
118
+ options: {
119
+ maskTextClass: 'rr-mask',
120
+ maskTextSelector: '.sensitive'
121
+ }
122
+ ```
123
+
124
+ Granular input masking:
125
+
126
+ ```javascript
127
+ options: {
128
+ maskInputOptions: {
129
+ email: true,
130
+ tel: true,
131
+ password: true // true by default
132
+ }
133
+ }
134
+ ```
135
+
136
+ ### Performance
137
+
138
+ ```javascript
139
+ options: {
140
+ sampling: {
141
+ mousemove: 100, // throttle mouse tracking to every 100ms (default: true)
142
+ scroll: 200, // throttle scroll events to 200ms (default: 150)
143
+ input: 'last' // only record final input value (default: 'last')
144
+ },
145
+ slimDOMOptions: 'all' // strip scripts, comments, meta tags from snapshots
146
+ }
147
+ ```
148
+
149
+ ## Network Capture
150
+
151
+ When `captureNetwork` is enabled (default), the SDK intercepts `fetch` and `XMLHttpRequest` calls and records them as replay events. Requests to the Tracebck API are excluded automatically.
152
+
153
+ Captured per request: method, URL, status code, headers, body (text content types only, max 100KB), and duration.
154
+
155
+ ## Distribution
68
156
 
157
+ | Format | File | Usage |
158
+ |--------|------|-------|
159
+ | ESM | `dist/index.js` | `import` / bundlers |
160
+ | CJS | `dist/index.cjs` | `require()` |
161
+ | IIFE | `dist/index.iife.js` | `<script>` tag (exposes `window.Tracebck`) |
69
162
 
70
163
  ## License
71
164
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tracebck-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Lightweight session recording SDK based on rrweb",
5
5
  "author": "Miguel Hang",
6
6
  "license": "MIT",