@lensx/tracking 0.2.0 → 0.2.1
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 +12 -15
- package/dist/config.js +5 -5
- package/dist/index.js +4 -4
- package/dist/react.d.ts +1 -1
- package/dist/react.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @lensx/tracking
|
|
2
2
|
|
|
3
3
|
Privacy-first session recording for web apps, on top of the [OpenReplay](https://openreplay.com) web tracker
|
|
4
4
|
(self-hosted or cloud). One package gives every project the same setup: a consent gate, mask-everything
|
|
@@ -15,14 +15,11 @@ Not an official OpenReplay package.
|
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
|
-
The package is published as `@lensx/tracking`. Install it under the name `@company/tracking`, so your
|
|
19
|
-
imports stay the same if the published name changes:
|
|
20
|
-
|
|
21
18
|
```bash
|
|
22
|
-
npm i
|
|
19
|
+
npm i @lensx/tracking
|
|
23
20
|
```
|
|
24
21
|
|
|
25
|
-
React is an optional peer dependency (needed only for `@
|
|
22
|
+
React is an optional peer dependency (needed only for `@lensx/tracking/react`).
|
|
26
23
|
|
|
27
24
|
## Quick start: Next.js (App Router)
|
|
28
25
|
|
|
@@ -40,8 +37,8 @@ NEXT_PUBLIC_TRACKING_ENV=production # local | staging | production
|
|
|
40
37
|
```tsx
|
|
41
38
|
'use client';
|
|
42
39
|
|
|
43
|
-
import { createTrackingConfig } from '@
|
|
44
|
-
import { ConsentBanner, TrackingProvider } from '@
|
|
40
|
+
import { createTrackingConfig } from '@lensx/tracking';
|
|
41
|
+
import { ConsentBanner, TrackingProvider } from '@lensx/tracking/react';
|
|
45
42
|
|
|
46
43
|
// Next.js inlines NEXT_PUBLIC_* only when written out literally.
|
|
47
44
|
const trackingConfig = createTrackingConfig({
|
|
@@ -87,7 +84,7 @@ const trackingConfig = createTrackingConfig({
|
|
|
87
84
|
## Without React
|
|
88
85
|
|
|
89
86
|
```ts
|
|
90
|
-
import { configureTracking, createTrackingConfig, setConsent } from '@
|
|
87
|
+
import { configureTracking, createTrackingConfig, setConsent } from '@lensx/tracking';
|
|
91
88
|
|
|
92
89
|
const config = createTrackingConfig({ projectKey, ingestPoint, apiUrl, env: 'production' });
|
|
93
90
|
if (config) configureTracking(config);
|
|
@@ -126,11 +123,11 @@ Or build your own with `useTracking()`: `consent` (`unknown` | `granted` | `deni
|
|
|
126
123
|
```ts
|
|
127
124
|
const t = useTracking(); // or import the functions directly
|
|
128
125
|
|
|
129
|
-
t.identify(user.id);
|
|
130
|
-
t.resetUser();
|
|
126
|
+
t.identify(user.id); // internal ID only, never email or phone
|
|
127
|
+
t.resetUser(); // on logout: ends the session, starts a fresh anonymous one
|
|
131
128
|
t.track('checkout_started', { items: 3 });
|
|
132
129
|
t.reportError(error, { orderId });
|
|
133
|
-
t.replayUrl();
|
|
130
|
+
t.replayUrl(); // link to the current replay, e.g. for support tickets
|
|
134
131
|
```
|
|
135
132
|
|
|
136
133
|
Call `identify()` as soon as the app knows the user, including on page load for a signed-in user, not
|
|
@@ -191,9 +188,9 @@ allowed. Any other env requires HTTPS.
|
|
|
191
188
|
## Develop (monorepo)
|
|
192
189
|
|
|
193
190
|
```bash
|
|
194
|
-
pnpm --filter @
|
|
195
|
-
pnpm --filter @
|
|
196
|
-
scripts/publish-tracking.sh <
|
|
191
|
+
pnpm --filter @lensx/tracking test
|
|
192
|
+
pnpm --filter @lensx/tracking build
|
|
193
|
+
scripts/publish-tracking.sh <version>
|
|
197
194
|
```
|
|
198
195
|
|
|
199
196
|
## License
|
package/dist/config.js
CHANGED
|
@@ -80,27 +80,27 @@ export function buildTrackerOptions(cfg) {
|
|
|
80
80
|
}
|
|
81
81
|
function validate(cfg) {
|
|
82
82
|
if (!cfg.projectKey)
|
|
83
|
-
throw new Error('@
|
|
83
|
+
throw new Error('@lensx/tracking: projectKey is required');
|
|
84
84
|
let ingest;
|
|
85
85
|
try {
|
|
86
86
|
ingest = new URL(cfg.ingestPoint);
|
|
87
87
|
}
|
|
88
88
|
catch {
|
|
89
|
-
throw new Error(`@
|
|
89
|
+
throw new Error(`@lensx/tracking: ingestPoint is not a URL: ${cfg.ingestPoint}`);
|
|
90
90
|
}
|
|
91
91
|
if (ingest.protocol !== 'https:') {
|
|
92
|
-
throw new Error('@
|
|
92
|
+
throw new Error('@lensx/tracking: ingestPoint must use https');
|
|
93
93
|
}
|
|
94
94
|
for (const base of cfg.apiBaseUrls) {
|
|
95
95
|
try {
|
|
96
96
|
new URL(base);
|
|
97
97
|
}
|
|
98
98
|
catch {
|
|
99
|
-
throw new Error(`@
|
|
99
|
+
throw new Error(`@lensx/tracking: apiBaseUrls entry must be an absolute URL: ${base}`);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
if (cfg.allowInsecureLocalhost && cfg.env !== 'local') {
|
|
103
|
-
throw new Error('@
|
|
103
|
+
throw new Error('@lensx/tracking: allowInsecureLocalhost is only allowed when env is local');
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
//# sourceMappingURL=config.js.map
|
package/dist/index.js
CHANGED
|
@@ -98,7 +98,7 @@ function drainPending(t) {
|
|
|
98
98
|
fn(t);
|
|
99
99
|
}
|
|
100
100
|
catch (e) {
|
|
101
|
-
console.warn('[@
|
|
101
|
+
console.warn('[@lensx/tracking] queued call failed:', e);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
if (calls.length)
|
|
@@ -179,10 +179,10 @@ async function startRecording(tracker, options) {
|
|
|
179
179
|
const delay = START_RETRY_DELAYS_MS[attempt];
|
|
180
180
|
if (delay === undefined || !isRetryableStartFailure(reason) || !state.consent) {
|
|
181
181
|
state.pending.length = 0;
|
|
182
|
-
console.warn('[@
|
|
182
|
+
console.warn('[@lensx/tracking] OpenReplay did not start:', reason);
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
|
-
console.warn(`[@
|
|
185
|
+
console.warn(`[@lensx/tracking] OpenReplay start failed (${reason}); retrying in ${delay} ms`);
|
|
186
186
|
await sleep(delay);
|
|
187
187
|
// consent withdrawn, or the app replaced the tracker, while we waited
|
|
188
188
|
if (!state.consent || state.tracker !== tracker) {
|
|
@@ -221,7 +221,7 @@ export function setMetadata(key, value) {
|
|
|
221
221
|
/** A standard name from `ALLOWED_EVENTS`, or a custom snake_case name (e.g. `booking_started`). */
|
|
222
222
|
export function track(name, payload) {
|
|
223
223
|
if (!isValidEventName(name)) {
|
|
224
|
-
console.warn(`[@
|
|
224
|
+
console.warn(`[@lensx/tracking] event "${name}" ignored: use snake_case, e.g. booking_started`);
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
227
|
whenRecording((t) => t.event(name, payload));
|
package/dist/react.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface TrackingContextValue {
|
|
|
19
19
|
replayUrl: typeof replayUrl;
|
|
20
20
|
flushBeforeNavigation: typeof flushBeforeNavigation;
|
|
21
21
|
}
|
|
22
|
-
export declare const CONSENT_STORAGE_KEY = "
|
|
22
|
+
export declare const CONSENT_STORAGE_KEY = "lensx.tracking.consent";
|
|
23
23
|
export interface TrackingProviderProps {
|
|
24
24
|
/** `null` turns tracking off (e.g. no project key in this environment). */
|
|
25
25
|
config: TrackingConfig | null;
|
package/dist/react.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
4
|
import { configureTracking, flushBeforeNavigation, identify, replayUrl, reportError, resetUser, setConsent, setMetadata, track, trackIssue, } from './index.js';
|
|
5
|
-
export const CONSENT_STORAGE_KEY = '
|
|
5
|
+
export const CONSENT_STORAGE_KEY = 'lensx.tracking.consent';
|
|
6
6
|
const TrackingContext = createContext(null);
|
|
7
7
|
function readStored() {
|
|
8
8
|
try {
|
|
@@ -41,7 +41,7 @@ export function TrackingProvider({ config, children }) {
|
|
|
41
41
|
ok = true;
|
|
42
42
|
}
|
|
43
43
|
catch (e) {
|
|
44
|
-
console.warn('[@
|
|
44
|
+
console.warn('[@lensx/tracking] tracking disabled:', e.message);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
setEnabled(ok);
|
package/package.json
CHANGED