humanbehavior-js 0.0.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/dist/cjs/index.js +4810 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/react/index.js +218 -0
- package/dist/cjs/react/index.js.map +1 -0
- package/dist/esm/index.js +4801 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/react/index.js +215 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/index.min.js +16 -0
- package/dist/index.min.js.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/react/index.d.ts +19 -0
- package/index.d.ts +2 -0
- package/index.js +3 -0
- package/package.json +71 -0
- package/react.d.ts +2 -0
- package/react.js +2 -0
- package/readme.md +57 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
HumanBehaviorTracker: typeof HumanBehaviorTracker;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
declare class HumanBehaviorTracker {
|
|
7
|
+
private eventIngestionQueue;
|
|
8
|
+
private queueSizeBytes;
|
|
9
|
+
private rejectedEvents;
|
|
10
|
+
private isProcessingRejectedEvents;
|
|
11
|
+
private sessionId;
|
|
12
|
+
private userProperties;
|
|
13
|
+
private isProcessing;
|
|
14
|
+
private flushInterval;
|
|
15
|
+
private readonly FLUSH_INTERVAL_MS;
|
|
16
|
+
private api;
|
|
17
|
+
private endUserId;
|
|
18
|
+
private apiKey;
|
|
19
|
+
private initialized;
|
|
20
|
+
initializationPromise: Promise<void> | null;
|
|
21
|
+
constructor(apiKey: string);
|
|
22
|
+
private init;
|
|
23
|
+
private ensureInitialized;
|
|
24
|
+
static logToStorage(message: string): void;
|
|
25
|
+
private setupPageUnloadHandler;
|
|
26
|
+
viewLogs(): void;
|
|
27
|
+
identifyUser(userProperties: Record<string, any>): Promise<void>;
|
|
28
|
+
customEvent(eventName: string, eventProperties?: Record<string, any>): Promise<void>;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
stop(): Promise<void>;
|
|
31
|
+
addEvent(event: any): Promise<void>;
|
|
32
|
+
private processRejectedEvents;
|
|
33
|
+
private flush;
|
|
34
|
+
private setCookie;
|
|
35
|
+
private getCookie;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare const MAX_CHUNK_SIZE_BYTES: number;
|
|
39
|
+
declare function isChunkSizeExceeded(currentChunk: any[], newEvent: any, sessionId: string): boolean;
|
|
40
|
+
declare function validateSingleEventSize(event: any, sessionId: string): void;
|
|
41
|
+
declare class HumanBehaviorAPI {
|
|
42
|
+
private apiKey;
|
|
43
|
+
private baseUrl;
|
|
44
|
+
constructor({ apiKey }: {
|
|
45
|
+
apiKey: string;
|
|
46
|
+
});
|
|
47
|
+
init(sessionId: string, userId: string | null): Promise<{
|
|
48
|
+
sessionId: any;
|
|
49
|
+
endUserId: any;
|
|
50
|
+
}>;
|
|
51
|
+
sendEvents(events: any[], sessionId: string, userId: string): Promise<void>;
|
|
52
|
+
sendEventsChunked(events: any[], sessionId: string): Promise<any[]>;
|
|
53
|
+
sendUserData(userId: string, userData: Record<string, any>, sessionId: string): Promise<any>;
|
|
54
|
+
sendSessionComplete(sessionId: string): Promise<void>;
|
|
55
|
+
sendCustomEvent(eventName: string, eventProperties: Record<string, any>, sessionId: string): Promise<any>;
|
|
56
|
+
sendCustomEvents(events: any[], sessionId: string): Promise<any>;
|
|
57
|
+
sendBeaconEvents(events: any[], sessionId: string, isSessionComplete?: boolean): void;
|
|
58
|
+
sendBeaconSessionComplete(sessionId: string): void;
|
|
59
|
+
sendBeaconCustomEvent(eventName: string, eventProperties: Record<string, any>, sessionId: string): boolean;
|
|
60
|
+
sendBeaconCustomEvents(events: any[], sessionId: string): boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { HumanBehaviorAPI, HumanBehaviorTracker, MAX_CHUNK_SIZE_BYTES, HumanBehaviorTracker as default, isChunkSizeExceeded, validateSingleEventSize };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { HumanBehaviorTracker } from '..';
|
|
3
|
+
|
|
4
|
+
interface HumanBehaviorInterface {
|
|
5
|
+
addEvent: (event: any) => void;
|
|
6
|
+
identifyUser: (userProperties: Record<string, any>) => Promise<void>;
|
|
7
|
+
start: () => void;
|
|
8
|
+
stop: () => void;
|
|
9
|
+
viewLogs: () => void;
|
|
10
|
+
}
|
|
11
|
+
interface HumanBehaviorProviderProps {
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
client?: HumanBehaviorTracker;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
declare const HumanBehaviorProvider: ({ apiKey, client, children }: HumanBehaviorProviderProps) => React.JSX.Element;
|
|
17
|
+
declare const useHumanBehavior: () => HumanBehaviorInterface;
|
|
18
|
+
|
|
19
|
+
export { HumanBehaviorProvider, useHumanBehavior };
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "humanbehavior-js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "SDK for HumanBehavior session and event recording",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"unpkg": "dist/index.min.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"react.js",
|
|
13
|
+
"react.d.ts",
|
|
14
|
+
"index.js",
|
|
15
|
+
"index.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/esm/index.js",
|
|
20
|
+
"require": "./dist/cjs/index.js",
|
|
21
|
+
"types": "./dist/types/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./react": {
|
|
24
|
+
"import": "./dist/esm/react/index.js",
|
|
25
|
+
"require": "./dist/cjs/react/index.js",
|
|
26
|
+
"types": "./dist/types/react/index.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rollup -c",
|
|
31
|
+
"build:dev": "rollup -c --environment NODE_ENV:development",
|
|
32
|
+
"prepare": "npm run build",
|
|
33
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
34
|
+
},
|
|
35
|
+
"author": "Chirag Kawediya, Skyler Ji, Amogh Chaturvedi",
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@types/react": "^19.0.12",
|
|
39
|
+
"react": "^19.0.0",
|
|
40
|
+
"rrweb": "^2.0.0-alpha.4",
|
|
41
|
+
"uuid": "^11.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
45
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
46
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
47
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
48
|
+
"@types/cors": "^2.8.17",
|
|
49
|
+
"@types/express": "^5.0.1",
|
|
50
|
+
"rollup": "^4.36.0",
|
|
51
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
52
|
+
"ts-loader": "^9.5.2",
|
|
53
|
+
"tslib": "^2.8.1",
|
|
54
|
+
"typescript": "^5.8.2",
|
|
55
|
+
"webpack": "^5.98.0",
|
|
56
|
+
"webpack-cli": "^6.0.1"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "https://github.com/humanbehavior-gh/HumanBehavior.git"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"session-recording",
|
|
67
|
+
"analytics",
|
|
68
|
+
"rrweb",
|
|
69
|
+
"koalaware"
|
|
70
|
+
]
|
|
71
|
+
}
|
package/react.d.ts
ADDED
package/react.js
ADDED
package/readme.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
To build, run `npm run build`
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
|
|
6
|
+
NextJS
|
|
7
|
+
|
|
8
|
+
Add the following to your `providers.tsx` file.
|
|
9
|
+
```ts
|
|
10
|
+
"use client"
|
|
11
|
+
|
|
12
|
+
import { KoalawareTracker } from "koalaware-js";
|
|
13
|
+
import { KoalawareProvider as KoalawareProviderJS } from "koalaware-js/react";
|
|
14
|
+
import { useEffect, useState } from "react";
|
|
15
|
+
|
|
16
|
+
export function KoalawareProvider({ children }: { children: React.ReactNode }) {
|
|
17
|
+
const [koalaware, setKoalaware] = useState<KoalawareTracker | null>(null);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const apiKey = "kw_1c8969a408ea2eb333fd174a7684c7c943e82ea1df8349b43640e4b608f35e68";
|
|
21
|
+
const koalaware = new KoalawareTracker(apiKey);
|
|
22
|
+
setKoalaware(koalaware);
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<KoalawareProviderJS client={koalaware}>
|
|
27
|
+
{children}
|
|
28
|
+
</KoalawareProviderJS>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Next, add the provider to your root app layout.
|
|
34
|
+
```ts
|
|
35
|
+
export default async function RootLayout({
|
|
36
|
+
children
|
|
37
|
+
}: {
|
|
38
|
+
children: React.ReactNode;
|
|
39
|
+
}) {
|
|
40
|
+
const session = await auth();
|
|
41
|
+
return (
|
|
42
|
+
<html lang='en' className={`${lato.className}`} suppressHydrationWarning>
|
|
43
|
+
<body className={'overflow-hidden'}>
|
|
44
|
+
<NextTopLoader showSpinner={false} />
|
|
45
|
+
<KoalawareProvider>
|
|
46
|
+
<NuqsAdapter>
|
|
47
|
+
<Providers session={session}>
|
|
48
|
+
<Toaster />
|
|
49
|
+
{children}
|
|
50
|
+
</Providers>
|
|
51
|
+
</NuqsAdapter>
|
|
52
|
+
</KoalawareProvider>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|