@plushanalytics/react-native-session-replay 1.2.5
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 +21 -0
- package/README.md +9 -0
- package/android/build.gradle +100 -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/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayModule.kt +204 -0
- package/android/src/main/java/com/posthogreactnativesessionreplay/PosthogReactNativeSessionReplayPackage.kt +13 -0
- package/ios/PosthogReactNativeSessionReplay-Bridging-Header.h +2 -0
- package/ios/PosthogReactNativeSessionReplay.mm +32 -0
- package/ios/PosthogReactNativeSessionReplay.swift +158 -0
- package/lib/commonjs/index.js +45 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +36 -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 +29 -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 +29 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +165 -0
- package/posthog-react-native-session-replay.podspec +47 -0
- package/src/index.tsx +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 PostHog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["PosthogReactNativeSessionReplay_kotlinVersion"]
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def reactNativeArchitectures() {
|
|
18
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
19
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def isNewArchitectureEnabled() {
|
|
23
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
apply plugin: "com.android.library"
|
|
27
|
+
apply plugin: "kotlin-android"
|
|
28
|
+
|
|
29
|
+
if (isNewArchitectureEnabled()) {
|
|
30
|
+
apply plugin: "com.facebook.react"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def getExtOrDefault(name) {
|
|
34
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["PosthogReactNativeSessionReplay_" + name]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def getExtOrIntegerDefault(name) {
|
|
38
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["PosthogReactNativeSessionReplay_" + name]).toInteger()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
def supportsNamespace() {
|
|
42
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
43
|
+
def major = parsed[0].toInteger()
|
|
44
|
+
def minor = parsed[1].toInteger()
|
|
45
|
+
|
|
46
|
+
// Namespace support was added in 7.3.0
|
|
47
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
android {
|
|
51
|
+
if (supportsNamespace()) {
|
|
52
|
+
namespace "com.posthogreactnativesessionreplay"
|
|
53
|
+
|
|
54
|
+
sourceSets {
|
|
55
|
+
main {
|
|
56
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
62
|
+
|
|
63
|
+
defaultConfig {
|
|
64
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
65
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
buildTypes {
|
|
70
|
+
release {
|
|
71
|
+
minifyEnabled false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
lintOptions {
|
|
76
|
+
disable "GradleCompatible"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
compileOptions {
|
|
80
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
81
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
repositories {
|
|
86
|
+
mavenCentral()
|
|
87
|
+
google()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
91
|
+
|
|
92
|
+
dependencies {
|
|
93
|
+
// For < 0.71, this will be from the local maven repo
|
|
94
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
95
|
+
//noinspection GradleDynamicVersion
|
|
96
|
+
implementation "com.facebook.react:react-native:+"
|
|
97
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
98
|
+
implementation "com.posthog:posthog-android:3.21.3"
|
|
99
|
+
}
|
|
100
|
+
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
package com.posthogreactnativesessionreplay
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
10
|
+
import com.posthog.PostHog
|
|
11
|
+
import com.posthog.PostHogConfig
|
|
12
|
+
import com.posthog.android.PostHogAndroid
|
|
13
|
+
import com.posthog.android.PostHogAndroidConfig
|
|
14
|
+
import com.posthog.internal.PostHogPreferences
|
|
15
|
+
import com.posthog.internal.PostHogPreferences.Companion.ANONYMOUS_ID
|
|
16
|
+
import com.posthog.internal.PostHogPreferences.Companion.DISTINCT_ID
|
|
17
|
+
import com.posthog.internal.PostHogSessionManager
|
|
18
|
+
import java.util.UUID
|
|
19
|
+
|
|
20
|
+
class PosthogReactNativeSessionReplayModule(
|
|
21
|
+
reactContext: ReactApplicationContext,
|
|
22
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
23
|
+
override fun getName(): String = NAME
|
|
24
|
+
|
|
25
|
+
@ReactMethod
|
|
26
|
+
fun start(
|
|
27
|
+
sessionId: String,
|
|
28
|
+
sdkOptions: ReadableMap,
|
|
29
|
+
sdkReplayConfig: ReadableMap,
|
|
30
|
+
decideReplayConfig: ReadableMap,
|
|
31
|
+
promise: Promise,
|
|
32
|
+
) {
|
|
33
|
+
val initRunnable =
|
|
34
|
+
Runnable {
|
|
35
|
+
try {
|
|
36
|
+
val uuid = UUID.fromString(sessionId)
|
|
37
|
+
PostHogSessionManager.setSessionId(uuid)
|
|
38
|
+
|
|
39
|
+
val context = this.reactApplicationContext
|
|
40
|
+
val apiKey = runCatching { sdkOptions.getString("apiKey") }.getOrNull() ?: ""
|
|
41
|
+
val host = runCatching { sdkOptions.getString("host") }.getOrNull() ?: PostHogConfig.DEFAULT_HOST
|
|
42
|
+
val debugValue = runCatching { sdkOptions.getBoolean("debug") }.getOrNull() ?: false
|
|
43
|
+
|
|
44
|
+
val maskAllTextInputs = runCatching { sdkReplayConfig.getBoolean("maskAllTextInputs") }.getOrNull() ?: DEFAULT_MASK_ALL_TEXT_INPUTS
|
|
45
|
+
val maskAllImages = runCatching { sdkReplayConfig.getBoolean("maskAllImages") }.getOrNull() ?: DEFAULT_MASK_ALL_IMAGES
|
|
46
|
+
val captureLog = runCatching { sdkReplayConfig.getBoolean("captureLog") }.getOrNull() ?: DEFAULT_CAPTURE_LOG
|
|
47
|
+
|
|
48
|
+
// read throttleDelayMs and use androidDebouncerDelayMs as a fallback for back compatibility
|
|
49
|
+
val throttleDelayMs =
|
|
50
|
+
if (sdkReplayConfig.hasKey("throttleDelayMs")) {
|
|
51
|
+
sdkReplayConfig.getInt("throttleDelayMs")
|
|
52
|
+
} else if (sdkReplayConfig.hasKey("androidDebouncerDelayMs")) {
|
|
53
|
+
sdkReplayConfig.getInt("androidDebouncerDelayMs")
|
|
54
|
+
} else {
|
|
55
|
+
DEFAULT_THROTTLE_DELAY_MS
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
val endpoint = decideReplayConfig.getString("endpoint")
|
|
59
|
+
|
|
60
|
+
val distinctId =
|
|
61
|
+
try {
|
|
62
|
+
sdkOptions.getString("distinctId") ?: ""
|
|
63
|
+
} catch (e: Throwable) {
|
|
64
|
+
logError("parse distinctId", e)
|
|
65
|
+
""
|
|
66
|
+
}
|
|
67
|
+
val anonymousId =
|
|
68
|
+
try {
|
|
69
|
+
sdkOptions.getString("anonymousId") ?: ""
|
|
70
|
+
} catch (e: Throwable) {
|
|
71
|
+
logError("parse anonymousId", e)
|
|
72
|
+
""
|
|
73
|
+
}
|
|
74
|
+
val theSdkVersion = runCatching { sdkOptions.getString("sdkVersion") }.getOrNull()
|
|
75
|
+
|
|
76
|
+
val theFlushAt = runCatching { sdkOptions.getInt("flushAt") }.getOrNull() ?: DEFAULT_FLUSH_AT
|
|
77
|
+
|
|
78
|
+
val config =
|
|
79
|
+
PostHogAndroidConfig(apiKey, host).apply {
|
|
80
|
+
debug = debugValue
|
|
81
|
+
captureDeepLinks = false
|
|
82
|
+
captureApplicationLifecycleEvents = false
|
|
83
|
+
captureScreenViews = false
|
|
84
|
+
flushAt = theFlushAt
|
|
85
|
+
sessionReplay = true
|
|
86
|
+
sessionReplayConfig.screenshot = true
|
|
87
|
+
sessionReplayConfig.captureLogcat = captureLog
|
|
88
|
+
sessionReplayConfig.throttleDelayMs = throttleDelayMs.toLong()
|
|
89
|
+
sessionReplayConfig.maskAllImages = maskAllImages
|
|
90
|
+
sessionReplayConfig.maskAllTextInputs = maskAllTextInputs
|
|
91
|
+
|
|
92
|
+
if (!endpoint.isNullOrEmpty()) {
|
|
93
|
+
snapshotEndpoint = endpoint
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!theSdkVersion.isNullOrEmpty()) {
|
|
97
|
+
sdkName = "posthog-react-native"
|
|
98
|
+
sdkVersion = theSdkVersion
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
PostHogAndroid.setup(context, config)
|
|
102
|
+
|
|
103
|
+
setIdentify(config.cachePreferences, distinctId, anonymousId)
|
|
104
|
+
} catch (e: Throwable) {
|
|
105
|
+
logError("start", e)
|
|
106
|
+
} finally {
|
|
107
|
+
promise.resolve(null)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// forces the SDK to be initialized on the main thread
|
|
112
|
+
if (UiThreadUtil.isOnUiThread()) {
|
|
113
|
+
initRunnable.run()
|
|
114
|
+
} else {
|
|
115
|
+
UiThreadUtil.runOnUiThread(initRunnable)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@ReactMethod
|
|
120
|
+
fun startSession(
|
|
121
|
+
sessionId: String,
|
|
122
|
+
promise: Promise,
|
|
123
|
+
) {
|
|
124
|
+
try {
|
|
125
|
+
val uuid = UUID.fromString(sessionId)
|
|
126
|
+
PostHogSessionManager.setSessionId(uuid)
|
|
127
|
+
PostHog.startSession()
|
|
128
|
+
} catch (e: Throwable) {
|
|
129
|
+
logError("startSession", e)
|
|
130
|
+
} finally {
|
|
131
|
+
promise.resolve(null)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@ReactMethod
|
|
136
|
+
fun isEnabled(promise: Promise) {
|
|
137
|
+
try {
|
|
138
|
+
promise.resolve(PostHog.isSessionReplayActive())
|
|
139
|
+
} catch (e: Throwable) {
|
|
140
|
+
logError("isEnabled", e)
|
|
141
|
+
promise.resolve(false)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@ReactMethod
|
|
146
|
+
fun endSession(promise: Promise) {
|
|
147
|
+
try {
|
|
148
|
+
PostHog.endSession()
|
|
149
|
+
} catch (e: Throwable) {
|
|
150
|
+
logError("endSession", e)
|
|
151
|
+
} finally {
|
|
152
|
+
promise.resolve(null)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@ReactMethod
|
|
157
|
+
fun identify(
|
|
158
|
+
distinctId: String,
|
|
159
|
+
anonymousId: String,
|
|
160
|
+
promise: Promise,
|
|
161
|
+
) {
|
|
162
|
+
try {
|
|
163
|
+
setIdentify(PostHog.getConfig<PostHogConfig>()?.cachePreferences, distinctId, anonymousId)
|
|
164
|
+
} catch (e: Throwable) {
|
|
165
|
+
logError("identify", e)
|
|
166
|
+
} finally {
|
|
167
|
+
promise.resolve(null)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private fun setIdentify(
|
|
172
|
+
cachePreferences: PostHogPreferences?,
|
|
173
|
+
distinctId: String,
|
|
174
|
+
anonymousId: String,
|
|
175
|
+
) {
|
|
176
|
+
cachePreferences?.let { preferences ->
|
|
177
|
+
if (anonymousId.isNotEmpty()) {
|
|
178
|
+
preferences.setValue(ANONYMOUS_ID, anonymousId)
|
|
179
|
+
}
|
|
180
|
+
if (distinctId.isNotEmpty()) {
|
|
181
|
+
preferences.setValue(DISTINCT_ID, distinctId)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private fun logError(
|
|
187
|
+
method: String,
|
|
188
|
+
error: Throwable,
|
|
189
|
+
) {
|
|
190
|
+
Log.println(Log.ERROR, POSTHOG_TAG, "Method $method, error: $error")
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
companion object {
|
|
194
|
+
const val NAME = "PosthogReactNativeSessionReplay"
|
|
195
|
+
const val POSTHOG_TAG = "PostHog"
|
|
196
|
+
|
|
197
|
+
// Default session replay configuration values
|
|
198
|
+
const val DEFAULT_MASK_ALL_TEXT_INPUTS = true
|
|
199
|
+
const val DEFAULT_MASK_ALL_IMAGES = true
|
|
200
|
+
const val DEFAULT_CAPTURE_LOG = true
|
|
201
|
+
const val DEFAULT_FLUSH_AT = 20
|
|
202
|
+
const val DEFAULT_THROTTLE_DELAY_MS = 1000
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package com.posthogreactnativesessionreplay
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
class PosthogReactNativeSessionReplayPackage : ReactPackage {
|
|
9
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
|
|
10
|
+
listOf(PosthogReactNativeSessionReplayModule(reactContext))
|
|
11
|
+
|
|
12
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> = emptyList()
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(PosthogReactNativeSessionReplay, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(start:(NSString)sessionId
|
|
6
|
+
withSdkOptions:(NSDictionary)sdkOptions
|
|
7
|
+
withSdkReplayConfig:(NSDictionary)sdkReplayConfig
|
|
8
|
+
withDecideReplayConfig:(NSDictionary)decideReplayConfig
|
|
9
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
10
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
11
|
+
|
|
12
|
+
RCT_EXTERN_METHOD(startSession:(NSString)sessionId
|
|
13
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
14
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
15
|
+
|
|
16
|
+
RCT_EXTERN_METHOD(isEnabled:(RCTPromiseResolveBlock)resolve
|
|
17
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
18
|
+
|
|
19
|
+
RCT_EXTERN_METHOD(endSession:(RCTPromiseResolveBlock)resolve
|
|
20
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
|
|
22
|
+
RCT_EXTERN_METHOD(identify:(NSString)distinctId
|
|
23
|
+
withAnonymousId:(NSString)anonymousId
|
|
24
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
25
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
26
|
+
|
|
27
|
+
+ (BOOL)requiresMainQueueSetup
|
|
28
|
+
{
|
|
29
|
+
return NO;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import PostHog
|
|
2
|
+
|
|
3
|
+
// Meant for internally logging PostHog related things
|
|
4
|
+
private func hedgeLog(_ message: String) {
|
|
5
|
+
print("[PostHog] \(message)")
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
@objc(PosthogReactNativeSessionReplay)
|
|
9
|
+
class PosthogReactNativeSessionReplay: NSObject {
|
|
10
|
+
private var config: PostHogConfig?
|
|
11
|
+
|
|
12
|
+
@objc(start:withSdkOptions:withSdkReplayConfig:withDecideReplayConfig:withResolver:withRejecter:)
|
|
13
|
+
func start(
|
|
14
|
+
sessionId: String, sdkOptions: [String: Any], sdkReplayConfig: [String: Any],
|
|
15
|
+
decideReplayConfig: [String: Any], resolve: RCTPromiseResolveBlock,
|
|
16
|
+
reject _: RCTPromiseRejectBlock
|
|
17
|
+
) {
|
|
18
|
+
// we've seen cases where distinctId and anonymousId are not strings, so we need to check and convert them
|
|
19
|
+
guard let sessionIdStr = sessionId as? String else {
|
|
20
|
+
hedgeLog("Invalid sessionId provided: \(sessionId). Expected a string.")
|
|
21
|
+
resolve(nil)
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let apiKey = sdkOptions["apiKey"] as? String ?? ""
|
|
26
|
+
let host = sdkOptions["host"] as? String ?? PostHogConfig.defaultHost
|
|
27
|
+
let debug = sdkOptions["debug"] as? Bool ?? false
|
|
28
|
+
|
|
29
|
+
PostHogSessionManager.shared.setSessionId(sessionIdStr)
|
|
30
|
+
|
|
31
|
+
let config = PostHogConfig(apiKey: apiKey, host: host)
|
|
32
|
+
config.sessionReplay = true
|
|
33
|
+
config.captureApplicationLifecycleEvents = false
|
|
34
|
+
config.captureScreenViews = false
|
|
35
|
+
config.debug = debug
|
|
36
|
+
config.sessionReplayConfig.screenshotMode = true
|
|
37
|
+
|
|
38
|
+
if #available(iOS 15.0, *) {
|
|
39
|
+
config.surveys = false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let maskAllTextInputs = sdkReplayConfig["maskAllTextInputs"] as? Bool ?? true
|
|
43
|
+
config.sessionReplayConfig.maskAllTextInputs = maskAllTextInputs
|
|
44
|
+
|
|
45
|
+
let maskAllImages = sdkReplayConfig["maskAllImages"] as? Bool ?? true
|
|
46
|
+
config.sessionReplayConfig.maskAllImages = maskAllImages
|
|
47
|
+
|
|
48
|
+
let maskAllSandboxedViews = sdkReplayConfig["maskAllSandboxedViews"] as? Bool ?? true
|
|
49
|
+
config.sessionReplayConfig.maskAllSandboxedViews = maskAllSandboxedViews
|
|
50
|
+
|
|
51
|
+
// read throttleDelayMs and use iOSdebouncerDelayMs as a fallback for back compatibility
|
|
52
|
+
let throttleDelayMs =
|
|
53
|
+
(sdkReplayConfig["throttleDelayMs"] as? Int)
|
|
54
|
+
?? (sdkReplayConfig["iOSdebouncerDelayMs"] as? Int)
|
|
55
|
+
?? 1000
|
|
56
|
+
|
|
57
|
+
let timeInterval: TimeInterval = Double(throttleDelayMs) / 1000.0
|
|
58
|
+
config.sessionReplayConfig.throttleDelay = timeInterval
|
|
59
|
+
|
|
60
|
+
let captureNetworkTelemetry = sdkReplayConfig["captureNetworkTelemetry"] as? Bool ?? true
|
|
61
|
+
config.sessionReplayConfig.captureNetworkTelemetry = captureNetworkTelemetry
|
|
62
|
+
|
|
63
|
+
let endpoint = decideReplayConfig["endpoint"] as? String ?? ""
|
|
64
|
+
if !endpoint.isEmpty {
|
|
65
|
+
config.snapshotEndpoint = endpoint
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let distinctId = sdkOptions["distinctId"] as? String ?? ""
|
|
69
|
+
let anonymousId = sdkOptions["anonymousId"] as? String ?? ""
|
|
70
|
+
|
|
71
|
+
let sdkVersion = sdkOptions["sdkVersion"] as? String ?? ""
|
|
72
|
+
|
|
73
|
+
let flushAt = sdkOptions["flushAt"] as? Int ?? 20
|
|
74
|
+
config.flushAt = flushAt
|
|
75
|
+
|
|
76
|
+
if !sdkVersion.isEmpty {
|
|
77
|
+
postHogSdkName = "posthog-react-native"
|
|
78
|
+
postHogVersion = sdkVersion
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
PostHogSDK.shared.setup(config)
|
|
82
|
+
|
|
83
|
+
self.config = config
|
|
84
|
+
|
|
85
|
+
guard let storageManager = self.config?.storageManager else {
|
|
86
|
+
hedgeLog("Storage manager is not available in the config.")
|
|
87
|
+
resolve(nil)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setIdentify(storageManager, distinctId: distinctId, anonymousId: anonymousId)
|
|
92
|
+
|
|
93
|
+
resolve(nil)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@objc(startSession:withResolver:withRejecter:)
|
|
97
|
+
func startSession(
|
|
98
|
+
sessionId: String, resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock
|
|
99
|
+
) {
|
|
100
|
+
// we've seen cases where distinctId and anonymousId are not strings, so we need to check and convert them
|
|
101
|
+
guard let sessionIdStr = sessionId as? String else {
|
|
102
|
+
hedgeLog("Invalid sessionId provided: \(sessionId). Expected a string.")
|
|
103
|
+
resolve(nil)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
PostHogSessionManager.shared.setSessionId(sessionIdStr)
|
|
107
|
+
PostHogSDK.shared.startSession()
|
|
108
|
+
resolve(nil)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@objc(isEnabled:withRejecter:)
|
|
112
|
+
func isEnabled(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
|
|
113
|
+
let isEnabled = PostHogSDK.shared.isSessionReplayActive()
|
|
114
|
+
resolve(isEnabled)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@objc(endSession:withRejecter:)
|
|
118
|
+
func endSession(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
|
|
119
|
+
PostHogSDK.shared.endSession()
|
|
120
|
+
resolve(nil)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@objc(identify:withAnonymousId:withResolver:withRejecter:)
|
|
124
|
+
func identify(
|
|
125
|
+
distinctId: String, anonymousId: String, resolve: RCTPromiseResolveBlock,
|
|
126
|
+
reject _: RCTPromiseRejectBlock
|
|
127
|
+
) {
|
|
128
|
+
// we've seen cases where distinctId and anonymousId are not strings, so we need to check and convert them
|
|
129
|
+
guard let distinctIdStr = distinctId as? String,
|
|
130
|
+
let anonymousIdStr = anonymousId as? String
|
|
131
|
+
else {
|
|
132
|
+
hedgeLog(
|
|
133
|
+
"Invalid distinctId: \(distinctId) or anonymousId: \(anonymousId) provided. Expected strings."
|
|
134
|
+
)
|
|
135
|
+
resolve(nil)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
guard let storageManager = config?.storageManager else {
|
|
139
|
+
hedgeLog("Storage manager is not available in the config.")
|
|
140
|
+
resolve(nil)
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
setIdentify(storageManager, distinctId: distinctIdStr, anonymousId: anonymousIdStr)
|
|
144
|
+
|
|
145
|
+
resolve(nil)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private func setIdentify(
|
|
149
|
+
_ storageManager: PostHogStorageManager, distinctId: String, anonymousId: String
|
|
150
|
+
) {
|
|
151
|
+
if !anonymousId.isEmpty {
|
|
152
|
+
storageManager.setAnonymousId(anonymousId)
|
|
153
|
+
}
|
|
154
|
+
if !distinctId.isEmpty {
|
|
155
|
+
storageManager.setDistinctId(distinctId)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.endSession = endSession;
|
|
8
|
+
exports.identify = identify;
|
|
9
|
+
exports.isEnabled = isEnabled;
|
|
10
|
+
exports.start = start;
|
|
11
|
+
exports.startSession = startSession;
|
|
12
|
+
var _reactNative = require("react-native");
|
|
13
|
+
const LINKING_ERROR = `The package '@plushanalytics/react-native-session-replay' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
14
|
+
ios: "- You have run 'pod install'\n",
|
|
15
|
+
default: ''
|
|
16
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
17
|
+
const PosthogReactNativeSessionReplay = _reactNative.NativeModules.PosthogReactNativeSessionReplay ? _reactNative.NativeModules.PosthogReactNativeSessionReplay : new Proxy({}, {
|
|
18
|
+
get() {
|
|
19
|
+
throw new Error(LINKING_ERROR);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
function start(sessionId, sdkOptions, sdkReplayConfig, decideReplayConfig) {
|
|
23
|
+
return PosthogReactNativeSessionReplay.start(sessionId, sdkOptions, sdkReplayConfig, decideReplayConfig);
|
|
24
|
+
}
|
|
25
|
+
function startSession(sessionId) {
|
|
26
|
+
return PosthogReactNativeSessionReplay.startSession(sessionId);
|
|
27
|
+
}
|
|
28
|
+
function endSession() {
|
|
29
|
+
return PosthogReactNativeSessionReplay.endSession();
|
|
30
|
+
}
|
|
31
|
+
function isEnabled() {
|
|
32
|
+
return PosthogReactNativeSessionReplay.isEnabled();
|
|
33
|
+
}
|
|
34
|
+
function identify(distinctId, anonymousId) {
|
|
35
|
+
return PosthogReactNativeSessionReplay.identify(distinctId, anonymousId);
|
|
36
|
+
}
|
|
37
|
+
const PostHogReactNativeSessionReplay = {
|
|
38
|
+
start,
|
|
39
|
+
startSession,
|
|
40
|
+
endSession,
|
|
41
|
+
isEnabled,
|
|
42
|
+
identify
|
|
43
|
+
};
|
|
44
|
+
var _default = exports.default = PostHogReactNativeSessionReplay;
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","PosthogReactNativeSessionReplay","NativeModules","Proxy","get","Error","start","sessionId","sdkOptions","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","PostHogReactNativeSessionReplay","_default","exports"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,sGAAsG,GACtGC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,+BAA+B,GACnCC,0BAAa,CAACD,+BAA+B,GACzCC,0BAAa,CAACD,+BAA+B,GAC7C,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEA,SAASU,KAAKA,CACnBC,SAAiB,EACjBC,UAAkC,EAClCC,eAAuC,EACvCC,kBAA0C,EAC3B;EACf,OAAOT,+BAA+B,CAACK,KAAK,CAC1CC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,kBACF,CAAC;AACH;AAEO,SAASC,YAAYA,CAACJ,SAAiB,EAAiB;EAC7D,OAAON,+BAA+B,CAACU,YAAY,CAACJ,SAAS,CAAC;AAChE;AAEO,SAASK,UAAUA,CAAA,EAAkB;EAC1C,OAAOX,+BAA+B,CAACW,UAAU,CAAC,CAAC;AACrD;AAEO,SAASC,SAASA,CAAA,EAAqB;EAC5C,OAAOZ,+BAA+B,CAACY,SAAS,CAAC,CAAC;AACpD;AAEO,SAASC,QAAQA,CACtBC,UAAkB,EAClBC,WAAmB,EACJ;EACf,OAAOf,+BAA+B,CAACa,QAAQ,CAACC,UAAU,EAAEC,WAAW,CAAC;AAC1E;AAmBA,MAAMC,+BAAsE,GAAG;EAC7EX,KAAK;EACLK,YAAY;EACZC,UAAU;EACVC,SAAS;EACTC;AACF,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAnB,OAAA,GAEaiB,+BAA+B","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules, Platform } from 'react-native';
|
|
4
|
+
const LINKING_ERROR = `The package '@plushanalytics/react-native-session-replay' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
5
|
+
ios: "- You have run 'pod install'\n",
|
|
6
|
+
default: ''
|
|
7
|
+
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
|
+
const PosthogReactNativeSessionReplay = NativeModules.PosthogReactNativeSessionReplay ? NativeModules.PosthogReactNativeSessionReplay : new Proxy({}, {
|
|
9
|
+
get() {
|
|
10
|
+
throw new Error(LINKING_ERROR);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export function start(sessionId, sdkOptions, sdkReplayConfig, decideReplayConfig) {
|
|
14
|
+
return PosthogReactNativeSessionReplay.start(sessionId, sdkOptions, sdkReplayConfig, decideReplayConfig);
|
|
15
|
+
}
|
|
16
|
+
export function startSession(sessionId) {
|
|
17
|
+
return PosthogReactNativeSessionReplay.startSession(sessionId);
|
|
18
|
+
}
|
|
19
|
+
export function endSession() {
|
|
20
|
+
return PosthogReactNativeSessionReplay.endSession();
|
|
21
|
+
}
|
|
22
|
+
export function isEnabled() {
|
|
23
|
+
return PosthogReactNativeSessionReplay.isEnabled();
|
|
24
|
+
}
|
|
25
|
+
export function identify(distinctId, anonymousId) {
|
|
26
|
+
return PosthogReactNativeSessionReplay.identify(distinctId, anonymousId);
|
|
27
|
+
}
|
|
28
|
+
const PostHogReactNativeSessionReplay = {
|
|
29
|
+
start,
|
|
30
|
+
startSession,
|
|
31
|
+
endSession,
|
|
32
|
+
isEnabled,
|
|
33
|
+
identify
|
|
34
|
+
};
|
|
35
|
+
export default PostHogReactNativeSessionReplay;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","PosthogReactNativeSessionReplay","Proxy","get","Error","start","sessionId","sdkOptions","sdkReplayConfig","decideReplayConfig","startSession","endSession","isEnabled","identify","distinctId","anonymousId","PostHogReactNativeSessionReplay"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,sGAAsG,GACtGD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,+BAA+B,GACnCN,aAAa,CAACM,+BAA+B,GACzCN,aAAa,CAACM,+BAA+B,GAC7C,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEP,OAAO,SAASQ,KAAKA,CACnBC,SAAiB,EACjBC,UAAkC,EAClCC,eAAuC,EACvCC,kBAA0C,EAC3B;EACf,OAAOR,+BAA+B,CAACI,KAAK,CAC1CC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,kBACF,CAAC;AACH;AAEA,OAAO,SAASC,YAAYA,CAACJ,SAAiB,EAAiB;EAC7D,OAAOL,+BAA+B,CAACS,YAAY,CAACJ,SAAS,CAAC;AAChE;AAEA,OAAO,SAASK,UAAUA,CAAA,EAAkB;EAC1C,OAAOV,+BAA+B,CAACU,UAAU,CAAC,CAAC;AACrD;AAEA,OAAO,SAASC,SAASA,CAAA,EAAqB;EAC5C,OAAOX,+BAA+B,CAACW,SAAS,CAAC,CAAC;AACpD;AAEA,OAAO,SAASC,QAAQA,CACtBC,UAAkB,EAClBC,WAAmB,EACJ;EACf,OAAOd,+BAA+B,CAACY,QAAQ,CAACC,UAAU,EAAEC,WAAW,CAAC;AAC1E;AAmBA,MAAMC,+BAAsE,GAAG;EAC7EX,KAAK;EACLK,YAAY;EACZC,UAAU;EACVC,SAAS;EACTC;AACF,CAAC;AAED,eAAeG,+BAA+B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare function start(sessionId: string, sdkOptions: {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}, sdkReplayConfig: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}, decideReplayConfig: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
export declare function startSession(sessionId: string): Promise<void>;
|
|
9
|
+
export declare function endSession(): Promise<void>;
|
|
10
|
+
export declare function isEnabled(): Promise<boolean>;
|
|
11
|
+
export declare function identify(distinctId: string, anonymousId: string): Promise<void>;
|
|
12
|
+
export interface PostHogReactNativeSessionReplayModule {
|
|
13
|
+
start: (sessionId: string, sdkOptions: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}, // options from SDK such as apiKey
|
|
16
|
+
sdkReplayConfig: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}, // config from SDK
|
|
19
|
+
decideReplayConfig: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
startSession: (sessionId: string) => Promise<void>;
|
|
23
|
+
endSession: () => Promise<void>;
|
|
24
|
+
isEnabled: () => Promise<boolean>;
|
|
25
|
+
identify: (distinctId: string, anonymousId: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
declare const PostHogReactNativeSessionReplay: PostHogReactNativeSessionReplayModule;
|
|
28
|
+
export default PostHogReactNativeSessionReplay;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAoBA,wBAAgB,KAAK,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAClC,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EACvC,kBAAkB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GACzC,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED,wBAAgB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;AAED,wBAAgB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAE5C;AAED,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,MAAM,WAAW,qCAAqC;IACpD,KAAK,EAAE,CACL,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,kCAAkC;IACtE,eAAe,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,kBAAkB;IAC3D,kBAAkB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KACvC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAElC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,QAAA,MAAM,+BAA+B,EAAE,qCAMtC,CAAC;AAEF,eAAe,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare function start(sessionId: string, sdkOptions: {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}, sdkReplayConfig: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}, decideReplayConfig: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
export declare function startSession(sessionId: string): Promise<void>;
|
|
9
|
+
export declare function endSession(): Promise<void>;
|
|
10
|
+
export declare function isEnabled(): Promise<boolean>;
|
|
11
|
+
export declare function identify(distinctId: string, anonymousId: string): Promise<void>;
|
|
12
|
+
export interface PostHogReactNativeSessionReplayModule {
|
|
13
|
+
start: (sessionId: string, sdkOptions: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}, // options from SDK such as apiKey
|
|
16
|
+
sdkReplayConfig: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}, // config from SDK
|
|
19
|
+
decideReplayConfig: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
startSession: (sessionId: string) => Promise<void>;
|
|
23
|
+
endSession: () => Promise<void>;
|
|
24
|
+
isEnabled: () => Promise<boolean>;
|
|
25
|
+
identify: (distinctId: string, anonymousId: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
declare const PostHogReactNativeSessionReplay: PostHogReactNativeSessionReplayModule;
|
|
28
|
+
export default PostHogReactNativeSessionReplay;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAoBA,wBAAgB,KAAK,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAClC,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EACvC,kBAAkB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GACzC,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED,wBAAgB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;AAED,wBAAgB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAE5C;AAED,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,MAAM,WAAW,qCAAqC;IACpD,KAAK,EAAE,CACL,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,kCAAkC;IACtE,eAAe,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,kBAAkB;IAC3D,kBAAkB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KACvC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAElC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,QAAA,MAAM,+BAA+B,EAAE,qCAMtC,CAAC;AAEF,eAAe,+BAA+B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plushanalytics/react-native-session-replay",
|
|
3
|
+
"version": "1.2.5",
|
|
4
|
+
"description": "Session Replay",
|
|
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
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"example": "pnpm --filter plush-react-native-session-replay-example",
|
|
41
|
+
"test": "jest",
|
|
42
|
+
"typecheck": "tsc",
|
|
43
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
44
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
45
|
+
"prepare": "bob build",
|
|
46
|
+
"changeset": "changeset"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"react-native",
|
|
50
|
+
"ios",
|
|
51
|
+
"android"
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/plush-analytics/plush-react-native-session-replay.git"
|
|
56
|
+
},
|
|
57
|
+
"author": "Plush Analytics",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/plush-analytics/plush-react-native-session-replay/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/plush-analytics/plush-react-native-session-replay#readme",
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"registry": "https://registry.npmjs.org/"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@changesets/cli": "^2.27.0",
|
|
68
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
69
|
+
"@react-native-community/cli": "20.0.0",
|
|
70
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
71
|
+
"@types/jest": "^29.5.5",
|
|
72
|
+
"@types/react": "^18.2.44",
|
|
73
|
+
"del-cli": "^5.1.0",
|
|
74
|
+
"eslint": "^8.51.0",
|
|
75
|
+
"eslint-config-prettier": "^9.0.0",
|
|
76
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
77
|
+
"jest": "^29.7.0",
|
|
78
|
+
"prettier": "^3.0.3",
|
|
79
|
+
"react": "18.3.1",
|
|
80
|
+
"react-native": "0.75.3",
|
|
81
|
+
"react-native-builder-bob": "^0.30.2",
|
|
82
|
+
"turbo": "^2.0.0",
|
|
83
|
+
"typescript": "^5.2.2"
|
|
84
|
+
},
|
|
85
|
+
"pnpm": {
|
|
86
|
+
"overrides": {
|
|
87
|
+
"@types/react": "^18.2.44",
|
|
88
|
+
"node-forge": "1.3.2",
|
|
89
|
+
"fast-xml-parser": "5.3.4"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"react": "*",
|
|
94
|
+
"react-native": "*"
|
|
95
|
+
},
|
|
96
|
+
"packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a",
|
|
97
|
+
"jest": {
|
|
98
|
+
"preset": "react-native",
|
|
99
|
+
"modulePathIgnorePatterns": [
|
|
100
|
+
"<rootDir>/example/node_modules",
|
|
101
|
+
"<rootDir>/lib/"
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"eslintConfig": {
|
|
105
|
+
"root": true,
|
|
106
|
+
"extends": [
|
|
107
|
+
"@react-native",
|
|
108
|
+
"prettier"
|
|
109
|
+
],
|
|
110
|
+
"rules": {
|
|
111
|
+
"react/react-in-jsx-scope": "off",
|
|
112
|
+
"prettier/prettier": [
|
|
113
|
+
"error",
|
|
114
|
+
{
|
|
115
|
+
"quoteProps": "consistent",
|
|
116
|
+
"singleQuote": true,
|
|
117
|
+
"tabWidth": 2,
|
|
118
|
+
"trailingComma": "es5",
|
|
119
|
+
"useTabs": false
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"eslintIgnore": [
|
|
125
|
+
"node_modules/",
|
|
126
|
+
"lib/"
|
|
127
|
+
],
|
|
128
|
+
"prettier": {
|
|
129
|
+
"quoteProps": "consistent",
|
|
130
|
+
"singleQuote": true,
|
|
131
|
+
"tabWidth": 2,
|
|
132
|
+
"trailingComma": "es5",
|
|
133
|
+
"useTabs": false
|
|
134
|
+
},
|
|
135
|
+
"react-native-builder-bob": {
|
|
136
|
+
"source": "src",
|
|
137
|
+
"output": "lib",
|
|
138
|
+
"targets": [
|
|
139
|
+
[
|
|
140
|
+
"commonjs",
|
|
141
|
+
{
|
|
142
|
+
"esm": true
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
"module",
|
|
147
|
+
{
|
|
148
|
+
"esm": true
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
"typescript",
|
|
153
|
+
{
|
|
154
|
+
"project": "tsconfig.build.json",
|
|
155
|
+
"esm": true
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
"create-react-native-library": {
|
|
161
|
+
"type": "module-legacy",
|
|
162
|
+
"languages": "kotlin-swift",
|
|
163
|
+
"version": "0.41.2"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "plush-react-native-session-replay"
|
|
8
|
+
s.version = package["version"]
|
|
9
|
+
s.summary = package["description"]
|
|
10
|
+
s.homepage = package["homepage"]
|
|
11
|
+
s.license = package["license"]
|
|
12
|
+
s.authors = package["author"]
|
|
13
|
+
|
|
14
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
15
|
+
s.source = { :git => "https://github.com/plush-analytics/plush-react-native-session-replay.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{swift,h,hpp,m,mm,c,cpp}"
|
|
18
|
+
|
|
19
|
+
# ~> Version 3.21.0 up to, but not including, 4.0.0
|
|
20
|
+
s.dependency 'PostHog', '~> 3.21'
|
|
21
|
+
s.ios.deployment_target = '13.0'
|
|
22
|
+
s.swift_versions = "5.3"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
26
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
27
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
28
|
+
install_modules_dependencies(s)
|
|
29
|
+
else
|
|
30
|
+
s.dependency "React-Core"
|
|
31
|
+
|
|
32
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
33
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
34
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
35
|
+
s.pod_target_xcconfig = {
|
|
36
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
37
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
38
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
39
|
+
}
|
|
40
|
+
s.dependency "React-Codegen"
|
|
41
|
+
s.dependency "RCT-Folly"
|
|
42
|
+
s.dependency "RCTRequired"
|
|
43
|
+
s.dependency "RCTTypeSafety"
|
|
44
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
package/src/index.tsx
ADDED
|
@@ -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;
|