@malleon/replay 1.0.13 → 1.0.14

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 CHANGED
@@ -8,6 +8,89 @@ clear && npm run dist
8
8
  ## Prod
9
9
  clear && npm run dist:prod
10
10
 
11
+ ## ES Module Usage (Recommended)
12
+
13
+ Install the package and import where you bootstrap your app:
14
+
15
+ ```bash
16
+ npm install @malleon/replay
17
+ ```
18
+
19
+ ```javascript
20
+ import { initReplay } from '@malleon/replay';
21
+
22
+ // Initialize as early as possible in your app bootstrap
23
+ initReplay('your-app-id', { release: '1.0.0', dist: 'production' });
24
+ ```
25
+
26
+ ES modules do not auto-initialize, so you must call `initReplay()` explicitly—typically in your main entry point, router setup, or app initialization logic.
27
+
28
+ ## UMD Script Tag Usage
29
+
30
+ When loading the Replay SDK via a script tag (using `replay.umd.js`), the library **auto-initializes** as soon as it finds an `appId`. You can pass configuration in several ways.
31
+
32
+ ### Script URL Parameters
33
+
34
+ Add query parameters to your script `src` attribute:
35
+
36
+ ```html
37
+ <script src="https://malleon.io/assets/replay.umd.js?appId=your-app-id&release=1.0.0&dist=production"></script> (or your CDN)
38
+ ```
39
+
40
+ | Parameter | Description |
41
+ |-----------|-------------|
42
+ | `appId` | (Required) Your application ID |
43
+ | `release` | (Optional) Release or version string (e.g. `1.0.0`) |
44
+ | `dist` | (Optional) Distribution or environment (e.g. `production`, `staging`) |
45
+ | `skipReplayAutoInit` | If present, disables auto-initialization so you can call `initReplay()` manually when ready |
46
+
47
+ Example: skip auto-init and manually initialize later:
48
+ ```html
49
+ <script src="https://malleon.io/assets/replay.umd.js?skipReplayAutoInit"></script> (or your CDN)
50
+ <script>
51
+ // Your code sets appId when ready, then:
52
+ window.waitForAppIdAndInitReplay(); // polls until appId found, then inits
53
+ // Or call directly when you have the values:
54
+ window.initReplay('your-app-id', { release: '1.0.0', dist: 'production' });
55
+ </script>
56
+ ```
57
+
58
+ ### Auto-Initialization
59
+
60
+ When loaded via a UMD script tag **without** `skipReplayAutoInit`, the SDK automatically calls `waitForAppIdAndInitReplay()`, which polls every 100ms until it finds an `appId`, then initializes. No manual `initReplay()` call is needed.
61
+
62
+ The recommended ES module imports (`import ... from 'replay'`) do **not** auto-initialize; you must call `initReplay()` explicitly.
63
+
64
+ ### Configuration Sources (Priority Order)
65
+
66
+ The SDK looks for `appId`, `release`, and `dist` in this order (first match wins):
67
+
68
+ 1. **Script URL** — query params on the script tag’s `src` (`appId`, `release`, `dist`)
69
+ 2. **Window** — `window.__replay__appId`, `window.__replay__release`, `window.__replay__dist`
70
+ 3. **Page URL** — search params `replayAppId`, `replayRelease`, `replayDist`
71
+ 4. **Hash URL** — same param names in the URL hash (e.g. `#/path?replayAppId=xyz`)
72
+ 5. **localStorage** — keys `__replay__appId`, `__replay__release`, `__replay__dist`
73
+ 6. **sessionStorage** — same keys
74
+
75
+ Example: set before the script loads for late-binding of appId:
76
+
77
+ ```html
78
+ <script>
79
+ window.__replay__appId = 'your-app-id';
80
+ window.__replay__release = '1.0.0';
81
+ window.__replay__dist = 'production';
82
+ </script>
83
+ <script src="https://malleon.io/assets/replay.umd.js"></script> (or your CDN)
84
+ ```
85
+
86
+ Example: use localStorage for persistence across page loads:
87
+
88
+ ```javascript
89
+ localStorage.setItem('__replay__appId', 'your-app-id');
90
+ localStorage.setItem('__replay__release', '1.0.0');
91
+ localStorage.setItem('__replay__dist', 'production');
92
+ ```
93
+
11
94
  ## Basic Usage
12
95
 
13
96
  ```javascript
@@ -41,8 +124,11 @@ updateReplayUserData({
41
124
 
42
125
  ## API Reference
43
126
 
44
- ### `initReplay(appId: string): void`
45
- Initializes the replay system for the specified app ID. Must be called before using other functions.
127
+ ### `initReplay(appId: string, options?: { release?: string; dist?: string }): void`
128
+ Initializes the replay system for the specified app ID. Must be called before using other functions. Optionally pass `release` and/or `dist` for version and environment tracking.
129
+
130
+ ### `waitForAppIdAndInitReplay(): void`
131
+ Polls until `appId` is available (from script URL, window, URL params, or storage), then calls `initReplay`. Useful when using `skipReplayAutoInit` but you want automatic init once config is set.
46
132
 
47
133
  ### `addTagToReplay(name: string, value: string | number | boolean | Date, type: TagType): Promise<void>`
48
134
  Adds a single tag to the current replay. The `type` parameter is required and must match one of the supported tag types.
@@ -99,7 +185,7 @@ The following tag types are supported:
99
185
 
100
186
  ## Requirements
101
187
 
102
- - Must call `initReplay()` first to initialize the replay system
188
+ - Must call `initReplay()` first to initialize the replay system (or use UMD script tag with `appId` for auto-init)
103
189
  - Functions will warn if called before initialization
104
190
  - All functions are asynchronous and return promises
105
191
  - Functions are also available globally on the `window` object
package/dist/index.d.ts CHANGED
@@ -4,6 +4,10 @@ declare global {
4
4
  __REPLAY_STARTED__?: boolean;
5
5
  __REPLAY_DISABLED__?: boolean;
6
6
  __replay__appId?: string;
7
+ __replay__release?: string;
8
+ __replay__dist?: string;
9
+ initReplay?: typeof initReplay;
10
+ waitForAppIdAndInitReplay?: typeof waitForAppIdAndInitReplay;
7
11
  addTagsToReplay?: typeof addTagsToReplay;
8
12
  addTagToReplay?: typeof addTagToReplay;
9
13
  updateReplayUserData?: typeof updateReplayUserData;