humanbehavior-js 0.1.6 → 0.1.8
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 +12 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react/index.js +14 -2
- package/dist/cjs/react/index.js.map +1 -1
- package/dist/esm/index.js +12 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/index.js +14 -2
- 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/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +14 -6
- package/src/react/index.tsx +5 -3
package/dist/types/index.d.ts
CHANGED
|
@@ -275,7 +275,7 @@ declare class HumanBehaviorAPI {
|
|
|
275
275
|
sendEventsChunked(events: any[], sessionId: string): Promise<any[]>;
|
|
276
276
|
sendUserData(userId: string, userData: Record<string, any>, sessionId: string): Promise<any>;
|
|
277
277
|
sendUserAuth(userId: string, userData: Record<string, any>, sessionId: string, authFields: string[]): Promise<any>;
|
|
278
|
-
sendBeaconEvents(events: any[], sessionId: string):
|
|
278
|
+
sendBeaconEvents(events: any[], sessionId: string): boolean;
|
|
279
279
|
sendCustomEvent(sessionId: string, eventName: string, eventProperties?: Record<string, any>): Promise<any>;
|
|
280
280
|
sendCustomEventBatch(sessionId: string, events: Array<{
|
|
281
281
|
eventName: string;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -220,16 +220,24 @@ export class HumanBehaviorAPI {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
public sendBeaconEvents(events: any[], sessionId: string) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
// Create JSON payload that matches the server's expected format
|
|
224
|
+
const payload = {
|
|
225
|
+
sessionId: sessionId,
|
|
226
|
+
events: events,
|
|
227
|
+
endUserId: null // Beacon doesn't have user context
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Convert to Blob for sendBeacon
|
|
231
|
+
const blob = new Blob([JSON.stringify(payload)], {
|
|
232
|
+
type: 'application/json'
|
|
233
|
+
});
|
|
228
234
|
|
|
229
235
|
const success = navigator.sendBeacon(
|
|
230
236
|
`${this.baseUrl}/api/ingestion/events`,
|
|
231
|
-
|
|
237
|
+
blob
|
|
232
238
|
);
|
|
239
|
+
|
|
240
|
+
return success;
|
|
233
241
|
}
|
|
234
242
|
|
|
235
243
|
async sendCustomEvent(sessionId: string, eventName: string, eventProperties?: Record<string, any>) {
|
package/src/react/index.tsx
CHANGED
|
@@ -113,9 +113,11 @@ export const HumanBehaviorProvider = ({ apiKey, client, children, options }: Hum
|
|
|
113
113
|
setHumanBehavior(tracker);
|
|
114
114
|
|
|
115
115
|
// Wait for initialization to complete
|
|
116
|
-
tracker.initializationPromise?.then(() => {
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
tracker.initializationPromise?.then(async () => {
|
|
117
|
+
// Start the tracker to enable event flushing and recording
|
|
118
|
+
await tracker.start();
|
|
119
|
+
setIsInitialized(true);
|
|
120
|
+
|
|
119
121
|
// Process any queued events
|
|
120
122
|
const currentQueue = eventQueueRef.current;
|
|
121
123
|
if (currentQueue.length > 0) {
|