@posthog/react-native-plugin 2.12.8 → 2.13.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/android/build.gradle
CHANGED
|
@@ -91,7 +91,7 @@ dependencies {
|
|
|
91
91
|
//noinspection GradleDynamicVersion
|
|
92
92
|
implementation "com.facebook.react:react-native:+"
|
|
93
93
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
94
|
-
implementation "com.posthog:posthog-android:3.
|
|
94
|
+
implementation "com.posthog:posthog-android:3.74.2"
|
|
95
95
|
|
|
96
96
|
testImplementation "junit:junit:4.13.2"
|
|
97
97
|
testImplementation "org.json:json:20250517"
|
package/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt
CHANGED
|
@@ -460,7 +460,8 @@ class PosthogReactNativePluginModule(
|
|
|
460
460
|
// capture() returns silently when the SDK was never set up. JS gives up its own copy of
|
|
461
461
|
// the event before calling this, so a false success would lose the crash without a
|
|
462
462
|
// trace; report it instead.
|
|
463
|
-
|
|
463
|
+
val config = PostHog.getConfig<PostHogConfig>()
|
|
464
|
+
if (config == null) {
|
|
464
465
|
promise.reject(FATAL_CAPTURE_ERROR_CODE, "captureFatalException: the native SDK is not set up")
|
|
465
466
|
return
|
|
466
467
|
}
|
|
@@ -472,7 +473,12 @@ class PosthogReactNativePluginModule(
|
|
|
472
473
|
event = "\$exception",
|
|
473
474
|
distinctId = distinctId.takeIf { it.isNotEmpty() },
|
|
474
475
|
properties = nativeProperties,
|
|
475
|
-
timestamp =
|
|
476
|
+
timestamp =
|
|
477
|
+
toSdkClock(
|
|
478
|
+
timestamp = parsedTimestamp,
|
|
479
|
+
deviceNowMs = System.currentTimeMillis(),
|
|
480
|
+
sdkNowMs = config.dateProvider.currentTimeMillis(),
|
|
481
|
+
),
|
|
476
482
|
)
|
|
477
483
|
}
|
|
478
484
|
promise.resolve(null)
|
|
@@ -853,6 +859,18 @@ private fun javascriptException(properties: Map<String, Any>?): Map<*, *>? {
|
|
|
853
859
|
}
|
|
854
860
|
}
|
|
855
861
|
|
|
862
|
+
/**
|
|
863
|
+
* Moves [timestamp], which JS read from the device clock, onto the native SDK's clock. On Android 13
|
|
864
|
+
* and later the SDK stamps each request's send time with network time, and PostHog corrects event
|
|
865
|
+
* timestamps by the gap between that send time and when it receives the request, so a device-clock
|
|
866
|
+
* timestamp would be shifted by however far the device clock is from network time.
|
|
867
|
+
*/
|
|
868
|
+
internal fun toSdkClock(
|
|
869
|
+
timestamp: Date,
|
|
870
|
+
deviceNowMs: Long,
|
|
871
|
+
sdkNowMs: Long,
|
|
872
|
+
): Date = Date(timestamp.time + (sdkNowMs - deviceNowMs))
|
|
873
|
+
|
|
856
874
|
// The JS layer sends an ISO-8601 UTC timestamp (`Date#toISOString`). Parse it explicitly
|
|
857
875
|
// rather than trusting a locale-dependent default, and treat anything unparseable as a
|
|
858
876
|
// caller error: silently substituting "now" would attribute the crash to the wrong instant.
|
|
@@ -906,10 +924,10 @@ internal fun applyScreenshotConfig(
|
|
|
906
924
|
map: ReadableMap?,
|
|
907
925
|
config: PostHogSessionReplayConfig,
|
|
908
926
|
) {
|
|
909
|
-
getDoubleOrNull(map, "screenshotScale")?.let { scale ->
|
|
910
|
-
// Keep
|
|
927
|
+
getDoubleOrNull(map, "screenshotScale")?.takeIf { it.isFinite() }?.let { scale ->
|
|
928
|
+
// Keep values within Float range; the native setter clamps to its supported range.
|
|
911
929
|
val floatMax = Float.MAX_VALUE.toDouble()
|
|
912
|
-
config.screenshotScale =
|
|
930
|
+
config.screenshotScale = scale.coerceIn(-floatMax, floatMax).toFloat()
|
|
913
931
|
}
|
|
914
932
|
getDoubleOrNull(map, "screenshotCompressionQuality")?.takeIf { it.isFinite() }?.let { quality ->
|
|
915
933
|
config.screenshotCompressionQuality = quality.toInt()
|