@amplitude/session-replay-react-native 0.0.1-beta.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.
- package/AmplitudeSessionReplayReactNative.podspec +45 -0
- package/LICENSE +20 -0
- package/README.md +101 -0
- package/android/build.gradle +101 -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/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +182 -0
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +17 -0
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeViewManager.kt +22 -0
- package/ios/AMPNativeSessionReplay.mm +21 -0
- package/ios/NativeSessionReplay-Bridging-Header.h +2 -0
- package/ios/NativeSessionReplay.swift +150 -0
- package/ios/RCTAmpMaskViewManager.m +29 -0
- package/lib/commonjs/amp-mask-view.js +9 -0
- package/lib/commonjs/amp-mask-view.js.map +1 -0
- package/lib/commonjs/index.js +76 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/logger.js +42 -0
- package/lib/commonjs/logger.js.map +1 -0
- package/lib/commonjs/native-module.js +31 -0
- package/lib/commonjs/native-module.js.map +1 -0
- package/lib/commonjs/plugin-session-replay-config.js +21 -0
- package/lib/commonjs/plugin-session-replay-config.js.map +1 -0
- package/lib/commonjs/plugin-session-replay.js +150 -0
- package/lib/commonjs/plugin-session-replay.js.map +1 -0
- package/lib/commonjs/session-replay-config.js +49 -0
- package/lib/commonjs/session-replay-config.js.map +1 -0
- package/lib/commonjs/session-replay.js +226 -0
- package/lib/commonjs/session-replay.js.map +1 -0
- package/lib/commonjs/version.js +9 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/amp-mask-view.js +3 -0
- package/lib/module/amp-mask-view.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/logger.js +35 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/module/native-module.js +25 -0
- package/lib/module/native-module.js.map +1 -0
- package/lib/module/plugin-session-replay-config.js +15 -0
- package/lib/module/plugin-session-replay-config.js.map +1 -0
- package/lib/module/plugin-session-replay.js +144 -0
- package/lib/module/plugin-session-replay.js.map +1 -0
- package/lib/module/session-replay-config.js +40 -0
- package/lib/module/session-replay-config.js.map +1 -0
- package/lib/module/session-replay.js +212 -0
- package/lib/module/session-replay.js.map +1 -0
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/amp-mask-view.d.ts +7 -0
- package/lib/typescript/amp-mask-view.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/logger.d.ts +9 -0
- package/lib/typescript/logger.d.ts.map +1 -0
- package/lib/typescript/native-module.d.ts +87 -0
- package/lib/typescript/native-module.d.ts.map +1 -0
- package/lib/typescript/plugin-session-replay-config.d.ts +29 -0
- package/lib/typescript/plugin-session-replay-config.d.ts.map +1 -0
- package/lib/typescript/plugin-session-replay.d.ts +77 -0
- package/lib/typescript/plugin-session-replay.d.ts.map +1 -0
- package/lib/typescript/session-replay-config.d.ts +80 -0
- package/lib/typescript/session-replay-config.d.ts.map +1 -0
- package/lib/typescript/session-replay.d.ts +128 -0
- package/lib/typescript/session-replay.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +2 -0
- package/lib/typescript/version.d.ts.map +1 -0
- package/package.json +96 -0
- package/src/amp-mask-view.tsx +7 -0
- package/src/index.tsx +16 -0
- package/src/logger.ts +41 -0
- package/src/native-module.ts +113 -0
- package/src/plugin-session-replay-config.ts +40 -0
- package/src/plugin-session-replay.ts +159 -0
- package/src/session-replay-config.ts +103 -0
- package/src/session-replay.ts +223 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,45 @@
|
|
|
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 = "AmplitudeSessionReplayReactNative"
|
|
8
|
+
s.version = package["version"].split(/[-+]/).first
|
|
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/amplitude/Amplitude-TypeScript.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
|
+
|
|
19
|
+
s.dependency 'AmplitudeSessionReplay', '>=0.4.0'
|
|
20
|
+
s.dependency 'AmplitudeCore', '>=1.1.0'
|
|
21
|
+
|
|
22
|
+
# This code is to support RN prior to 0.71.0. Should be removed when we drop support for RN < 0.71.0.
|
|
23
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
24
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
25
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
26
|
+
install_modules_dependencies(s)
|
|
27
|
+
else
|
|
28
|
+
s.dependency "React-Core"
|
|
29
|
+
|
|
30
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
31
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
32
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
33
|
+
s.pod_target_xcconfig = {
|
|
34
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
35
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
36
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
37
|
+
}
|
|
38
|
+
s.dependency "React-Codegen"
|
|
39
|
+
s.dependency "RCT-Folly"
|
|
40
|
+
s.dependency "RCTRequired"
|
|
41
|
+
s.dependency "RCTTypeSafety"
|
|
42
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Amplitude, Inc.
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @amplitude/session-replay-react-native
|
|
2
|
+
|
|
3
|
+
Amplitude Session Replay for React Native
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @amplitude/session-replay-react-native
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Session Replay React Native Standalone SDK
|
|
14
|
+
|
|
15
|
+
Initialize SDK with your amplidude API Key
|
|
16
|
+
```js
|
|
17
|
+
import { init, SessionReplayConfig } from '@amplitude/session-replay-react-native';
|
|
18
|
+
|
|
19
|
+
const config: SessionReplayConfig = {
|
|
20
|
+
apiKey: 'YOUR_API_KEY',
|
|
21
|
+
deviceId: 'YOUR_DEVICE_ID',
|
|
22
|
+
sessionId: Date.now()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await init(config);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Session Replay React Native Plugin
|
|
29
|
+
|
|
30
|
+
Add the session replay plugin to your Amplitude instance as follows
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { SessionReplayPlugin, SessionReplaPluginConfig } from '@amplitude/session-replay-react-native';
|
|
34
|
+
|
|
35
|
+
// ...
|
|
36
|
+
|
|
37
|
+
const config: SessionReplaPluginConfig = {
|
|
38
|
+
enableRemoteConfig: true, // default true
|
|
39
|
+
sampleRate: 1, // default 0
|
|
40
|
+
logLevel: LogLevel.Warn, // default LogLevel.Warn
|
|
41
|
+
};
|
|
42
|
+
await init('YOUR_API_KEY').promise;
|
|
43
|
+
await add(new SessionReplayPlugin(config)).promise;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Masking views
|
|
47
|
+
|
|
48
|
+
To maks certain views, add the `AmpMaskView` tag with the mask property `amp-mask` around the section to be masked
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import { AmpMaskView } from '@amplitude/session-replay-react-native';
|
|
52
|
+
|
|
53
|
+
// ...
|
|
54
|
+
|
|
55
|
+
<AmpMaskView mask="amp-mask">
|
|
56
|
+
<Text
|
|
57
|
+
style={[
|
|
58
|
+
styles.sectionTitle,
|
|
59
|
+
{
|
|
60
|
+
color: isDarkMode ? Colors.white : Colors.black,
|
|
61
|
+
},
|
|
62
|
+
]}
|
|
63
|
+
>
|
|
64
|
+
{title}
|
|
65
|
+
</Text>
|
|
66
|
+
</AmpMaskView>;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Unmasking views
|
|
70
|
+
|
|
71
|
+
To unmask views, add the `AmpMaskView` tag with the mask property `amp-unmask` around the section to be unmasked
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { AmpMaskView } from '@amplitude/session-replay-react-native';
|
|
75
|
+
|
|
76
|
+
// ...
|
|
77
|
+
|
|
78
|
+
<AmpMaskView mask="amp-unmask">
|
|
79
|
+
<Text
|
|
80
|
+
style={[
|
|
81
|
+
styles.sectionTitle,
|
|
82
|
+
{
|
|
83
|
+
color: isDarkMode ? Colors.white : Colors.black,
|
|
84
|
+
},
|
|
85
|
+
]}
|
|
86
|
+
>
|
|
87
|
+
{title}
|
|
88
|
+
</Text>
|
|
89
|
+
</AmpMaskView>;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Tracking Web Views (Beta)
|
|
93
|
+
|
|
94
|
+
Web views are blocked by default and will not be tracked. If you'd like webviews to be tracked, you can manually unmask
|
|
95
|
+
them by doing the following
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
<AmpMaskView mask="amp-unmask" style={{ flex: 1 }}>
|
|
99
|
+
<WebView source={{ uri: 'https://reactnative.dev/' }} style={{ flex: 1 }} />
|
|
100
|
+
</AmpMaskView>
|
|
101
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
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["SessionReplayReactNative_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["SessionReplayReactNative_" + name]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def getExtOrIntegerDefault(name) {
|
|
38
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SessionReplayReactNative_" + 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.amplitude.sessionreplayreactnative"
|
|
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
|
+
implementation("com.amplitude:session-replay-android:[0.20.6]")
|
|
94
|
+
implementation("com.amplitude:analytics-android:1.21.1")
|
|
95
|
+
|
|
96
|
+
// For < 0.71, this will be from the local maven repo
|
|
97
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
98
|
+
//noinspection GradleDynamicVersion
|
|
99
|
+
implementation "com.facebook.react:react-native:+"
|
|
100
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
101
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
package com.amplitude.sessionreplayreactnative
|
|
2
|
+
|
|
3
|
+
import com.amplitude.android.sessionreplay.SessionReplay
|
|
4
|
+
import com.amplitude.android.sessionreplay.config.MaskLevel
|
|
5
|
+
import com.amplitude.android.sessionreplay.config.PrivacyConfig
|
|
6
|
+
import com.amplitude.common.Logger
|
|
7
|
+
import com.amplitude.common.android.LogcatLogger
|
|
8
|
+
import com.amplitude.core.ServerZone
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
11
|
+
import com.facebook.react.bridge.ReactMethod
|
|
12
|
+
import com.facebook.react.bridge.Promise
|
|
13
|
+
import com.facebook.react.bridge.WritableMap
|
|
14
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
15
|
+
import com.facebook.react.bridge.ReadableMap
|
|
16
|
+
|
|
17
|
+
class SessionReplayReactNativeModule(private val reactContext: ReactApplicationContext) :
|
|
18
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
19
|
+
private lateinit var sessionReplay: SessionReplay
|
|
20
|
+
|
|
21
|
+
override fun getName(): String {
|
|
22
|
+
return "AMPNativeSessionReplay"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@ReactMethod
|
|
26
|
+
fun setup(config: ReadableMap, promise: Promise) {
|
|
27
|
+
try {
|
|
28
|
+
val apiKey = config.getString("apiKey") ?: throw IllegalArgumentException("apiKey is required")
|
|
29
|
+
val deviceId = config.getString("deviceId")
|
|
30
|
+
val sessionId = config.getDouble("sessionId").toLong()
|
|
31
|
+
val serverZone = config.getString("serverZone") ?: "US"
|
|
32
|
+
val sampleRate = config.getDouble("sampleRate")
|
|
33
|
+
val enableRemoteConfig = config.getBoolean("enableRemoteConfig")
|
|
34
|
+
val logLevel = config.getInt("logLevel")
|
|
35
|
+
val autoStart = config.getBoolean("autoStart")
|
|
36
|
+
val optOut = config.getBoolean("optOut")
|
|
37
|
+
val maskLevel = when ((config.getString("maskLevel") ?: "medium").lowercase()) {
|
|
38
|
+
"light" -> MaskLevel.LIGHT
|
|
39
|
+
"medium" -> MaskLevel.MEDIUM
|
|
40
|
+
"conservative" -> MaskLevel.CONSERVATIVE
|
|
41
|
+
else -> MaskLevel.MEDIUM
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
LogcatLogger.logger.logMode = when (logLevel) {
|
|
45
|
+
0 -> Logger.LogMode.OFF
|
|
46
|
+
1 -> Logger.LogMode.ERROR
|
|
47
|
+
2 -> Logger.LogMode.WARN
|
|
48
|
+
3 -> Logger.LogMode.INFO
|
|
49
|
+
4 -> Logger.LogMode.DEBUG
|
|
50
|
+
else -> Logger.LogMode.WARN
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
LogcatLogger.logger.debug("""
|
|
54
|
+
setup:
|
|
55
|
+
API Key: $apiKey
|
|
56
|
+
Device Id: $deviceId
|
|
57
|
+
Session Id: $sessionId
|
|
58
|
+
Server Zone: $serverZone
|
|
59
|
+
Sample Rate: $sampleRate
|
|
60
|
+
Enable Remote Config: $enableRemoteConfig
|
|
61
|
+
Log Level: $logLevel
|
|
62
|
+
Auto Start: $autoStart
|
|
63
|
+
Mask Level: $maskLevel
|
|
64
|
+
Opt Out: $optOut
|
|
65
|
+
""".trimIndent())
|
|
66
|
+
|
|
67
|
+
sessionReplay = SessionReplay(
|
|
68
|
+
apiKey,
|
|
69
|
+
reactContext.applicationContext,
|
|
70
|
+
deviceId ?: "",
|
|
71
|
+
sessionId,
|
|
72
|
+
logger = LogcatLogger.logger,
|
|
73
|
+
sampleRate = sampleRate,
|
|
74
|
+
enableRemoteConfig = enableRemoteConfig,
|
|
75
|
+
serverZone = when (serverZone) {
|
|
76
|
+
"EU" -> ServerZone.EU
|
|
77
|
+
else -> ServerZone.US
|
|
78
|
+
},
|
|
79
|
+
autoStart = autoStart,
|
|
80
|
+
privacyConfig = PrivacyConfig(maskLevel = maskLevel),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
promise.resolve(null)
|
|
84
|
+
} catch (e: Exception) {
|
|
85
|
+
promise.reject("SETUP_ERROR", e.message, e)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
fun setSessionId(sessionId: Double, promise: Promise) {
|
|
91
|
+
try {
|
|
92
|
+
sessionReplay.setSessionId(sessionId.toLong())
|
|
93
|
+
promise.resolve(null)
|
|
94
|
+
} catch (e: Exception) {
|
|
95
|
+
promise.reject("SET_SESSION_ID_ERROR", e.message, e)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@ReactMethod
|
|
100
|
+
fun setDeviceId(deviceId: String?, promise: Promise) {
|
|
101
|
+
try {
|
|
102
|
+
sessionReplay.setDeviceId(deviceId ?: "")
|
|
103
|
+
promise.resolve(null)
|
|
104
|
+
} catch (e: Exception) {
|
|
105
|
+
promise.reject("SET_DEVICE_ID_ERROR", e.message, e)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@ReactMethod
|
|
110
|
+
fun getSessionId(promise: Promise) {
|
|
111
|
+
try {
|
|
112
|
+
promise.resolve(sessionReplay.getSessionId().toDouble())
|
|
113
|
+
} catch (e: Exception) {
|
|
114
|
+
promise.reject("GET_SESSION_ID_ERROR", e.message, e)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactMethod
|
|
119
|
+
fun getSessionReplayProperties(promise: Promise) {
|
|
120
|
+
try {
|
|
121
|
+
val properties: Map<String, Any> = sessionReplay.getSessionReplayProperties()
|
|
122
|
+
val map: WritableMap = WritableNativeMap()
|
|
123
|
+
for ((key, value) in properties) {
|
|
124
|
+
if (value is String) {
|
|
125
|
+
map.putString(key, value)
|
|
126
|
+
} else if (value is Int) {
|
|
127
|
+
map.putInt(key, value)
|
|
128
|
+
} else if (value is Long) {
|
|
129
|
+
map.putDouble(key, value.toDouble())
|
|
130
|
+
} else if (value is Double) {
|
|
131
|
+
map.putDouble(key, value)
|
|
132
|
+
} else if (value is Boolean) {
|
|
133
|
+
map.putBoolean(key, value)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
promise.resolve(map)
|
|
137
|
+
} catch (e: Exception) {
|
|
138
|
+
promise.reject("GET_PROPERTIES_ERROR", e.message, e)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@ReactMethod
|
|
143
|
+
fun start(promise: Promise) {
|
|
144
|
+
try {
|
|
145
|
+
sessionReplay.start()
|
|
146
|
+
promise.resolve(null)
|
|
147
|
+
} catch (e: Exception) {
|
|
148
|
+
promise.reject("START_ERROR", e.message, e)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@ReactMethod
|
|
153
|
+
fun stop(promise: Promise) {
|
|
154
|
+
try {
|
|
155
|
+
sessionReplay.stop()
|
|
156
|
+
promise.resolve(null)
|
|
157
|
+
} catch (e: Exception) {
|
|
158
|
+
promise.reject("STOP_ERROR", e.message, e)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@ReactMethod
|
|
163
|
+
fun flush(promise: Promise) {
|
|
164
|
+
try {
|
|
165
|
+
sessionReplay.flush()
|
|
166
|
+
promise.resolve(null)
|
|
167
|
+
} catch (e: Exception) {
|
|
168
|
+
promise.reject("FLUSH_ERROR", e.message, e)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@ReactMethod
|
|
173
|
+
fun teardown() {
|
|
174
|
+
sessionReplay.shutdown()
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
override fun invalidate() {
|
|
178
|
+
if (::sessionReplay.isInitialized) {
|
|
179
|
+
sessionReplay.shutdown()
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.amplitude.sessionreplayreactnative
|
|
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
|
+
|
|
9
|
+
class SessionReplayReactNativePackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(SessionReplayReactNativeModule(reactContext))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
+
return listOf(SessionReplayReactNativeViewManager())
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.amplitude.sessionreplayreactnative
|
|
2
|
+
|
|
3
|
+
import android.view.ViewGroup
|
|
4
|
+
import com.amplitude.android.sessionreplay.SessionReplay
|
|
5
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
6
|
+
import com.facebook.react.views.view.ReactViewManager
|
|
7
|
+
|
|
8
|
+
class SessionReplayReactNativeViewManager : ReactViewManager() {
|
|
9
|
+
|
|
10
|
+
override fun getName(): String {
|
|
11
|
+
return "AMPMaskComponentView"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@ReactProp(name = "mask")
|
|
15
|
+
fun setMask(view: ViewGroup, ampMask: String) {
|
|
16
|
+
when (ampMask) {
|
|
17
|
+
"amp-mask" -> SessionReplay.mask(view)
|
|
18
|
+
"amp-unmask" -> SessionReplay.unmask(view)
|
|
19
|
+
"amp-block" -> SessionReplay.block(view)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(AMPNativeSessionReplay, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(flush:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
6
|
+
|
|
7
|
+
RCT_EXTERN_METHOD(getSessionId:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
|
|
9
|
+
RCT_EXTERN_METHOD(getSessionReplayProperties:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
10
|
+
|
|
11
|
+
RCT_EXTERN_METHOD(setSessionId:(nonnull NSNumber)sessionId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN_METHOD(setDeviceId:(NSString)deviceId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
14
|
+
|
|
15
|
+
RCT_EXTERN_METHOD(setup:(NSDictionary *)config resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
16
|
+
|
|
17
|
+
RCT_EXTERN_METHOD(start:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
18
|
+
|
|
19
|
+
RCT_EXTERN_METHOD(stop:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
20
|
+
|
|
21
|
+
@end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import AmplitudeSessionReplay
|
|
3
|
+
import AmplitudeCore
|
|
4
|
+
|
|
5
|
+
@objc(AMPNativeSessionReplay)
|
|
6
|
+
class NativeSessionReplay: NSObject, RCTBridgeModule {
|
|
7
|
+
static func moduleName() -> String! {
|
|
8
|
+
"AMPNativeSessionReplay"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var sessionReplay: SessionReplay!
|
|
12
|
+
var logger: CoreLogger!
|
|
13
|
+
|
|
14
|
+
override init() {
|
|
15
|
+
print("NativeSessionReplay init")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@objc(setup:resolve:reject:)
|
|
19
|
+
func setup(_ config: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
20
|
+
guard let apiKey = config["apiKey"] as? String,
|
|
21
|
+
let sessionId = config["sessionId"] as? NSNumber,
|
|
22
|
+
let serverZone = config["serverZone"] as? String,
|
|
23
|
+
let sampleRate = config["sampleRate"] as? NSNumber,
|
|
24
|
+
let enableRemoteConfig = config["enableRemoteConfig"] as? Bool,
|
|
25
|
+
let logLevel = config["logLevel"] as? Int,
|
|
26
|
+
let autoStart = config["autoStart"] as? Bool,
|
|
27
|
+
let maskLevel = config["maskLevel"] as? String,
|
|
28
|
+
let optOut = config["optOut"] as? Bool else {
|
|
29
|
+
reject("INVALID_CONFIG", "Invalid configuration parameters", nil)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let deviceId = config["deviceId"] as? String
|
|
34
|
+
|
|
35
|
+
logger = OSLogger(logLevel: LogLevel(rawValue: logLevel) ?? .warn)
|
|
36
|
+
|
|
37
|
+
logger.log(message:
|
|
38
|
+
"""
|
|
39
|
+
setup:
|
|
40
|
+
API Key: \(apiKey)
|
|
41
|
+
Device ID: \(deviceId ?? "null")
|
|
42
|
+
Session ID: \(sessionId)
|
|
43
|
+
Server Zone: \(serverZone)
|
|
44
|
+
Sample Rate: \(sampleRate)
|
|
45
|
+
Enable Remote Config: \(enableRemoteConfig)
|
|
46
|
+
Log Level: \(logLevel)
|
|
47
|
+
Auto Start: \(autoStart)
|
|
48
|
+
Mask Level: \(maskLevel)
|
|
49
|
+
Opt Out: \(optOut)
|
|
50
|
+
"""
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
sessionReplay = SessionReplay(
|
|
54
|
+
apiKey: apiKey,
|
|
55
|
+
deviceId: deviceId,
|
|
56
|
+
sessionId: sessionId.int64Value,
|
|
57
|
+
optOut: optOut,
|
|
58
|
+
sampleRate: Float(truncating: sampleRate),
|
|
59
|
+
logger: logger,
|
|
60
|
+
serverZone: serverZone == "EU" ? .EU : .US,
|
|
61
|
+
maskLevel: .fromString(maskLevel),
|
|
62
|
+
enableRemoteConfig: enableRemoteConfig
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if (autoStart) {
|
|
66
|
+
sessionReplay.start()
|
|
67
|
+
}
|
|
68
|
+
resolve(nil)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@objc(setSessionId:resolve:reject:)
|
|
72
|
+
func setSessionId(_ sessionId: NSNumber, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
73
|
+
logger.debug(message: "setSessionId: \(sessionId)")
|
|
74
|
+
sessionReplay.sessionId = sessionId.int64Value
|
|
75
|
+
resolve(nil)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@objc(setDeviceId:resolve:reject:)
|
|
79
|
+
func setDeviceId(_ deviceId: NSString, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
80
|
+
logger.debug(message: "setDeviceId: \(deviceId)")
|
|
81
|
+
sessionReplay.deviceId = deviceId as String?
|
|
82
|
+
resolve(nil)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@objc(getSessionId:reject:)
|
|
86
|
+
func getSessionId(
|
|
87
|
+
_ resolve: RCTPromiseResolveBlock,
|
|
88
|
+
reject: RCTPromiseRejectBlock
|
|
89
|
+
) {
|
|
90
|
+
logger.debug(message: "getSessionId")
|
|
91
|
+
resolve(NSNumber(value:sessionReplay.sessionId))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@objc(getSessionReplayProperties:reject:)
|
|
95
|
+
func getSessionReplayProperties(
|
|
96
|
+
_ resolve: RCTPromiseResolveBlock,
|
|
97
|
+
reject: RCTPromiseRejectBlock
|
|
98
|
+
) {
|
|
99
|
+
logger.debug(message: "getSessionReplayProperties")
|
|
100
|
+
resolve(sessionReplay.additionalEventProperties)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@objc(start:reject:)
|
|
104
|
+
func start(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
105
|
+
logger.debug(message: "start")
|
|
106
|
+
sessionReplay.start()
|
|
107
|
+
print(sessionReplay.additionalEventProperties)
|
|
108
|
+
print(
|
|
109
|
+
"SessionId: \(sessionReplay.sessionId); DeviceId: \(sessionReplay.deviceId ?? "nil")"
|
|
110
|
+
)
|
|
111
|
+
resolve(nil)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@objc(stop:reject:)
|
|
115
|
+
func stop(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
116
|
+
logger.debug(message: "stop")
|
|
117
|
+
sessionReplay.stop()
|
|
118
|
+
resolve(nil)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@objc(flush:reject:)
|
|
122
|
+
func flush(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
123
|
+
logger.debug(message: "flush")
|
|
124
|
+
sessionReplay.flush()
|
|
125
|
+
resolve(nil)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@objc(invalidate)
|
|
129
|
+
func invalidate() {
|
|
130
|
+
print("invalidate")
|
|
131
|
+
// could be nil here
|
|
132
|
+
sessionReplay?.stop()
|
|
133
|
+
sessionReplay = nil
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
extension MaskLevel {
|
|
138
|
+
static func fromString(_ input: String) -> MaskLevel {
|
|
139
|
+
switch input.lowercased() {
|
|
140
|
+
case "light":
|
|
141
|
+
return .light
|
|
142
|
+
case "medium":
|
|
143
|
+
return .medium
|
|
144
|
+
case "conservative":
|
|
145
|
+
return .conservative
|
|
146
|
+
default:
|
|
147
|
+
return .medium
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|