humanbehavior-js 0.3.4 → 0.3.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 +1 -53
- 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 +2 -53
- 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/index.d.ts +3 -25
- package/dist/types/react/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/index.ts +0 -3
- package/src/react/index.tsx +8 -9
- package/src/tracker.ts +1 -1
- package/src/server.ts +0 -63
package/dist/types/index.d.ts
CHANGED
|
@@ -199,8 +199,7 @@ declare class HumanBehaviorTracker {
|
|
|
199
199
|
* Add user identification information to the tracker
|
|
200
200
|
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
201
201
|
*/
|
|
202
|
-
identifyUser({
|
|
203
|
-
userId?: string;
|
|
202
|
+
identifyUser({ userProperties }: {
|
|
204
203
|
userProperties: Record<string, any>;
|
|
205
204
|
}): Promise<string>;
|
|
206
205
|
/**
|
|
@@ -327,27 +326,6 @@ declare class HumanBehaviorAPI {
|
|
|
327
326
|
}>): Promise<any>;
|
|
328
327
|
}
|
|
329
328
|
|
|
330
|
-
/**
|
|
331
|
-
* Server-side utilities for HumanBehavior SDK
|
|
332
|
-
*/
|
|
333
|
-
interface ServerSideUserData {
|
|
334
|
-
email: string;
|
|
335
|
-
name?: string;
|
|
336
|
-
image?: string;
|
|
337
|
-
provider?: string;
|
|
338
|
-
[key: string]: any;
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Identify user from server-side (NextAuth, Firebase, etc.)
|
|
342
|
-
* Use this in your auth events to track users immediately on sign-in
|
|
343
|
-
*/
|
|
344
|
-
declare function identifyUser(userId: string, // Separate userId parameter (should be stable unique identifier)
|
|
345
|
-
userData: ServerSideUserData, apiKey: string): Promise<{
|
|
346
|
-
success: boolean;
|
|
347
|
-
error?: string;
|
|
348
|
-
actualUserId?: string;
|
|
349
|
-
}>;
|
|
350
|
-
|
|
351
329
|
declare enum LogLevel {
|
|
352
330
|
NONE = 0,
|
|
353
331
|
ERROR = 1,
|
|
@@ -381,5 +359,5 @@ declare const logWarn: (message: string, ...args: any[]) => void;
|
|
|
381
359
|
declare const logInfo: (message: string, ...args: any[]) => void;
|
|
382
360
|
declare const logDebug: (message: string, ...args: any[]) => void;
|
|
383
361
|
|
|
384
|
-
export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, HumanBehaviorTracker as default,
|
|
385
|
-
export type { LoggerConfig, RedactionOptions
|
|
362
|
+
export { HumanBehaviorAPI, HumanBehaviorTracker, LogLevel, MAX_CHUNK_SIZE_BYTES, RedactionManager, HumanBehaviorTracker as default, isChunkSizeExceeded, logDebug, logError, logInfo, logWarn, logger, redactionManager, splitLargeEvent, validateSingleEventSize };
|
|
363
|
+
export type { LoggerConfig, RedactionOptions };
|
|
@@ -20,8 +20,7 @@ declare const useRedaction: () => {
|
|
|
20
20
|
getRedactedFields: () => string[];
|
|
21
21
|
};
|
|
22
22
|
declare const useUserTracking: () => {
|
|
23
|
-
identifyUser: ({
|
|
24
|
-
userId?: string;
|
|
23
|
+
identifyUser: ({ userProperties }: {
|
|
25
24
|
userProperties: Record<string, any>;
|
|
26
25
|
}) => Promise<{
|
|
27
26
|
success: boolean;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
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
|
-
identifyUser: ({
|
|
11
|
+
identifyUser: ({ userProperties }: { userProperties: Record<string, any> }) => Promise<string>;
|
|
12
12
|
start: () => void;
|
|
13
13
|
stop: () => void;
|
|
14
14
|
logout: () => void;
|
|
@@ -136,7 +136,7 @@ export const HumanBehaviorProvider = ({ apiKey, client, children, options }: Hum
|
|
|
136
136
|
if (event.type === 'identify') {
|
|
137
137
|
logDebug('Processing queued identify event', event);
|
|
138
138
|
try {
|
|
139
|
-
await tracker.identifyUser({
|
|
139
|
+
await tracker.identifyUser({ userProperties: event.userProperties });
|
|
140
140
|
} catch (error) {
|
|
141
141
|
logError('Failed to process queued user info:', error);
|
|
142
142
|
}
|
|
@@ -180,8 +180,8 @@ export const HumanBehaviorProvider = ({ apiKey, client, children, options }: Hum
|
|
|
180
180
|
// Default implementation for when tracker is not available
|
|
181
181
|
const defaultImplementation: HumanBehaviorInterface = {
|
|
182
182
|
addEvent: () => {},
|
|
183
|
-
identifyUser: async ({
|
|
184
|
-
return
|
|
183
|
+
identifyUser: async ({ userProperties }: { userProperties: Record<string, any> }) => {
|
|
184
|
+
return '';
|
|
185
185
|
},
|
|
186
186
|
start: () => {},
|
|
187
187
|
stop: () => {},
|
|
@@ -194,13 +194,12 @@ const createQueuingImplementation = (queueEvent: (event: any) => void): HumanBeh
|
|
|
194
194
|
addEvent: (event: any) => {
|
|
195
195
|
queueEvent(event);
|
|
196
196
|
},
|
|
197
|
-
identifyUser: async ({
|
|
197
|
+
identifyUser: async ({ userProperties }: { userProperties: Record<string, any> }) => {
|
|
198
198
|
queueEvent({
|
|
199
199
|
type: 'identify',
|
|
200
|
-
userId,
|
|
201
200
|
userProperties,
|
|
202
201
|
});
|
|
203
|
-
return
|
|
202
|
+
return ''; // Return empty string to match interface
|
|
204
203
|
},
|
|
205
204
|
start: () => {
|
|
206
205
|
// Start will be called automatically when initialized
|
|
@@ -251,9 +250,9 @@ export const useRedaction = () => {
|
|
|
251
250
|
export const useUserTracking = () => {
|
|
252
251
|
const tracker = useHumanBehavior();
|
|
253
252
|
|
|
254
|
-
const identifyUser = useCallback(async ({
|
|
253
|
+
const identifyUser = useCallback(async ({ userProperties }: { userProperties: Record<string, any> }) => {
|
|
255
254
|
try {
|
|
256
|
-
await tracker.identifyUser({
|
|
255
|
+
await tracker.identifyUser({ userProperties });
|
|
257
256
|
return { success: true };
|
|
258
257
|
} catch (error) {
|
|
259
258
|
logError('Failed to identify user:', error);
|
package/src/tracker.ts
CHANGED
|
@@ -718,7 +718,7 @@ export class HumanBehaviorTracker {
|
|
|
718
718
|
* If userId is not provided, will use userProperties.email as the userId (if present)
|
|
719
719
|
*/
|
|
720
720
|
public async identifyUser(
|
|
721
|
-
{
|
|
721
|
+
{ userProperties }: { userProperties: Record<string, any> }
|
|
722
722
|
): Promise<string> {
|
|
723
723
|
await this.ensureInitialized();
|
|
724
724
|
|
package/src/server.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side utilities for HumanBehavior SDK
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface ServerSideUserData {
|
|
6
|
-
email: string;
|
|
7
|
-
name?: string;
|
|
8
|
-
image?: string;
|
|
9
|
-
provider?: string;
|
|
10
|
-
[key: string]: any; // Allow additional properties
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Identify user from server-side (NextAuth, Firebase, etc.)
|
|
15
|
-
* Use this in your auth events to track users immediately on sign-in
|
|
16
|
-
*/
|
|
17
|
-
export async function identifyUser(
|
|
18
|
-
userId: string, // Separate userId parameter (should be stable unique identifier)
|
|
19
|
-
userData: ServerSideUserData,
|
|
20
|
-
apiKey: string
|
|
21
|
-
): Promise<{ success: boolean; error?: string; actualUserId?: string }> {
|
|
22
|
-
try {
|
|
23
|
-
const response = await fetch('https://ingest.humanbehavior.co/api/ingestion/user', {
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: {
|
|
26
|
-
'Content-Type': 'application/json',
|
|
27
|
-
'Authorization': `Bearer ${apiKey}`
|
|
28
|
-
},
|
|
29
|
-
body: JSON.stringify({
|
|
30
|
-
userId: userId, // Use stable unique identifier
|
|
31
|
-
userAttributes: userData, // Email and other data go here
|
|
32
|
-
sessionId: 'server-side-identification', // Dummy sessionId for server-side requests
|
|
33
|
-
posthogName: userData.email || userData.name || null // Update posthogName with email
|
|
34
|
-
})
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
const errorText = await response.text();
|
|
39
|
-
return {
|
|
40
|
-
success: false,
|
|
41
|
-
error: `Failed to identify user: ${response.status} ${response.statusText} - ${errorText}`
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const result = await response.json();
|
|
46
|
-
|
|
47
|
-
// If server found existing user, return the actual userId
|
|
48
|
-
if (result.actualUserId && result.actualUserId !== userId) {
|
|
49
|
-
console.log(`🔄 Server found existing user: ${result.actualUserId} (sent: ${userId})`);
|
|
50
|
-
return {
|
|
51
|
-
success: true,
|
|
52
|
-
actualUserId: result.actualUserId
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return { success: true };
|
|
57
|
-
} catch (error) {
|
|
58
|
-
return {
|
|
59
|
-
success: false,
|
|
60
|
-
error: error instanceof Error ? error.message : 'Unknown error'
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|