@plushanalytics/react-native-session-replay 1.2.6 → 3.0.0
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 +85 -3
- package/lib/commonjs/adapters/mobileReplayAdapter.js +98 -0
- package/lib/commonjs/adapters/mobileReplayAdapter.js.map +1 -0
- package/lib/commonjs/client.js +41 -0
- package/lib/commonjs/client.js.map +1 -0
- package/lib/commonjs/index.js +31 -37
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeBridge.js +45 -0
- package/lib/commonjs/nativeBridge.js.map +1 -0
- package/lib/commonjs/provider.js +45 -0
- package/lib/commonjs/provider.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/adapters/mobileReplayAdapter.js +93 -0
- package/lib/module/adapters/mobileReplayAdapter.js.map +1 -0
- package/lib/module/client.js +32 -0
- package/lib/module/client.js.map +1 -0
- package/lib/module/index.js +3 -33
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeBridge.js +36 -0
- package/lib/module/nativeBridge.js.map +1 -0
- package/lib/module/provider.js +39 -0
- package/lib/module/provider.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/src/adapters/mobileReplayAdapter.d.ts +8 -0
- package/lib/typescript/commonjs/src/adapters/mobileReplayAdapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/client.d.ts +6 -0
- package/lib/typescript/commonjs/src/client.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -28
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeBridge.d.ts +29 -0
- package/lib/typescript/commonjs/src/nativeBridge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/provider.d.ts +12 -0
- package/lib/typescript/commonjs/src/provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +21 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/src/adapters/mobileReplayAdapter.d.ts +8 -0
- package/lib/typescript/module/src/adapters/mobileReplayAdapter.d.ts.map +1 -0
- package/lib/typescript/module/src/client.d.ts +6 -0
- package/lib/typescript/module/src/client.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -28
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeBridge.d.ts +29 -0
- package/lib/typescript/module/src/nativeBridge.d.ts.map +1 -0
- package/lib/typescript/module/src/provider.d.ts +12 -0
- package/lib/typescript/module/src/provider.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +21 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/package.json +22 -25
- package/src/adapters/mobileReplayAdapter.ts +113 -0
- package/src/client.ts +42 -0
- package/src/index.tsx +23 -79
- package/src/nativeBridge.ts +79 -0
- package/src/provider.tsx +46 -0
- package/src/types.ts +59 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPlushAnalyticsClient as createCoreClient,
|
|
3
|
+
PlushAnalyticsClient
|
|
4
|
+
} from "@plushanalytics/javascript";
|
|
5
|
+
import { createMobileReplayRecorderAdapter } from "./adapters/mobileReplayAdapter";
|
|
6
|
+
import type { PlushAnalyticsConfig, SessionRecordingOptions } from "./types";
|
|
7
|
+
|
|
8
|
+
export { PlushAnalyticsClient };
|
|
9
|
+
|
|
10
|
+
const DEFAULT_ENDPOINT = "https://apim-plushanalytics-prod-rwth6ltqgdxg2.azure-api.net/api";
|
|
11
|
+
|
|
12
|
+
function normalizeSource(value: unknown): string | undefined {
|
|
13
|
+
if (typeof value !== "string") return undefined;
|
|
14
|
+
const trimmed = value.trim();
|
|
15
|
+
if (!trimmed) return undefined;
|
|
16
|
+
return trimmed.length > 64 ? trimmed.slice(0, 64) : trimmed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createPlushAnalyticsClient(config: PlushAnalyticsConfig): PlushAnalyticsClient {
|
|
20
|
+
const endpoint = config.endpoint ?? DEFAULT_ENDPOINT;
|
|
21
|
+
const source = normalizeSource(config.source) ?? "mobile";
|
|
22
|
+
|
|
23
|
+
const wrapped: PlushAnalyticsConfig = {
|
|
24
|
+
...config,
|
|
25
|
+
endpoint,
|
|
26
|
+
source,
|
|
27
|
+
replay: {
|
|
28
|
+
...(config.replay ?? {}),
|
|
29
|
+
defaultRecorder:
|
|
30
|
+
config.replay?.defaultRecorder ??
|
|
31
|
+
createMobileReplayRecorderAdapter({
|
|
32
|
+
apiKey: config.apiKey,
|
|
33
|
+
endpoint
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return createCoreClient(wrapped);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Re-export the type so consumers can pass platform-specific options while using the core surface.
|
|
42
|
+
export type { SessionRecordingOptions };
|
package/src/index.tsx
CHANGED
|
@@ -1,79 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
sdkReplayConfig: { [key: string]: any },
|
|
25
|
-
decideReplayConfig: { [key: string]: any }
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
return PosthogReactNativeSessionReplay.start(
|
|
28
|
-
sessionId,
|
|
29
|
-
sdkOptions,
|
|
30
|
-
sdkReplayConfig,
|
|
31
|
-
decideReplayConfig
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function startSession(sessionId: string): Promise<void> {
|
|
36
|
-
return PosthogReactNativeSessionReplay.startSession(sessionId);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function endSession(): Promise<void> {
|
|
40
|
-
return PosthogReactNativeSessionReplay.endSession();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function isEnabled(): Promise<boolean> {
|
|
44
|
-
return PosthogReactNativeSessionReplay.isEnabled();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function identify(
|
|
48
|
-
distinctId: string,
|
|
49
|
-
anonymousId: string
|
|
50
|
-
): Promise<void> {
|
|
51
|
-
return PosthogReactNativeSessionReplay.identify(distinctId, anonymousId);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface PostHogReactNativeSessionReplayModule {
|
|
55
|
-
start: (
|
|
56
|
-
sessionId: string,
|
|
57
|
-
sdkOptions: { [key: string]: any }, // options from SDK such as apiKey
|
|
58
|
-
sdkReplayConfig: { [key: string]: any }, // config from SDK
|
|
59
|
-
decideReplayConfig: { [key: string]: any } // config from Decide API
|
|
60
|
-
) => Promise<void>;
|
|
61
|
-
|
|
62
|
-
startSession: (sessionId: string) => Promise<void>;
|
|
63
|
-
|
|
64
|
-
endSession: () => Promise<void>;
|
|
65
|
-
|
|
66
|
-
isEnabled: () => Promise<boolean>;
|
|
67
|
-
|
|
68
|
-
identify: (distinctId: string, anonymousId: string) => Promise<void>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const PostHogReactNativeSessionReplay: PostHogReactNativeSessionReplayModule = {
|
|
72
|
-
start,
|
|
73
|
-
startSession,
|
|
74
|
-
endSession,
|
|
75
|
-
isEnabled,
|
|
76
|
-
identify,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default PostHogReactNativeSessionReplay;
|
|
1
|
+
export { createPlushAnalyticsClient, PlushAnalyticsClient } from "./client";
|
|
2
|
+
export { createMobileReplayRecorderAdapter } from "./adapters/mobileReplayAdapter";
|
|
3
|
+
export { PlushAnalyticsProvider, usePlushAnalytics } from "./provider";
|
|
4
|
+
export type {
|
|
5
|
+
EventEnvelope,
|
|
6
|
+
EventType,
|
|
7
|
+
FlushResult,
|
|
8
|
+
GroupOptions,
|
|
9
|
+
IdentifyOptions,
|
|
10
|
+
JsonValue,
|
|
11
|
+
MobileReplayConfig,
|
|
12
|
+
PlushAnalytics,
|
|
13
|
+
PlushAnalyticsConfig,
|
|
14
|
+
ReplayChunkEnvelope,
|
|
15
|
+
ReplayRecordEmission,
|
|
16
|
+
ReplayRecorderAdapter,
|
|
17
|
+
RetryOptions,
|
|
18
|
+
ScreenOptions,
|
|
19
|
+
SessionRecordingOptions,
|
|
20
|
+
StorageAdapter,
|
|
21
|
+
TrackOptions,
|
|
22
|
+
UnifiedBatchPayload
|
|
23
|
+
} from "./types";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package '@plushanalytics/react-native-session-replay' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo Go\n';
|
|
8
|
+
|
|
9
|
+
const PosthogReactNativeSessionReplay =
|
|
10
|
+
NativeModules.PosthogReactNativeSessionReplay
|
|
11
|
+
? NativeModules.PosthogReactNativeSessionReplay
|
|
12
|
+
: new Proxy(
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
get() {
|
|
16
|
+
throw new Error(LINKING_ERROR);
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export function start(
|
|
22
|
+
sessionId: string,
|
|
23
|
+
sdkOptions: { [key: string]: any },
|
|
24
|
+
sdkReplayConfig: { [key: string]: any },
|
|
25
|
+
decideReplayConfig: { [key: string]: any }
|
|
26
|
+
): Promise<void> {
|
|
27
|
+
return PosthogReactNativeSessionReplay.start(
|
|
28
|
+
sessionId,
|
|
29
|
+
sdkOptions,
|
|
30
|
+
sdkReplayConfig,
|
|
31
|
+
decideReplayConfig
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function startSession(sessionId: string): Promise<void> {
|
|
36
|
+
return PosthogReactNativeSessionReplay.startSession(sessionId);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function endSession(): Promise<void> {
|
|
40
|
+
return PosthogReactNativeSessionReplay.endSession();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isEnabled(): Promise<boolean> {
|
|
44
|
+
return PosthogReactNativeSessionReplay.isEnabled();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function identify(
|
|
48
|
+
distinctId: string,
|
|
49
|
+
anonymousId: string
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
return PosthogReactNativeSessionReplay.identify(distinctId, anonymousId);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PostHogReactNativeSessionReplayModule {
|
|
55
|
+
start: (
|
|
56
|
+
sessionId: string,
|
|
57
|
+
sdkOptions: { [key: string]: any }, // options from SDK such as apiKey
|
|
58
|
+
sdkReplayConfig: { [key: string]: any }, // config from SDK
|
|
59
|
+
decideReplayConfig: { [key: string]: any } // config from Decide API
|
|
60
|
+
) => Promise<void>;
|
|
61
|
+
|
|
62
|
+
startSession: (sessionId: string) => Promise<void>;
|
|
63
|
+
|
|
64
|
+
endSession: () => Promise<void>;
|
|
65
|
+
|
|
66
|
+
isEnabled: () => Promise<boolean>;
|
|
67
|
+
|
|
68
|
+
identify: (distinctId: string, anonymousId: string) => Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const PostHogReactNativeSessionReplay: PostHogReactNativeSessionReplayModule = {
|
|
72
|
+
start,
|
|
73
|
+
startSession,
|
|
74
|
+
endSession,
|
|
75
|
+
isEnabled,
|
|
76
|
+
identify,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default PostHogReactNativeSessionReplay;
|
package/src/provider.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useRef } from "react";
|
|
2
|
+
import { createPlushAnalyticsClient, type PlushAnalyticsClient } from "./client";
|
|
3
|
+
import type { PlushAnalytics, PlushAnalyticsConfig } from "./types";
|
|
4
|
+
|
|
5
|
+
type PlushAnalyticsProviderProps = {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
config?: PlushAnalyticsConfig;
|
|
8
|
+
client?: PlushAnalyticsClient;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const PlushAnalyticsContext = createContext<PlushAnalytics | null>(null);
|
|
12
|
+
|
|
13
|
+
export function PlushAnalyticsProvider({
|
|
14
|
+
children,
|
|
15
|
+
config,
|
|
16
|
+
client
|
|
17
|
+
}: PlushAnalyticsProviderProps): React.ReactElement {
|
|
18
|
+
const clientRef = useRef<PlushAnalyticsClient | null>(null);
|
|
19
|
+
|
|
20
|
+
if (!clientRef.current) {
|
|
21
|
+
if (client) {
|
|
22
|
+
clientRef.current = client;
|
|
23
|
+
} else if (config) {
|
|
24
|
+
clientRef.current = createPlushAnalyticsClient(config);
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error("PlushAnalyticsProvider requires either a `client` or `config` prop.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
return () => {
|
|
32
|
+
void clientRef.current?.shutdown();
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
return <PlushAnalyticsContext.Provider value={clientRef.current}>{children}</PlushAnalyticsContext.Provider>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function usePlushAnalytics(): PlushAnalytics {
|
|
40
|
+
const context = useContext(PlushAnalyticsContext);
|
|
41
|
+
if (!context) {
|
|
42
|
+
throw new Error("usePlushAnalytics must be used inside PlushAnalyticsProvider.");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return context;
|
|
46
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventEnvelope,
|
|
3
|
+
EventType,
|
|
4
|
+
FlushResult,
|
|
5
|
+
GroupOptions,
|
|
6
|
+
IdentifyOptions,
|
|
7
|
+
JsonValue,
|
|
8
|
+
PlushAnalytics as CorePlushAnalytics,
|
|
9
|
+
PlushAnalyticsConfig as CoreConfig,
|
|
10
|
+
ReplayChunkEnvelope,
|
|
11
|
+
ReplayRecordEmission,
|
|
12
|
+
ReplayRecorderAdapter,
|
|
13
|
+
RetryOptions,
|
|
14
|
+
ScreenOptions,
|
|
15
|
+
SessionRecordingOptions as CoreSessionRecordingOptions,
|
|
16
|
+
StorageAdapter,
|
|
17
|
+
TrackOptions,
|
|
18
|
+
UnifiedBatchPayload
|
|
19
|
+
} from "@plushanalytics/javascript";
|
|
20
|
+
|
|
21
|
+
export type MobileReplayConfig = {
|
|
22
|
+
maskAllTextInputs?: boolean;
|
|
23
|
+
maskAllImages?: boolean;
|
|
24
|
+
maskAllSandboxedViews?: boolean;
|
|
25
|
+
captureLog?: boolean;
|
|
26
|
+
captureNetworkTelemetry?: boolean;
|
|
27
|
+
throttleDelayMs?: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type SessionRecordingOptions = CoreSessionRecordingOptions & {
|
|
31
|
+
// Used by the bundled replay adapter (optional, replay still works without these when you pass a custom recorder).
|
|
32
|
+
replayHost?: string;
|
|
33
|
+
replaySnapshotPath?: string;
|
|
34
|
+
replayConfig?: MobileReplayConfig;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type PlushAnalyticsConfig = CoreConfig;
|
|
38
|
+
|
|
39
|
+
export type {
|
|
40
|
+
EventEnvelope,
|
|
41
|
+
EventType,
|
|
42
|
+
FlushResult,
|
|
43
|
+
GroupOptions,
|
|
44
|
+
IdentifyOptions,
|
|
45
|
+
JsonValue,
|
|
46
|
+
ReplayChunkEnvelope,
|
|
47
|
+
ReplayRecordEmission,
|
|
48
|
+
ReplayRecorderAdapter,
|
|
49
|
+
RetryOptions,
|
|
50
|
+
ScreenOptions,
|
|
51
|
+
StorageAdapter,
|
|
52
|
+
TrackOptions,
|
|
53
|
+
UnifiedBatchPayload
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type PlushAnalytics = Omit<CorePlushAnalytics, "startSessionRecording" | "startReplay"> & {
|
|
57
|
+
startSessionRecording: (options?: SessionRecordingOptions) => Promise<void>;
|
|
58
|
+
startReplay: (options?: SessionRecordingOptions) => Promise<void>;
|
|
59
|
+
};
|