@plushanalytics/react-native-session-replay 1.2.6 → 3.0.2

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.
Files changed (59) hide show
  1. package/README.md +138 -3
  2. package/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayModule.kt +68 -27
  3. package/ios/PosthogReactNativeSessionReplay.mm +3 -0
  4. package/ios/PosthogReactNativeSessionReplay.swift +58 -31
  5. package/lib/commonjs/adapters/mobileReplayAdapter.js +135 -0
  6. package/lib/commonjs/adapters/mobileReplayAdapter.js.map +1 -0
  7. package/lib/commonjs/client.js +42 -0
  8. package/lib/commonjs/client.js.map +1 -0
  9. package/lib/commonjs/index.js +31 -37
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/nativeBridge.js +50 -0
  12. package/lib/commonjs/nativeBridge.js.map +1 -0
  13. package/lib/commonjs/provider.js +45 -0
  14. package/lib/commonjs/provider.js.map +1 -0
  15. package/lib/commonjs/types.js +6 -0
  16. package/lib/commonjs/types.js.map +1 -0
  17. package/lib/module/adapters/mobileReplayAdapter.js +130 -0
  18. package/lib/module/adapters/mobileReplayAdapter.js.map +1 -0
  19. package/lib/module/client.js +33 -0
  20. package/lib/module/client.js.map +1 -0
  21. package/lib/module/index.js +3 -33
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/nativeBridge.js +40 -0
  24. package/lib/module/nativeBridge.js.map +1 -0
  25. package/lib/module/provider.js +39 -0
  26. package/lib/module/provider.js.map +1 -0
  27. package/lib/module/types.js +4 -0
  28. package/lib/module/types.js.map +1 -0
  29. package/lib/typescript/commonjs/src/adapters/mobileReplayAdapter.d.ts +9 -0
  30. package/lib/typescript/commonjs/src/adapters/mobileReplayAdapter.d.ts.map +1 -0
  31. package/lib/typescript/commonjs/src/client.d.ts +6 -0
  32. package/lib/typescript/commonjs/src/client.d.ts.map +1 -0
  33. package/lib/typescript/commonjs/src/index.d.ts +4 -28
  34. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/src/nativeBridge.d.ts +31 -0
  36. package/lib/typescript/commonjs/src/nativeBridge.d.ts.map +1 -0
  37. package/lib/typescript/commonjs/src/provider.d.ts +12 -0
  38. package/lib/typescript/commonjs/src/provider.d.ts.map +1 -0
  39. package/lib/typescript/commonjs/src/types.d.ts +32 -0
  40. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  41. package/lib/typescript/module/src/adapters/mobileReplayAdapter.d.ts +9 -0
  42. package/lib/typescript/module/src/adapters/mobileReplayAdapter.d.ts.map +1 -0
  43. package/lib/typescript/module/src/client.d.ts +6 -0
  44. package/lib/typescript/module/src/client.d.ts.map +1 -0
  45. package/lib/typescript/module/src/index.d.ts +4 -28
  46. package/lib/typescript/module/src/index.d.ts.map +1 -1
  47. package/lib/typescript/module/src/nativeBridge.d.ts +31 -0
  48. package/lib/typescript/module/src/nativeBridge.d.ts.map +1 -0
  49. package/lib/typescript/module/src/provider.d.ts +12 -0
  50. package/lib/typescript/module/src/provider.d.ts.map +1 -0
  51. package/lib/typescript/module/src/types.d.ts +32 -0
  52. package/lib/typescript/module/src/types.d.ts.map +1 -0
  53. package/package.json +22 -25
  54. package/src/adapters/mobileReplayAdapter.ts +206 -0
  55. package/src/client.ts +43 -0
  56. package/src/index.tsx +25 -79
  57. package/src/nativeBridge.ts +86 -0
  58. package/src/provider.tsx +46 -0
  59. package/src/types.ts +73 -0
