@posthog/react-native-plugin 0.0.1 → 2.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/LICENSE +326 -0
- package/README.md +21 -35
- package/android/build.gradle +90 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt +301 -0
- package/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginPackage.kt +13 -0
- package/ios/PosthogReactNativePlugin-Bridging-Header.h +2 -0
- package/ios/PosthogReactNativePlugin.mm +45 -0
- package/ios/PosthogReactNativePlugin.swift +217 -0
- package/lib/commonjs/index.js +60 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +48 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +39 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +39 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +112 -7
- package/posthog-react-native-plugin.podspec +68 -0
- package/src/index.tsx +119 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","PosthogReactNativePlugin","Proxy","get","Error","setup","sessionId","sdkOptions","pluginConfig","start","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","startRecording","resumeCurrent","stopRecording","PostHogReactNativePlugin"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,uFAAuF,GACvFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC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B,CAACmB,aAAa,CAAC,CAAC;AACjD;AAgCA,MAAMC,wBAAwD,GAAG;EAC/DhB,KAAK;EACLI,KAAK;EACLG,YAAY;EACZC,UAAU;EACVC,SAAS;EACTC,QAAQ;EACRG,cAAc;EACdE;AACF,CAAC;AAED,eAAeC,wBAAwB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type PostHogReactNativePluginMap = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export interface PostHogReactNativePluginSessionReplayConfig {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
sdkReplayConfig?: PostHogReactNativePluginMap;
|
|
7
|
+
decideReplayConfig?: PostHogReactNativePluginMap;
|
|
8
|
+
}
|
|
9
|
+
export interface PostHogReactNativePluginErrorTrackingConfig {
|
|
10
|
+
nativeAutocapture?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PostHogReactNativePluginConfig {
|
|
13
|
+
sessionReplay?: PostHogReactNativePluginSessionReplayConfig;
|
|
14
|
+
errorTracking?: PostHogReactNativePluginErrorTrackingConfig;
|
|
15
|
+
}
|
|
16
|
+
export declare function setup(sessionId: string, sdkOptions: PostHogReactNativePluginMap, pluginConfig?: PostHogReactNativePluginConfig): Promise<void>;
|
|
17
|
+
export declare function start(sessionId: string, sdkOptions: PostHogReactNativePluginMap, sdkReplayConfig: PostHogReactNativePluginMap, decideReplayConfig: PostHogReactNativePluginMap): Promise<void>;
|
|
18
|
+
export declare function startSession(sessionId: string): Promise<void>;
|
|
19
|
+
export declare function endSession(): Promise<void>;
|
|
20
|
+
export declare function isEnabled(): Promise<boolean>;
|
|
21
|
+
export declare function identify(distinctId: string, anonymousId: string): Promise<void>;
|
|
22
|
+
export declare function startRecording(resumeCurrent: boolean): Promise<void>;
|
|
23
|
+
export declare function stopRecording(): Promise<void>;
|
|
24
|
+
export interface PostHogReactNativePluginModule {
|
|
25
|
+
setup: (sessionId: string, sdkOptions: PostHogReactNativePluginMap, pluginConfig?: PostHogReactNativePluginConfig) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Legacy session replay setup entrypoint. Prefer setup() for new native features.
|
|
28
|
+
*/
|
|
29
|
+
start: (sessionId: string, sdkOptions: PostHogReactNativePluginMap, sdkReplayConfig: PostHogReactNativePluginMap, decideReplayConfig: PostHogReactNativePluginMap) => Promise<void>;
|
|
30
|
+
startSession: (sessionId: string) => Promise<void>;
|
|
31
|
+
endSession: () => Promise<void>;
|
|
32
|
+
isEnabled: () => Promise<boolean>;
|
|
33
|
+
identify: (distinctId: string, anonymousId: string) => Promise<void>;
|
|
34
|
+
startRecording: (resumeCurrent: boolean) => Promise<void>;
|
|
35
|
+
stopRecording: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
declare const PostHogReactNativePlugin: PostHogReactNativePluginModule;
|
|
38
|
+
export default PostHogReactNativePlugin;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,MAAM,2BAA2B,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAEhE,MAAM,WAAW,2CAA2C;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,eAAe,CAAC,EAAE,2BAA2B,CAAA;IAC7C,kBAAkB,CAAC,EAAE,2BAA2B,CAAA;CACjD;AAED,MAAM,WAAW,2CAA2C;IAC1D,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,2CAA2C,CAAA;IAC3D,aAAa,CAAC,EAAE,2CAA2C,CAAA;CAC5D;AAED,wBAAgB,KAAK,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,2BA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AAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpE,cAAc,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzD,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACnC;AAED,QAAA,MAAM,wBAAwB,EAAE,8BAS/B,CAAA;AAED,eAAe,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type PostHogReactNativePluginMap = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export interface PostHogReactNativePluginSessionReplayConfig {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
sdkReplayConfig?: PostHogReactNativePluginMap;
|
|
7
|
+
decideReplayConfig?: PostHogReactNativePluginMap;
|
|
8
|
+
}
|
|
9
|
+
export interface PostHogReactNativePluginErrorTrackingConfig {
|
|
10
|
+
nativeAutocapture?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PostHogReactNativePluginConfig {
|
|
13
|
+
sessionReplay?: PostHogReactNativePluginSessionReplayConfig;
|
|
14
|
+
errorTracking?: PostHogReactNativePluginErrorTrackingConfig;
|
|
15
|
+
}
|
|
16
|
+
export declare function setup(sessionId: string, sdkOptions: PostHogReactNativePluginMap, pluginConfig?: PostHogReactNativePluginConfig): Promise<void>;
|
|
17
|
+
export declare function start(sessionId: string, sdkOptions: PostHogReactNativePluginMap, sdkReplayConfig: PostHogReactNativePluginMap, decideReplayConfig: PostHogReactNativePluginMap): Promise<void>;
|
|
18
|
+
export declare function startSession(sessionId: string): Promise<void>;
|
|
19
|
+
export declare function endSession(): Promise<void>;
|
|
20
|
+
export declare function isEnabled(): Promise<boolean>;
|
|
21
|
+
export declare function identify(distinctId: string, anonymousId: string): Promise<void>;
|
|
22
|
+
export declare function startRecording(resumeCurrent: boolean): Promise<void>;
|
|
23
|
+
export declare function stopRecording(): Promise<void>;
|
|
24
|
+
export interface PostHogReactNativePluginModule {
|
|
25
|
+
setup: (sessionId: string, sdkOptions: PostHogReactNativePluginMap, pluginConfig?: PostHogReactNativePluginConfig) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Legacy session replay setup entrypoint. Prefer setup() for new native features.
|
|
28
|
+
*/
|
|
29
|
+
start: (sessionId: string, sdkOptions: PostHogReactNativePluginMap, sdkReplayConfig: PostHogReactNativePluginMap, decideReplayConfig: PostHogReactNativePluginMap) => Promise<void>;
|
|
30
|
+
startSession: (sessionId: string) => Promise<void>;
|
|
31
|
+
endSession: () => Promise<void>;
|
|
32
|
+
isEnabled: () => Promise<boolean>;
|
|
33
|
+
identify: (distinctId: string, anonymousId: string) => Promise<void>;
|
|
34
|
+
startRecording: (resumeCurrent: boolean) => Promise<void>;
|
|
35
|
+
stopRecording: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
declare const PostHogReactNativePlugin: PostHogReactNativePluginModule;
|
|
38
|
+
export default PostHogReactNativePlugin;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,MAAM,2BAA2B,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAEhE,MAAM,WAAW,2CAA2C;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,eAAe,CAAC,EAAE,2BAA2B,CAAA;IAC7C,kBAAkB,CAAC,EAAE,2BAA2B,CAAA;CACjD;AAED,MAAM,WAAW,2CAA2C;IAC1D,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B;AAED,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,2CAA2C,CAAA;IAC3D,aAAa,CAAC,EAAE,2CAA2C,CAA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AAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAEjC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpE,cAAc,EAAE,CAAC,aAAa,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzD,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACnC;AAED,QAAA,MAAM,wBAAwB,EAAE,8BAS/B,CAAA;AAED,eAAe,wBAAwB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,115 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/react-native-plugin",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "PostHog React Native plugin for iOS and Android integrations",
|
|
5
|
+
"source": "./src/index.tsx",
|
|
6
|
+
"main": "./lib/commonjs/index.js",
|
|
7
|
+
"module": "./lib/module/index.js",
|
|
8
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
13
|
+
"default": "./lib/module/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
17
|
+
"default": "./lib/commonjs/index.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"lib",
|
|
24
|
+
"android",
|
|
25
|
+
"ios",
|
|
26
|
+
"cpp",
|
|
27
|
+
"*.podspec",
|
|
28
|
+
"!ios/build",
|
|
29
|
+
"!android/build",
|
|
30
|
+
"!android/gradle",
|
|
31
|
+
"!android/gradlew",
|
|
32
|
+
"!android/gradlew.bat",
|
|
33
|
+
"!android/local.properties",
|
|
34
|
+
"!**/__tests__",
|
|
35
|
+
"!**/__fixtures__",
|
|
36
|
+
"!**/__mocks__",
|
|
37
|
+
"!**/.*"
|
|
38
|
+
],
|
|
5
39
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
]
|
|
10
|
-
|
|
40
|
+
"react-native",
|
|
41
|
+
"ios",
|
|
42
|
+
"android"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/PostHog/posthog-js.git",
|
|
47
|
+
"directory": "packages/react-native-plugin"
|
|
48
|
+
},
|
|
49
|
+
"author": "PostHog <engineering@posthog.com> (https://github.com/PostHog)",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/PostHog/posthog-js/tree/main/packages/react-native-plugin#readme",
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@react-native-community/cli": "20.0.0",
|
|
57
|
+
"@types/jest": "^29.5.14",
|
|
58
|
+
"@types/react": "^18.2.44",
|
|
59
|
+
"del-cli": "^5.1.0",
|
|
60
|
+
"jest": "29.7.0",
|
|
61
|
+
"react": "18.3.1",
|
|
62
|
+
"react-native": "0.75.3",
|
|
63
|
+
"react-native-builder-bob": "^0.30.2",
|
|
64
|
+
"typescript": "5.8.2"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"react": "*",
|
|
68
|
+
"react-native": "*"
|
|
69
|
+
},
|
|
70
|
+
"jest": {
|
|
71
|
+
"preset": "react-native",
|
|
72
|
+
"modulePathIgnorePatterns": [
|
|
73
|
+
"<rootDir>/lib/"
|
|
74
|
+
],
|
|
75
|
+
"testPathIgnorePatterns": [
|
|
76
|
+
"/node_modules/",
|
|
77
|
+
"<rootDir>/lib/"
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"react-native-builder-bob": {
|
|
81
|
+
"source": "src",
|
|
82
|
+
"output": "lib",
|
|
83
|
+
"targets": [
|
|
84
|
+
[
|
|
85
|
+
"commonjs",
|
|
86
|
+
{
|
|
87
|
+
"esm": true
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
"module",
|
|
92
|
+
{
|
|
93
|
+
"esm": true
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
"typescript",
|
|
98
|
+
{
|
|
99
|
+
"project": "tsconfig.build.json",
|
|
100
|
+
"esm": true
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"scripts": {
|
|
106
|
+
"clean": "del-cli android/build lib",
|
|
107
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
108
|
+
"lint:fix": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
109
|
+
"typecheck": "tsc",
|
|
110
|
+
"test:unit": "jest --passWithNoTests",
|
|
111
|
+
"test": "pnpm test:unit",
|
|
112
|
+
"build": "bob build",
|
|
113
|
+
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
|
+
|
|
6
|
+
# Single source of truth for the posthog-ios native dependency version.
|
|
7
|
+
# Used by both the SPM and CocoaPods resolution paths below; bump this
|
|
8
|
+
# line when picking up a new posthog-ios release.
|
|
9
|
+
posthog_ios_version = '3.58.1'
|
|
10
|
+
|
|
11
|
+
Pod::Spec.new do |s|
|
|
12
|
+
s.name = "posthog-react-native-plugin"
|
|
13
|
+
s.version = package["version"]
|
|
14
|
+
s.summary = package["description"]
|
|
15
|
+
s.homepage = package["homepage"]
|
|
16
|
+
s.license = package["license"]
|
|
17
|
+
s.authors = package["author"]
|
|
18
|
+
|
|
19
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
20
|
+
s.source = { :git => "https://github.com/PostHog/posthog-js.git", :tag => "@posthog/react-native-plugin@#{s.version}" }
|
|
21
|
+
|
|
22
|
+
s.source_files = "ios/**/*.{swift,h,hpp,m,mm,c,cpp}"
|
|
23
|
+
|
|
24
|
+
# Default: resolve posthog-ios via CocoaPods trunk.
|
|
25
|
+
# Opt-in: set `posthog.useSpm` to `"true"` in the consumer's
|
|
26
|
+
# `ios/Podfile.properties.json` to resolve posthog-ios via Swift Package
|
|
27
|
+
# Manager using the React Native `spm_dependency` helper (RN >= 0.75).
|
|
28
|
+
# The SPM path requires `use_frameworks! :linkage => :dynamic` in the Podfile.
|
|
29
|
+
podfile_properties_path = File.join(Pod::Config.instance.installation_root.to_s, 'Podfile.properties.json')
|
|
30
|
+
podfile_properties = File.exist?(podfile_properties_path) ? (JSON.parse(File.read(podfile_properties_path)) rescue {}) : {}
|
|
31
|
+
posthog_use_spm = podfile_properties['posthog.useSpm'].to_s == 'true'
|
|
32
|
+
|
|
33
|
+
if posthog_use_spm && respond_to?(:spm_dependency, true)
|
|
34
|
+
spm_dependency(s,
|
|
35
|
+
url: 'https://github.com/PostHog/posthog-ios.git',
|
|
36
|
+
requirement: { kind: 'upToNextMinorVersion', minimumVersion: posthog_ios_version },
|
|
37
|
+
products: ['PostHog']
|
|
38
|
+
)
|
|
39
|
+
else
|
|
40
|
+
s.dependency 'PostHog', "~> #{posthog_ios_version}"
|
|
41
|
+
end
|
|
42
|
+
s.ios.deployment_target = '13.0'
|
|
43
|
+
s.swift_versions = "5.3"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
47
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
48
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
49
|
+
install_modules_dependencies(s)
|
|
50
|
+
else
|
|
51
|
+
s.dependency "React-Core"
|
|
52
|
+
|
|
53
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
54
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
55
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
56
|
+
s.pod_target_xcconfig = {
|
|
57
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
58
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
59
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
60
|
+
}
|
|
61
|
+
s.dependency "React-Codegen"
|
|
62
|
+
s.dependency "RCT-Folly"
|
|
63
|
+
s.dependency "RCTRequired"
|
|
64
|
+
s.dependency "RCTTypeSafety"
|
|
65
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native'
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package '@posthog/react-native-plugin' 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 PosthogReactNativePlugin = NativeModules.PosthogReactNativePlugin
|
|
10
|
+
? NativeModules.PosthogReactNativePlugin
|
|
11
|
+
: new Proxy(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
get() {
|
|
15
|
+
throw new Error(LINKING_ERROR)
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
export type PostHogReactNativePluginMap = { [key: string]: any }
|
|
21
|
+
|
|
22
|
+
export interface PostHogReactNativePluginSessionReplayConfig {
|
|
23
|
+
enabled?: boolean
|
|
24
|
+
sdkReplayConfig?: PostHogReactNativePluginMap
|
|
25
|
+
decideReplayConfig?: PostHogReactNativePluginMap
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PostHogReactNativePluginErrorTrackingConfig {
|
|
29
|
+
nativeAutocapture?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PostHogReactNativePluginConfig {
|
|
33
|
+
sessionReplay?: PostHogReactNativePluginSessionReplayConfig
|
|
34
|
+
errorTracking?: PostHogReactNativePluginErrorTrackingConfig
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function setup(
|
|
38
|
+
sessionId: string,
|
|
39
|
+
sdkOptions: PostHogReactNativePluginMap,
|
|
40
|
+
pluginConfig: PostHogReactNativePluginConfig = {}
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
return PosthogReactNativePlugin.setup(sessionId, sdkOptions, pluginConfig)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function start(
|
|
46
|
+
sessionId: string,
|
|
47
|
+
sdkOptions: PostHogReactNativePluginMap,
|
|
48
|
+
sdkReplayConfig: PostHogReactNativePluginMap,
|
|
49
|
+
decideReplayConfig: PostHogReactNativePluginMap
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
return PosthogReactNativePlugin.start(sessionId, sdkOptions, sdkReplayConfig, decideReplayConfig)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function startSession(sessionId: string): Promise<void> {
|
|
55
|
+
return PosthogReactNativePlugin.startSession(sessionId)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function endSession(): Promise<void> {
|
|
59
|
+
return PosthogReactNativePlugin.endSession()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isEnabled(): Promise<boolean> {
|
|
63
|
+
return PosthogReactNativePlugin.isEnabled()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function identify(distinctId: string, anonymousId: string): Promise<void> {
|
|
67
|
+
return PosthogReactNativePlugin.identify(distinctId, anonymousId)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function startRecording(resumeCurrent: boolean): Promise<void> {
|
|
71
|
+
return PosthogReactNativePlugin.startRecording(resumeCurrent)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function stopRecording(): Promise<void> {
|
|
75
|
+
return PosthogReactNativePlugin.stopRecording()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface PostHogReactNativePluginModule {
|
|
79
|
+
setup: (
|
|
80
|
+
sessionId: string,
|
|
81
|
+
sdkOptions: PostHogReactNativePluginMap,
|
|
82
|
+
pluginConfig?: PostHogReactNativePluginConfig
|
|
83
|
+
) => Promise<void>
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Legacy session replay setup entrypoint. Prefer setup() for new native features.
|
|
87
|
+
*/
|
|
88
|
+
start: (
|
|
89
|
+
sessionId: string,
|
|
90
|
+
sdkOptions: PostHogReactNativePluginMap,
|
|
91
|
+
sdkReplayConfig: PostHogReactNativePluginMap,
|
|
92
|
+
decideReplayConfig: PostHogReactNativePluginMap
|
|
93
|
+
) => Promise<void>
|
|
94
|
+
|
|
95
|
+
startSession: (sessionId: string) => Promise<void>
|
|
96
|
+
|
|
97
|
+
endSession: () => Promise<void>
|
|
98
|
+
|
|
99
|
+
isEnabled: () => Promise<boolean>
|
|
100
|
+
|
|
101
|
+
identify: (distinctId: string, anonymousId: string) => Promise<void>
|
|
102
|
+
|
|
103
|
+
startRecording: (resumeCurrent: boolean) => Promise<void>
|
|
104
|
+
|
|
105
|
+
stopRecording: () => Promise<void>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const PostHogReactNativePlugin: PostHogReactNativePluginModule = {
|
|
109
|
+
setup,
|
|
110
|
+
start,
|
|
111
|
+
startSession,
|
|
112
|
+
endSession,
|
|
113
|
+
isEnabled,
|
|
114
|
+
identify,
|
|
115
|
+
startRecording,
|
|
116
|
+
stopRecording,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default PostHogReactNativePlugin
|