humanbehavior-js 0.2.4 → 0.2.6
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/dist/cjs/index.js +32 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react/index.js +3 -3
- package/dist/cjs/react/index.js.map +1 -1
- package/dist/esm/index.js +32 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/index.js +3 -3
- package/dist/esm/react/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/types/react/index.d.ts +4 -1
- package/package.json +2 -2
- package/src/react/index.tsx +12 -8
- package/src/tracker.ts +32 -1
|
@@ -20,7 +20,10 @@ declare const useRedaction: () => {
|
|
|
20
20
|
getRedactedFields: () => string[];
|
|
21
21
|
};
|
|
22
22
|
declare const useUserTracking: () => {
|
|
23
|
-
addUserInfo: (userId
|
|
23
|
+
addUserInfo: ({ userId, userProperties }: {
|
|
24
|
+
userId?: string;
|
|
25
|
+
userProperties: Record<string, any>;
|
|
26
|
+
}) => Promise<{
|
|
24
27
|
success: boolean;
|
|
25
28
|
error?: undefined;
|
|
26
29
|
} | {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "humanbehavior-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "SDK for HumanBehavior session and event recording",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
|
53
53
|
"type": "git",
|
|
54
|
-
"url": "git+https://github.com/humanbehavior-gh/
|
|
54
|
+
"url": "git+https://github.com/humanbehavior-gh/humanbehavior-js.git"
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"session-recording",
|
package/src/react/index.tsx
CHANGED
|
@@ -8,7 +8,7 @@ const isBrowser = () => typeof window !== 'undefined';
|
|
|
8
8
|
// Define the public interface that components will interact with
|
|
9
9
|
interface HumanBehaviorInterface {
|
|
10
10
|
addEvent: (event: any) => void;
|
|
11
|
-
addUserInfo: (userProperties: Record<string, any>) => Promise<
|
|
11
|
+
addUserInfo: ({ userId, userProperties }: { userId?: string, userProperties: Record<string, any> }) => Promise<string>;
|
|
12
12
|
start: () => void;
|
|
13
13
|
stop: () => void;
|
|
14
14
|
viewLogs: () => void;
|
|
@@ -122,9 +122,9 @@ export const HumanBehaviorProvider = ({ apiKey, client, children, options }: Hum
|
|
|
122
122
|
if (currentQueue.length > 0) {
|
|
123
123
|
for (const event of currentQueue) {
|
|
124
124
|
if (event.type === 'identify') {
|
|
125
|
-
logDebug('Processing queued identify event', event
|
|
125
|
+
logDebug('Processing queued identify event', event);
|
|
126
126
|
try {
|
|
127
|
-
await tracker.addUserInfo(event.userProperties);
|
|
127
|
+
await tracker.addUserInfo({ userId: event.userId, userProperties: event.userProperties });
|
|
128
128
|
} catch (error) {
|
|
129
129
|
logError('Failed to process queued user info:', error);
|
|
130
130
|
}
|
|
@@ -165,10 +165,12 @@ export const HumanBehaviorProvider = ({ apiKey, client, children, options }: Hum
|
|
|
165
165
|
);
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
-
//
|
|
169
|
-
const
|
|
168
|
+
// Default implementation for when tracker is not available
|
|
169
|
+
const defaultImplementation: HumanBehaviorInterface = {
|
|
170
170
|
addEvent: () => {},
|
|
171
|
-
addUserInfo: async () => {
|
|
171
|
+
addUserInfo: async ({ userId, userProperties }: { userId?: string, userProperties: Record<string, any> }) => {
|
|
172
|
+
return userId || '';
|
|
173
|
+
},
|
|
172
174
|
start: () => {},
|
|
173
175
|
stop: () => {},
|
|
174
176
|
viewLogs: () => {},
|
|
@@ -179,11 +181,13 @@ const createQueuingImplementation = (queueEvent: (event: any) => void): HumanBeh
|
|
|
179
181
|
addEvent: (event: any) => {
|
|
180
182
|
queueEvent(event);
|
|
181
183
|
},
|
|
182
|
-
addUserInfo: async (userProperties: Record<string, any>) => {
|
|
184
|
+
addUserInfo: async ({ userId, userProperties }: { userId?: string, userProperties: Record<string, any> }) => {
|
|
183
185
|
queueEvent({
|
|
184
186
|
type: 'identify',
|
|
187
|
+
userId,
|
|
185
188
|
userProperties,
|
|
186
189
|
});
|
|
190
|
+
return userId || ''; // Return userId or empty string to match interface
|
|
187
191
|
},
|
|
188
192
|
start: () => {
|
|
189
193
|
// Start will be called automatically when initialized
|
|
@@ -231,7 +235,7 @@ export const useRedaction = () => {
|
|
|
231
235
|
export const useUserTracking = () => {
|
|
232
236
|
const tracker = useHumanBehavior();
|
|
233
237
|
|
|
234
|
-
const addUserInfo = useCallback(async (userId: string, userProperties: Record<string, any>) => {
|
|
238
|
+
const addUserInfo = useCallback(async ({ userId, userProperties }: { userId?: string, userProperties: Record<string, any> }) => {
|
|
235
239
|
try {
|
|
236
240
|
await tracker.addUserInfo({ userId, userProperties });
|
|
237
241
|
return { success: true };
|
package/src/tracker.ts
CHANGED
|
@@ -762,6 +762,21 @@ export class HumanBehaviorTracker {
|
|
|
762
762
|
// Start recording with redaction enabled
|
|
763
763
|
rrweb.record({
|
|
764
764
|
emit: (event) => {
|
|
765
|
+
// Add additional validation for FullSnapshot events
|
|
766
|
+
if (event.type === 2) { // FullSnapshot event
|
|
767
|
+
if (!event.data || !event.data.node) {
|
|
768
|
+
logWarn('rrweb generated malformed FullSnapshot event:', {
|
|
769
|
+
hasData: !!event.data,
|
|
770
|
+
hasNode: !!(event.data && event.data.node),
|
|
771
|
+
dataType: typeof event.data,
|
|
772
|
+
eventType: event.type,
|
|
773
|
+
timestamp: event.timestamp
|
|
774
|
+
});
|
|
775
|
+
// Don't skip - let the addEvent method handle it
|
|
776
|
+
} else {
|
|
777
|
+
logDebug('Valid FullSnapshot event received from rrweb');
|
|
778
|
+
}
|
|
779
|
+
}
|
|
765
780
|
this.addEvent(event);
|
|
766
781
|
},
|
|
767
782
|
inlineStylesheet: true,
|
|
@@ -770,7 +785,10 @@ export class HumanBehaviorTracker {
|
|
|
770
785
|
inlineImages: true,
|
|
771
786
|
blockClass: 'rr-block',
|
|
772
787
|
ignoreClass: 'rr-ignore',
|
|
773
|
-
maskTextClass: 'rr-ignore'
|
|
788
|
+
maskTextClass: 'rr-ignore',
|
|
789
|
+
// Add more robust configuration
|
|
790
|
+
checkoutEveryNms: 5000, // Take full snapshot every 5 seconds
|
|
791
|
+
checkoutEveryNth: 100 // Take full snapshot every 100 events
|
|
774
792
|
});
|
|
775
793
|
}
|
|
776
794
|
|
|
@@ -793,6 +811,19 @@ export class HumanBehaviorTracker {
|
|
|
793
811
|
public async addEvent(event: any) {
|
|
794
812
|
await this.ensureInitialized();
|
|
795
813
|
|
|
814
|
+
// Validate FullSnapshot events before processing
|
|
815
|
+
if (event.type === 2) { // FullSnapshot event
|
|
816
|
+
if (!event.data || !event.data.node) {
|
|
817
|
+
logWarn('Malformed FullSnapshot event detected, skipping:', {
|
|
818
|
+
hasData: !!event.data,
|
|
819
|
+
hasNode: !!(event.data && event.data.node),
|
|
820
|
+
dataType: typeof event.data,
|
|
821
|
+
eventType: event.type
|
|
822
|
+
});
|
|
823
|
+
return; // Skip malformed FullSnapshot events
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
796
827
|
// Process event through redaction manager if active
|
|
797
828
|
const processedEvent = this.redactionManager.processEvent(event);
|
|
798
829
|
|