package/src/index.tsx CHANGED
@@ -1,79 +1,25 @@
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;
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
+ SessionReplayConfig,
21
+ SessionReplayMaskingConfig,
22
+ StorageAdapter,
23
+ TrackOptions,
24
+ UnifiedBatchPayload
25
+ } from "./types";
@@ -0,0 +1,86 @@
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 flush(): Promise<void> {
44
+ return PosthogReactNativeSessionReplay.flush();
45
+ }
46
+
47
+ export function isEnabled(): Promise<boolean> {
48
+ return PosthogReactNativeSessionReplay.isEnabled();
49
+ }
50
+
51
+ export function identify(
52
+ distinctId: string,
53
+ anonymousId: string
54
+ ): Promise<void> {
55
+ return PosthogReactNativeSessionReplay.identify(distinctId, anonymousId);
56
+ }
57
+
58
+ export interface PostHogReactNativeSessionReplayModule {
59
+ start: (
60
+ sessionId: string,
61
+ sdkOptions: { [key: string]: any }, // options from SDK such as apiKey
62
+ sdkReplayConfig: { [key: string]: any }, // config from SDK
63
+ decideReplayConfig: { [key: string]: any } // replay runtime config
64
+ ) => Promise<void>;
65
+
66
+ startSession: (sessionId: string) => Promise<void>;
67
+
68
+ endSession: () => Promise<void>;
69
+
70
+ flush: () => Promise<void>;
71
+
72
+ isEnabled: () => Promise<boolean>;
73
+
74
+ identify: (distinctId: string, anonymousId: string) => Promise<void>;
75
+ }
76
+
77
+ const PostHogReactNativeSessionReplay: PostHogReactNativeSessionReplayModule = {
78
+ start,
79
+ startSession,
80
+ endSession,
81
+ flush,
82
+ isEnabled,
83
+ identify,
84
+ };
85
+
86
+ export default PostHogReactNativeSessionReplay;
@@ -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,73 @@
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 SessionReplayMaskingConfig = {
22
+ textInputs?: boolean;
23
+ images?: boolean;
24
+ sandboxedViews?: boolean;
25
+ };
26
+
27
+ export type SessionReplayConfig = {
28
+ enabled?: boolean;
29
+ masking?: SessionReplayMaskingConfig;
30
+ captureLog?: boolean;
31
+ captureNetworkTelemetry?: boolean;
32
+ throttleDelayMs?: number;
33
+ };
34
+
35
+ export type MobileReplayConfig = SessionReplayConfig & {
36
+ // Legacy flat options are still supported for backward compatibility.
37
+ maskAllTextInputs?: boolean;
38
+ maskAllImages?: boolean;
39
+ maskAllSandboxedViews?: boolean;
40
+ };
41
+
42
+ export type SessionRecordingOptions = CoreSessionRecordingOptions & {
43
+ // Used by the bundled replay adapter (optional, replay still works without these when you pass a custom recorder).
44
+ replayHost?: string;
45
+ replaySnapshotPath?: string;
46
+ replayConfig?: MobileReplayConfig;
47
+ };
48
+
49
+ export type PlushAnalyticsConfig = CoreConfig & {
50
+ sessionReplayConfig?: SessionReplayConfig;
51
+ };
52
+
53
+ export type {
54
+ EventEnvelope,
55
+ EventType,
56
+ FlushResult,
57
+ GroupOptions,
58
+ IdentifyOptions,
59
+ JsonValue,
60
+ ReplayChunkEnvelope,
61
+ ReplayRecordEmission,
62
+ ReplayRecorderAdapter,
63
+ RetryOptions,
64
+ ScreenOptions,
65
+ StorageAdapter,
66
+ TrackOptions,
67
+ UnifiedBatchPayload
68
+ };
69
+
70
+ export type PlushAnalytics = Omit<CorePlushAnalytics, "startSessionRecording" | "startReplay"> & {
71
+ startSessionRecording: (options?: SessionRecordingOptions) => Promise<void>;
72
+ startReplay: (options?: SessionRecordingOptions) => Promise<void>;
73
+ };