@posthog/react-native-plugin 2.1.1 → 2.2.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
CHANGED
|
@@ -327,12 +327,12 @@ SOFTWARE.
|
|
|
327
327
|
|
|
328
328
|
---
|
|
329
329
|
|
|
330
|
-
Some files in this codebase contain code from MCPCat/mcpcat-typescript-sdk.
|
|
330
|
+
Some files in this codebase contain code from agentcathq/agentcat-typescript-sdk (formerly MCPCat/mcpcat-typescript-sdk).
|
|
331
331
|
In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
|
|
332
332
|
|
|
333
333
|
MIT License
|
|
334
334
|
|
|
335
|
-
Copyright (c) 2025 MCPcat
|
|
335
|
+
Copyright (c) 2025 AgentCat, Inc. (formerly MCPcat)
|
|
336
336
|
|
|
337
337
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
338
338
|
of this software and associated documentation files (the "Software"), to deal
|
package/android/build.gradle
CHANGED
|
@@ -85,6 +85,6 @@ dependencies {
|
|
|
85
85
|
//noinspection GradleDynamicVersion
|
|
86
86
|
implementation "com.facebook.react:react-native:+"
|
|
87
87
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
88
|
-
implementation "com.posthog:posthog-android:3.
|
|
88
|
+
implementation "com.posthog:posthog-android:3.52.0"
|
|
89
89
|
}
|
|
90
90
|
|
package/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt
CHANGED
|
@@ -93,6 +93,13 @@ class PosthogReactNativePluginModule(
|
|
|
93
93
|
val theSdkVersion = getString(sdkOptions, "sdkVersion", "")
|
|
94
94
|
val theFlushAt = getInt(sdkOptions, "flushAt", DEFAULT_FLUSH_AT)
|
|
95
95
|
|
|
96
|
+
// Forward custom headers (e.g. Authorization for a reverse proxy) so the native SDK
|
|
97
|
+
// attaches them to the requests it sends directly (session replay, crash uploads).
|
|
98
|
+
val theRequestHeaders =
|
|
99
|
+
getMap(sdkOptions, "requestHeaders")?.toHashMap()
|
|
100
|
+
?.filterValues { it is String }
|
|
101
|
+
?.mapValues { it.value as String }
|
|
102
|
+
|
|
96
103
|
val config =
|
|
97
104
|
PostHogAndroidConfig(apiKey, host).apply {
|
|
98
105
|
debug = debugValue
|
|
@@ -100,6 +107,7 @@ class PosthogReactNativePluginModule(
|
|
|
100
107
|
captureApplicationLifecycleEvents = false
|
|
101
108
|
captureScreenViews = false
|
|
102
109
|
flushAt = theFlushAt
|
|
110
|
+
theRequestHeaders?.let { requestHeaders = it }
|
|
103
111
|
errorTrackingConfig.autoCapture = nativeErrorTrackingAutocapture
|
|
104
112
|
|
|
105
113
|
// Keep the native exception-steps buffer aligned with the JS layer (one logical buffer).
|
|
@@ -5,7 +5,18 @@ private func hedgeLog(_ message: String) {
|
|
|
5
5
|
print("[PostHog] \(message)")
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
#if !os(iOS)
|
|
9
|
+
// Session replay is part of posthog-ios's iOS-only surface, so recording is a no-op on macOS.
|
|
10
|
+
// Log once so a caller isn't left wondering why recording "started" but nothing arrives.
|
|
11
|
+
private var didLogSessionReplayUnsupported = false
|
|
12
|
+
private func logSessionReplayUnsupportedOnMacOS() {
|
|
13
|
+
guard !didLogSessionReplayUnsupported else { return }
|
|
14
|
+
didLogSessionReplayUnsupported = true
|
|
15
|
+
hedgeLog("Session replay is not supported on macOS")
|
|
16
|
+
}
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
// Deduplication works on Android (both architectures), iOS (old architecture only), and macOS.
|
|
9
20
|
// On the iOS new architecture, fatal JS exception events surface as a generic SIGABRT
|
|
10
21
|
// crash event with no JS-error text in any field, so they currently cannot be filtered.
|
|
11
22
|
private let fatalJsErrorMarkers = ["Unhandled JS Exception", "ExceptionsManager.reportException", "facebook::jsi::JSError"]
|
|
@@ -126,49 +137,53 @@ class PosthogReactNativePlugin: NSObject {
|
|
|
126
137
|
isReactNativeFatalJsError(event) ? nil : event
|
|
127
138
|
}
|
|
128
139
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
// Surveys and session replay are iOS-only in posthog-ios, so the APIs below
|
|
141
|
+
// don't exist on macOS. macOS gets error tracking only.
|
|
142
|
+
#if os(iOS)
|
|
143
|
+
if #available(iOS 15.0, *) {
|
|
144
|
+
config.surveys = false
|
|
145
|
+
}
|
|
132
146
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
// Always apply the session replay configuration so that recording started later
|
|
148
|
+
// (e.g. startRecording or a linked feature flag) uses the right mode and masking;
|
|
149
|
+
// sessionReplayEnabled only controls whether recording starts at setup.
|
|
150
|
+
config.sessionReplay = sessionReplayEnabled
|
|
151
|
+
config.sessionReplayConfig.screenshotMode = true
|
|
138
152
|
|
|
139
|
-
|
|
140
|
-
|
|
153
|
+
let maskAllTextInputs = sdkReplayConfig["maskAllTextInputs"] as? Bool ?? true
|
|
154
|
+
config.sessionReplayConfig.maskAllTextInputs = maskAllTextInputs
|
|
141
155
|
|
|
142
|
-
|
|
143
|
-
|
|
156
|
+
let maskAllImages = sdkReplayConfig["maskAllImages"] as? Bool ?? true
|
|
157
|
+
config.sessionReplayConfig.maskAllImages = maskAllImages
|
|
144
158
|
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
let maskAllSandboxedViews = sdkReplayConfig["maskAllSandboxedViews"] as? Bool ?? true
|
|
160
|
+
config.sessionReplayConfig.maskAllSandboxedViews = maskAllSandboxedViews
|
|
147
161
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
// read throttleDelayMs and use iOSdebouncerDelayMs as a fallback for back compatibility
|
|
163
|
+
let throttleDelayMs =
|
|
164
|
+
(sdkReplayConfig["throttleDelayMs"] as? Int)
|
|
165
|
+
?? (sdkReplayConfig["iOSdebouncerDelayMs"] as? Int)
|
|
166
|
+
?? 1000
|
|
153
167
|
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
let timeInterval: TimeInterval = Double(throttleDelayMs) / 1000.0
|
|
169
|
+
config.sessionReplayConfig.throttleDelay = timeInterval
|
|
156
170
|
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
let captureNetworkTelemetry = sdkReplayConfig["captureNetworkTelemetry"] as? Bool ?? true
|
|
172
|
+
config.sessionReplayConfig.captureNetworkTelemetry = captureNetworkTelemetry
|
|
159
173
|
|
|
160
|
-
|
|
161
|
-
|
|
174
|
+
let captureLog = sdkReplayConfig["captureLog"] as? Bool ?? true
|
|
175
|
+
config.sessionReplayConfig.captureLogs = captureLog
|
|
162
176
|
|
|
163
|
-
|
|
177
|
+
config.sessionReplayConfig.sampleRate = sdkReplayConfig["sampleRate"] as? NSNumber
|
|
164
178
|
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
let screenshotModeBackgroundCapture = sdkReplayConfig["screenshotModeBackgroundCapture"] as? Bool ?? false
|
|
180
|
+
config.sessionReplayConfig.screenshotModeBackgroundCapture = screenshotModeBackgroundCapture
|
|
167
181
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
182
|
+
let endpoint = decideReplayConfig["endpoint"] as? String ?? ""
|
|
183
|
+
if !endpoint.isEmpty {
|
|
184
|
+
config.snapshotEndpoint = endpoint
|
|
185
|
+
}
|
|
186
|
+
#endif
|
|
172
187
|
|
|
173
188
|
let distinctId = sdkOptions["distinctId"] as? String ?? ""
|
|
174
189
|
let anonymousId = sdkOptions["anonymousId"] as? String ?? ""
|
|
@@ -178,6 +193,13 @@ class PosthogReactNativePlugin: NSObject {
|
|
|
178
193
|
let flushAt = sdkOptions["flushAt"] as? Int ?? 20
|
|
179
194
|
config.flushAt = flushAt
|
|
180
195
|
|
|
196
|
+
// Forward custom headers (e.g. Authorization for a reverse proxy) so the native SDK
|
|
197
|
+
// attaches them to the requests it sends directly (session replay, crash uploads).
|
|
198
|
+
// Keep only string values so a stray non-string doesn't drop every header (matches Android).
|
|
199
|
+
if let rawHeaders = sdkOptions["requestHeaders"] as? [String: Any] {
|
|
200
|
+
config.requestHeaders = rawHeaders.compactMapValues { $0 as? String }
|
|
201
|
+
}
|
|
202
|
+
|
|
181
203
|
if !sdkVersion.isEmpty {
|
|
182
204
|
postHogSdkName = "posthog-react-native"
|
|
183
205
|
postHogVersion = sdkVersion
|
|
@@ -214,8 +236,12 @@ class PosthogReactNativePlugin: NSObject {
|
|
|
214
236
|
|
|
215
237
|
@objc(isEnabled:withRejecter:)
|
|
216
238
|
func isEnabled(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
|
|
217
|
-
|
|
218
|
-
|
|
239
|
+
#if os(iOS)
|
|
240
|
+
resolve(PostHogSDK.shared.isSessionReplayActive())
|
|
241
|
+
#else
|
|
242
|
+
// Session replay is unsupported on macOS.
|
|
243
|
+
resolve(false)
|
|
244
|
+
#endif
|
|
219
245
|
}
|
|
220
246
|
|
|
221
247
|
@objc(endSession:withRejecter:)
|
|
@@ -254,13 +280,21 @@ class PosthogReactNativePlugin: NSObject {
|
|
|
254
280
|
func startRecording(
|
|
255
281
|
resumeCurrent: Bool, resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock
|
|
256
282
|
) {
|
|
257
|
-
|
|
283
|
+
#if os(iOS)
|
|
284
|
+
PostHogSDK.shared.startSessionRecording(resumeCurrent: resumeCurrent)
|
|
285
|
+
#else
|
|
286
|
+
logSessionReplayUnsupportedOnMacOS()
|
|
287
|
+
#endif
|
|
258
288
|
resolve(nil)
|
|
259
289
|
}
|
|
260
290
|
|
|
261
291
|
@objc(stopRecording:withRejecter:)
|
|
262
292
|
func stopRecording(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
|
|
263
|
-
|
|
293
|
+
#if os(iOS)
|
|
294
|
+
PostHogSDK.shared.stopSessionRecording()
|
|
295
|
+
#else
|
|
296
|
+
logSessionReplayUnsupportedOnMacOS()
|
|
297
|
+
#endif
|
|
264
298
|
resolve(nil)
|
|
265
299
|
}
|
|
266
300
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/react-native-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "PostHog React Native plugin for iOS and Android integrations",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"keywords": [
|
|
40
40
|
"react-native",
|
|
41
41
|
"ios",
|
|
42
|
-
"android"
|
|
42
|
+
"android",
|
|
43
|
+
"macos"
|
|
43
44
|
],
|
|
44
45
|
"repository": {
|
|
45
46
|
"type": "git",
|
|
@@ -6,7 +6,7 @@ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1
|
|
|
6
6
|
# Single source of truth for the posthog-ios native dependency version.
|
|
7
7
|
# Used by both the SPM and CocoaPods resolution paths below; bump this
|
|
8
8
|
# line when picking up a new posthog-ios release.
|
|
9
|
-
posthog_ios_version = '3.
|
|
9
|
+
posthog_ios_version = '3.63.0'
|
|
10
10
|
|
|
11
11
|
Pod::Spec.new do |s|
|
|
12
12
|
s.name = "posthog-react-native-plugin"
|
|
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.license = package["license"]
|
|
17
17
|
s.authors = package["author"]
|
|
18
18
|
|
|
19
|
-
s.platforms = { :ios => min_ios_version_supported }
|
|
19
|
+
s.platforms = { :ios => min_ios_version_supported, :osx => '10.15' }
|
|
20
20
|
s.source = { :git => "https://github.com/PostHog/posthog-js.git", :tag => "@posthog/react-native-plugin@#{s.version}" }
|
|
21
21
|
|
|
22
22
|
s.source_files = "ios/**/*.{swift,h,hpp,m,mm,c,cpp}"
|
|
@@ -40,6 +40,7 @@ Pod::Spec.new do |s|
|
|
|
40
40
|
s.dependency 'PostHog', "~> #{posthog_ios_version}"
|
|
41
41
|
end
|
|
42
42
|
s.ios.deployment_target = '13.0'
|
|
43
|
+
s.osx.deployment_target = '10.15'
|
|
43
44
|
s.swift_versions = "5.3"
|
|
44
45
|
|
|
45
46
|
|