mapp-intelligence-reactnative-plugin 1.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 +20 -0
- package/README.md +31 -0
- package/android/build.gradle +118 -0
- package/android/gradle.properties +7 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/mappinteligenceplugin/ConfigAdapter.kt +25 -0
- package/android/src/main/java/com/mappinteligenceplugin/MappinteligencePluginModule.kt +489 -0
- package/android/src/main/java/com/mappinteligenceplugin/MappinteligencePluginPackage.kt +23 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/ActionEventMapper.kt +26 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/CampaignActionMapper.kt +17 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/CampaignParametersMapper.kt +28 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/ECommerceParametersMapper.kt +59 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/EventParametersMapper.kt +17 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/ExceptionTypeMapper.kt +13 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/Mapper.kt +5 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/MediaEventMapper.kt +43 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/MediaParametersMapper.kt +29 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/PageParametersMapper.kt +23 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/ProductMapper.kt +29 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/SessionParametersMapper.kt +16 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/UserCategoriesMapper.kt +49 -0
- package/android/src/main/java/com/mappinteligenceplugin/mapper/Util.kt +75 -0
- package/ios/MappinteligencePlugin.h +11 -0
- package/ios/MappinteligencePlugin.mm +533 -0
- package/lib/commonjs/Converters.js +168 -0
- package/lib/commonjs/Converters.js.map +1 -0
- package/lib/commonjs/DataTypes.js +71 -0
- package/lib/commonjs/DataTypes.js.map +1 -0
- package/lib/commonjs/GlobalErrorHandler.js +51 -0
- package/lib/commonjs/GlobalErrorHandler.js.map +1 -0
- package/lib/commonjs/UseWebTracking.js +114 -0
- package/lib/commonjs/UseWebTracking.js.map +1 -0
- package/lib/commonjs/global.d.js +6 -0
- package/lib/commonjs/global.d.js.map +1 -0
- package/lib/commonjs/index.js +401 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/promiseRejectionHandler.js +50 -0
- package/lib/commonjs/promiseRejectionHandler.js.map +1 -0
- package/lib/module/Converters.js +155 -0
- package/lib/module/Converters.js.map +1 -0
- package/lib/module/DataTypes.js +65 -0
- package/lib/module/DataTypes.js.map +1 -0
- package/lib/module/GlobalErrorHandler.js +44 -0
- package/lib/module/GlobalErrorHandler.js.map +1 -0
- package/lib/module/UseWebTracking.js +107 -0
- package/lib/module/UseWebTracking.js.map +1 -0
- package/lib/module/global.d.js +4 -0
- package/lib/module/global.d.js.map +1 -0
- package/lib/module/index.js +321 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/promiseRejectionHandler.js +44 -0
- package/lib/module/promiseRejectionHandler.js.map +1 -0
- package/lib/typescript/src/Converters.d.ts +10 -0
- package/lib/typescript/src/Converters.d.ts.map +1 -0
- package/lib/typescript/src/DataTypes.d.ts +151 -0
- package/lib/typescript/src/DataTypes.d.ts.map +1 -0
- package/lib/typescript/src/GlobalErrorHandler.d.ts +3 -0
- package/lib/typescript/src/GlobalErrorHandler.d.ts.map +1 -0
- package/lib/typescript/src/UseWebTracking.d.ts +13 -0
- package/lib/typescript/src/UseWebTracking.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +201 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/promiseRejectionHandler.d.ts +3 -0
- package/lib/typescript/src/promiseRejectionHandler.d.ts.map +1 -0
- package/mapp-intelligence-reactnative-plugin.podspec +25 -0
- package/package.json +163 -0
- package/src/Converters.tsx +219 -0
- package/src/DataTypes.tsx +168 -0
- package/src/GlobalErrorHandler.tsx +58 -0
- package/src/UseWebTracking.tsx +135 -0
- package/src/global.d.ts +24 -0
- package/src/index.tsx +410 -0
- package/src/promiseRejectionHandler.tsx +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Mapp Digital
|
|
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,31 @@
|
|
|
1
|
+
# react-native-mappinteligence-plugin
|
|
2
|
+
|
|
3
|
+
The MappIntelligence SDK allows you to track user activities, screen flow and media usage for an App. All data is send to the MappIntelligence tracking system for further analysis.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install react-native-mappinteligence-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { multiply } from 'react-native-mappinteligence-plugin';
|
|
15
|
+
|
|
16
|
+
// ...
|
|
17
|
+
|
|
18
|
+
const result = await multiply(3, 7);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
MIT
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import com.android.Version
|
|
2
|
+
|
|
3
|
+
buildscript {
|
|
4
|
+
repositories {
|
|
5
|
+
flatDir {
|
|
6
|
+
dirs 'libs'
|
|
7
|
+
}
|
|
8
|
+
google()
|
|
9
|
+
mavenCentral()
|
|
10
|
+
maven {
|
|
11
|
+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
12
|
+
url "$rootDir/../node_modules/react-native/android"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
dependencies {
|
|
17
|
+
classpath("com.android.tools.build:gradle:8.3.2")
|
|
18
|
+
// noinspection DifferentKotlinGradleVersion
|
|
19
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
allprojects {
|
|
24
|
+
repositories {
|
|
25
|
+
google()
|
|
26
|
+
mavenLocal()
|
|
27
|
+
mavenCentral()
|
|
28
|
+
maven { url "https://maven.google.com/" }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def isNewArchitectureEnabled() {
|
|
33
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
apply plugin: "com.android.library"
|
|
37
|
+
apply plugin: "kotlin-android"
|
|
38
|
+
|
|
39
|
+
if (isNewArchitectureEnabled()) {
|
|
40
|
+
apply plugin: "com.facebook.react"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
44
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["MappinteligencePlugin_kotlinVersion"]
|
|
45
|
+
|
|
46
|
+
def getExtOrDefault(name) {
|
|
47
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["MappinteligencePlugin_" + name]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
def getExtOrIntegerDefault(name) {
|
|
51
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["MappinteligencePlugin_" + name]).toInteger()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static def supportsNamespace() {
|
|
55
|
+
def parsed = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
56
|
+
def major = parsed[0].toInteger()
|
|
57
|
+
def minor = parsed[1].toInteger()
|
|
58
|
+
|
|
59
|
+
// Namespace support was added in 7.3.0
|
|
60
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
android {
|
|
64
|
+
if (supportsNamespace()) {
|
|
65
|
+
namespace "com.mappinteligenceplugin"
|
|
66
|
+
|
|
67
|
+
sourceSets {
|
|
68
|
+
main {
|
|
69
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
75
|
+
|
|
76
|
+
defaultConfig {
|
|
77
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
78
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
buildTypes {
|
|
83
|
+
release {
|
|
84
|
+
minifyEnabled false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
lintOptions {
|
|
89
|
+
disable "GradleCompatible"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
compileOptions {
|
|
93
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
94
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
repositories {
|
|
99
|
+
mavenCentral()
|
|
100
|
+
google()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
dependencies {
|
|
105
|
+
// For < 0.71, this will be from the local maven repo
|
|
106
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
107
|
+
//noinspection GradleDynamicVersion
|
|
108
|
+
implementation('com.facebook.react:react-native:0.20.1')
|
|
109
|
+
implementation("androidx.annotation:annotation:1.8.2")
|
|
110
|
+
implementation("androidx.core:core-ktx:1.13.1")
|
|
111
|
+
|
|
112
|
+
implementation("androidx.appcompat:appcompat:1.7.0")
|
|
113
|
+
implementation("com.mapp.sdk:intelligence-android:5.1.10")
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
configurations.configureEach {
|
|
117
|
+
exclude(group: "com.android.support", module :"support-v4")
|
|
118
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.mappinteligenceplugin
|
|
2
|
+
|
|
3
|
+
import webtrekk.android.sdk.ExceptionType
|
|
4
|
+
import webtrekk.android.sdk.Logger
|
|
5
|
+
import webtrekk.android.sdk.data.model.GenerationMode
|
|
6
|
+
|
|
7
|
+
data class ConfigAdapter(
|
|
8
|
+
var trackIds: List<String> = emptyList(),
|
|
9
|
+
var trackDomain: String = "",
|
|
10
|
+
var anonymousTracking: Boolean = false,
|
|
11
|
+
var logLevel: Logger.Level = Logger.Level.NONE,
|
|
12
|
+
var requestsIntervalMinutes: Int = 15,
|
|
13
|
+
var autoTracking: Boolean = true,
|
|
14
|
+
var fragmentsAutoTracking: Boolean = true,
|
|
15
|
+
var requestPerBatch: Int = 1000,
|
|
16
|
+
var batchSupport: Boolean = false,
|
|
17
|
+
var activityAutoTracking: Boolean = true,
|
|
18
|
+
var exceptionLogLevel: ExceptionType = ExceptionType.NONE,
|
|
19
|
+
var shouldMigrate: Boolean = false,
|
|
20
|
+
var versionInEachRequest: Boolean = false,
|
|
21
|
+
var everId: String? = null,
|
|
22
|
+
var userMatchingEnabled: Boolean = false,
|
|
23
|
+
var temporarySessionId:String="",
|
|
24
|
+
var everIdMode: GenerationMode? = GenerationMode.AUTO_GENERATED,
|
|
25
|
+
)
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
package com.mappinteligenceplugin
|
|
2
|
+
|
|
3
|
+
import android.net.Uri
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import androidx.annotation.IntRange
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod
|
|
10
|
+
import com.facebook.react.bridge.ReadableArray
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap
|
|
12
|
+
import com.mappinteligenceplugin.mapper.CampaignParametersMapper
|
|
13
|
+
import com.mappinteligenceplugin.mapper.ECommerceParametersMapper
|
|
14
|
+
import com.mappinteligenceplugin.mapper.EventParametersMapper
|
|
15
|
+
import com.mappinteligenceplugin.mapper.ExceptionTypeMapper
|
|
16
|
+
import com.mappinteligenceplugin.mapper.MediaEventMapper
|
|
17
|
+
import com.mappinteligenceplugin.mapper.PageParametersMapper
|
|
18
|
+
import com.mappinteligenceplugin.mapper.SessionParametersMapper
|
|
19
|
+
import com.mappinteligenceplugin.mapper.UserCategoriesMapper
|
|
20
|
+
import com.mappinteligenceplugin.mapper.Util.toMap
|
|
21
|
+
import webtrekk.android.sdk.Logger
|
|
22
|
+
import webtrekk.android.sdk.Webtrekk
|
|
23
|
+
import webtrekk.android.sdk.WebtrekkConfiguration
|
|
24
|
+
import webtrekk.android.sdk.events.ActionEvent
|
|
25
|
+
import webtrekk.android.sdk.events.PageViewEvent
|
|
26
|
+
import java.util.concurrent.TimeUnit
|
|
27
|
+
|
|
28
|
+
class MappinteligencePluginModule(private val reactContext: ReactApplicationContext) :
|
|
29
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
30
|
+
|
|
31
|
+
private lateinit var instance: Webtrekk
|
|
32
|
+
private val configAdapter = ConfigAdapter()
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initialize native SDK with the provided trackIds and trackDomain and with the default other parameters
|
|
36
|
+
*/
|
|
37
|
+
@ReactMethod
|
|
38
|
+
fun initWithConfiguration(trackIds: ReadableArray, trackDomain: String, promise: Promise) {
|
|
39
|
+
val trackValues = mutableListOf<Double?>()
|
|
40
|
+
for (i in 0 until trackIds.size()) {
|
|
41
|
+
trackValues.add(trackIds.getDouble(i))
|
|
42
|
+
}
|
|
43
|
+
val ids = trackValues.mapNotNull { it?.toBigDecimal()?.toPlainString() }
|
|
44
|
+
runOnPlugin(whenInitialized = {
|
|
45
|
+
instance.setIdsAndDomain(ids, trackDomain)
|
|
46
|
+
}, whenNotInitialized = {
|
|
47
|
+
configAdapter.trackIds = ids
|
|
48
|
+
configAdapter.trackDomain = trackDomain
|
|
49
|
+
})
|
|
50
|
+
promise.resolve(true)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if SDK is initialized and ready for usage
|
|
55
|
+
* Returns true if initialization was finished, otherwise false
|
|
56
|
+
*/
|
|
57
|
+
@ReactMethod
|
|
58
|
+
fun isInitialized(promise: Promise) {
|
|
59
|
+
runOnPlugin(whenInitialized = {
|
|
60
|
+
promise.resolve(true)
|
|
61
|
+
}, whenNotInitialized = {
|
|
62
|
+
promise.resolve(false)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Enable or disable anonymous tracking
|
|
68
|
+
* When anonymous tracking is enabled, everId will be deleted and not created again while this value stays true
|
|
69
|
+
*/
|
|
70
|
+
@ReactMethod
|
|
71
|
+
fun setAnonymousTracking(enabled: Boolean, promise: Promise) {
|
|
72
|
+
runOnPlugin(
|
|
73
|
+
whenInitialized = {
|
|
74
|
+
instance.anonymousTracking(enabled)
|
|
75
|
+
}, whenNotInitialized = {
|
|
76
|
+
configAdapter.anonymousTracking = enabled
|
|
77
|
+
})
|
|
78
|
+
promise.resolve(true)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Enable or disable sending appVersion parameter with a every request
|
|
83
|
+
*/
|
|
84
|
+
@ReactMethod
|
|
85
|
+
fun setSendAppVersionInEveryRequest(enabled: Boolean, promise: Promise) {
|
|
86
|
+
runOnPlugin(whenInitialized = {
|
|
87
|
+
instance.setVersionInEachRequest(enabled)
|
|
88
|
+
}, whenNotInitialized = {
|
|
89
|
+
configAdapter.versionInEachRequest = enabled
|
|
90
|
+
})
|
|
91
|
+
promise.resolve(true)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Enable or disable user matching option
|
|
96
|
+
* User matching provides connection between users on Engage and Intelligence systems
|
|
97
|
+
*/
|
|
98
|
+
@ReactMethod
|
|
99
|
+
fun setEnableUserMatching(enabled: Boolean, promise: Promise) {
|
|
100
|
+
runOnPlugin(whenInitialized = {
|
|
101
|
+
instance.setUserMatchingEnabled(enabled)
|
|
102
|
+
}, whenNotInitialized = {
|
|
103
|
+
configAdapter.userMatchingEnabled = enabled
|
|
104
|
+
})
|
|
105
|
+
promise.resolve(true)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set custom everId
|
|
110
|
+
* If null or empty string passed, everId will be autogenerated
|
|
111
|
+
* <b>It has effect only if anonymous tracking is disabled</b>
|
|
112
|
+
*/
|
|
113
|
+
@ReactMethod
|
|
114
|
+
fun setEverId(everId: String?, promise: Promise) {
|
|
115
|
+
runOnPlugin(whenInitialized = {
|
|
116
|
+
instance.setEverId(everId)
|
|
117
|
+
}, whenNotInitialized = {
|
|
118
|
+
configAdapter.everId = everId
|
|
119
|
+
})
|
|
120
|
+
promise.resolve(true)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@ReactMethod
|
|
124
|
+
fun getEverId(promise: Promise) {
|
|
125
|
+
runOnPlugin(whenInitialized = {
|
|
126
|
+
val everId = instance.getEverId()
|
|
127
|
+
promise.resolve(everId)
|
|
128
|
+
}, whenNotInitialized = {
|
|
129
|
+
promise.reject("", "SDK not initialized yet!")
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@ReactMethod
|
|
134
|
+
fun setTemporarySessionId(sessionId: String, promise: Promise) {
|
|
135
|
+
runOnPlugin(whenInitialized = {
|
|
136
|
+
instance.setTemporarySessionId(sessionId)
|
|
137
|
+
}, whenNotInitialized = {
|
|
138
|
+
configAdapter.temporarySessionId = sessionId
|
|
139
|
+
})
|
|
140
|
+
promise.resolve(true)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@ReactMethod
|
|
144
|
+
fun optOut(sendData: Boolean, promise: Promise) {
|
|
145
|
+
runOnPlugin(whenInitialized = {
|
|
146
|
+
instance.optOut(true, sendData)
|
|
147
|
+
})
|
|
148
|
+
promise.resolve(true)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
fun optIn(sendData: Boolean, promise: Promise) {
|
|
153
|
+
runOnPlugin(whenInitialized = {
|
|
154
|
+
instance.optOut(false, sendData)
|
|
155
|
+
})
|
|
156
|
+
promise.resolve(true)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@ReactMethod
|
|
160
|
+
fun setExceptionLogLevel(exceptionLevel: Double, promise: Promise) {
|
|
161
|
+
val exceptionType = ExceptionTypeMapper(exceptionLevel).getData()
|
|
162
|
+
runOnPlugin(whenInitialized = {
|
|
163
|
+
instance.setExceptionLogLevel(exceptionType)
|
|
164
|
+
}, whenNotInitialized = {
|
|
165
|
+
configAdapter.exceptionLogLevel = exceptionType
|
|
166
|
+
})
|
|
167
|
+
promise.resolve(true)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Sets log level for a library. Disable or enable logs in the logcat from the intelligence SDK and it's plugin
|
|
172
|
+
*/
|
|
173
|
+
@ReactMethod
|
|
174
|
+
fun setLogLevel(level: Int, promise: Promise) {
|
|
175
|
+
val nativeLevel = if (level == 7) {
|
|
176
|
+
Logger.Level.NONE
|
|
177
|
+
} else {
|
|
178
|
+
Logger.Level.BASIC
|
|
179
|
+
}
|
|
180
|
+
runOnPlugin(whenInitialized = {
|
|
181
|
+
instance.setLogLevel(nativeLevel)
|
|
182
|
+
}, whenNotInitialized = {
|
|
183
|
+
configAdapter.logLevel = nativeLevel
|
|
184
|
+
})
|
|
185
|
+
promise.resolve(true)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Enable or disable sending requests in a batch
|
|
191
|
+
* When enabled, multiple track records are send via single Http request
|
|
192
|
+
*/
|
|
193
|
+
@ReactMethod
|
|
194
|
+
fun setBatchSupportEnabled(enabled: Boolean, promise: Promise) {
|
|
195
|
+
runOnPlugin(whenInitialized = {
|
|
196
|
+
instance.setBatchEnabled(enabled)
|
|
197
|
+
}, whenNotInitialized = {
|
|
198
|
+
configAdapter.batchSupport = enabled
|
|
199
|
+
})
|
|
200
|
+
promise.resolve(true)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Sets the number of records to be send in a single network request.
|
|
205
|
+
* Value must be in the defined range for size
|
|
206
|
+
*/
|
|
207
|
+
@ReactMethod
|
|
208
|
+
fun setBatchSupportSize(
|
|
209
|
+
@IntRange size: Int, promise: Promise
|
|
210
|
+
) {
|
|
211
|
+
runOnPlugin(
|
|
212
|
+
whenInitialized = {
|
|
213
|
+
instance.setRequestPerBatch(size)
|
|
214
|
+
}, whenNotInitialized = {
|
|
215
|
+
configAdapter.requestPerBatch = size
|
|
216
|
+
})
|
|
217
|
+
promise.resolve(true)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Sets time interval, in minutes, for a job of automatic sending of the tracking records
|
|
222
|
+
* Minimum value is 15 minutes, limited by Android OS.
|
|
223
|
+
*/
|
|
224
|
+
@ReactMethod
|
|
225
|
+
fun setRequestInterval(
|
|
226
|
+
@IntRange(from = 15) interval: Int, promise: Promise
|
|
227
|
+
) {
|
|
228
|
+
runOnPlugin(
|
|
229
|
+
whenInitialized = {
|
|
230
|
+
instance.setRequestInterval(interval.toLong())
|
|
231
|
+
}, whenNotInitialized = {
|
|
232
|
+
configAdapter.requestsIntervalMinutes = interval
|
|
233
|
+
})
|
|
234
|
+
promise.resolve(true)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* This operation is not supported on android
|
|
239
|
+
* Method exists only for compatibility
|
|
240
|
+
*/
|
|
241
|
+
@ReactMethod
|
|
242
|
+
fun setRequestPerQueue(queue: Int, promise: Promise) {
|
|
243
|
+
promise.resolve(true)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Enable or disable migration from previous version of a native SDK
|
|
248
|
+
* React Native plugin was not developed with a older version (v4) of the native plugin,
|
|
249
|
+
* so migration for this plugin will always stay false.
|
|
250
|
+
*/
|
|
251
|
+
@ReactMethod
|
|
252
|
+
fun setShouldMigrate(migrate: Boolean, promise: Promise) {
|
|
253
|
+
runOnPlugin(
|
|
254
|
+
whenInitialized = {
|
|
255
|
+
if (migrate) {
|
|
256
|
+
reset { it.enableMigration() }
|
|
257
|
+
}
|
|
258
|
+
}, whenNotInitialized = {
|
|
259
|
+
configAdapter.shouldMigrate = migrate
|
|
260
|
+
})
|
|
261
|
+
promise.resolve(true)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Required only for iOS;
|
|
266
|
+
* Method just returns success and exist only for compatibility
|
|
267
|
+
*/
|
|
268
|
+
@ReactMethod
|
|
269
|
+
fun setEnableBackgroundSendout(enabled: Boolean, promise: Promise) {
|
|
270
|
+
promise.resolve(true)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
@ReactMethod
|
|
274
|
+
fun trackCustomPage(
|
|
275
|
+
pageTitle: String,
|
|
276
|
+
pageParams: ReadableMap?,
|
|
277
|
+
sessionParams: ReadableMap?,
|
|
278
|
+
userCategoryParams: ReadableMap?,
|
|
279
|
+
ecommerceParams: ReadableMap?,
|
|
280
|
+
campaignParams: ReadableMap?,
|
|
281
|
+
promise: Promise
|
|
282
|
+
) {
|
|
283
|
+
runOnPlugin(
|
|
284
|
+
whenInitialized = {
|
|
285
|
+
val page = PageParametersMapper(pageParams).getData()
|
|
286
|
+
val session = SessionParametersMapper(sessionParams).getData()
|
|
287
|
+
val userCat = UserCategoriesMapper(userCategoryParams).getData()
|
|
288
|
+
val ecommerce = ECommerceParametersMapper(ecommerceParams).getData()
|
|
289
|
+
val campaign = CampaignParametersMapper(campaignParams).getData()
|
|
290
|
+
|
|
291
|
+
val pageViewEvent = PageViewEvent(pageTitle).apply {
|
|
292
|
+
this.pageParameters = page
|
|
293
|
+
this.sessionParameters = session
|
|
294
|
+
this.userCategories = userCat
|
|
295
|
+
this.eCommerceParameters = ecommerce
|
|
296
|
+
this.campaignParameters = campaign
|
|
297
|
+
}
|
|
298
|
+
instance.trackPage(pageViewEvent)
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
promise.resolve(true)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Track page with a provided [PageViewEvent]
|
|
306
|
+
*/
|
|
307
|
+
@ReactMethod
|
|
308
|
+
fun trackPageWithCustomData(params: ReadableMap?, pageTitle: String, promise: Promise) {
|
|
309
|
+
runOnPlugin(whenInitialized = {
|
|
310
|
+
instance.trackCustomPage(pageTitle, params.toMap(keyTransform = {it.toString()}))
|
|
311
|
+
})
|
|
312
|
+
promise.resolve(true)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
@ReactMethod
|
|
316
|
+
fun trackPage(pageTitle: String, promise: Promise) {
|
|
317
|
+
runOnPlugin(whenInitialized = {
|
|
318
|
+
instance.trackPage(PageViewEvent(pageTitle))
|
|
319
|
+
})
|
|
320
|
+
promise.resolve(true)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
@ReactMethod
|
|
324
|
+
fun sendRequestsAndClean(promise: Promise) {
|
|
325
|
+
runOnPlugin(
|
|
326
|
+
whenInitialized = {
|
|
327
|
+
instance.sendRequestsNowAndClean()
|
|
328
|
+
})
|
|
329
|
+
promise.resolve(true)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@ReactMethod
|
|
333
|
+
fun trackAction(
|
|
334
|
+
name: String,
|
|
335
|
+
eventParameters: ReadableMap?,
|
|
336
|
+
sessionParameters: ReadableMap?,
|
|
337
|
+
userCategories: ReadableMap?,
|
|
338
|
+
eCommerceParameters: ReadableMap?,
|
|
339
|
+
campaignParameters: ReadableMap?,
|
|
340
|
+
promise: Promise
|
|
341
|
+
) {
|
|
342
|
+
runOnPlugin(
|
|
343
|
+
whenInitialized = {
|
|
344
|
+
val event = EventParametersMapper(eventParameters).getData()
|
|
345
|
+
val session = SessionParametersMapper(sessionParameters).getData()
|
|
346
|
+
val userCat = UserCategoriesMapper(userCategories).getData()
|
|
347
|
+
val ecommerce = ECommerceParametersMapper(eCommerceParameters).getData()
|
|
348
|
+
val campaignParams = CampaignParametersMapper(campaignParameters).getData()
|
|
349
|
+
val actionEvent = ActionEvent(name).apply {
|
|
350
|
+
this.eventParameters = event
|
|
351
|
+
this.sessionParameters = session
|
|
352
|
+
this.userCategories = userCat
|
|
353
|
+
this.eCommerceParameters = ecommerce
|
|
354
|
+
this.campaignParameters = campaignParams
|
|
355
|
+
}
|
|
356
|
+
instance.trackAction(actionEvent)
|
|
357
|
+
})
|
|
358
|
+
promise.resolve(true)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
@ReactMethod
|
|
362
|
+
fun trackException(exception: ReadableMap, promise: Promise) {
|
|
363
|
+
runOnPlugin(
|
|
364
|
+
whenInitialized = {
|
|
365
|
+
val innerException = Exception(exception.getString("message"))
|
|
366
|
+
instance.trackException(innerException)
|
|
367
|
+
|
|
368
|
+
})
|
|
369
|
+
promise.resolve(true)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@ReactMethod
|
|
373
|
+
fun trackMedia(readableMap: ReadableMap?, promise: Promise) {
|
|
374
|
+
runOnPlugin(whenInitialized = {
|
|
375
|
+
MediaEventMapper(readableMap).getData()?.let {
|
|
376
|
+
instance.trackMedia(it)
|
|
377
|
+
}
|
|
378
|
+
})
|
|
379
|
+
promise.resolve(true)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@ReactMethod
|
|
383
|
+
fun trackUrl(url: String, mediaCode: String?, promise: Promise) {
|
|
384
|
+
runOnPlugin(
|
|
385
|
+
whenInitialized = {
|
|
386
|
+
instance.trackUrl(Uri.parse(url), mediaCode)
|
|
387
|
+
})
|
|
388
|
+
promise.resolve(true)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
@ReactMethod
|
|
392
|
+
fun trackException(name: String, message: String, stacktrace: String? = null, promise: Promise) {
|
|
393
|
+
runOnPlugin(whenInitialized = {
|
|
394
|
+
Log.d("MappIntelligencePlugin", "trackException")
|
|
395
|
+
if (stacktrace.isNullOrEmpty()) {
|
|
396
|
+
instance.trackException(name, message)
|
|
397
|
+
} else {
|
|
398
|
+
instance.trackException(name, message + "\n${stacktrace}")
|
|
399
|
+
}
|
|
400
|
+
})
|
|
401
|
+
promise.resolve(true)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Configure webtrekk SDK and initialize it
|
|
406
|
+
*/
|
|
407
|
+
@ReactMethod
|
|
408
|
+
fun build(promise: Promise) {
|
|
409
|
+
runOnPlugin(whenNotInitialized = {
|
|
410
|
+
val builder = WebtrekkConfiguration.Builder(configAdapter.trackIds, configAdapter.trackDomain)
|
|
411
|
+
.logLevel(configAdapter.logLevel)
|
|
412
|
+
.enableCrashTracking(configAdapter.exceptionLogLevel)
|
|
413
|
+
.setBatchSupport(configAdapter.batchSupport, configAdapter.requestPerBatch)
|
|
414
|
+
.requestsInterval(TimeUnit.MINUTES, configAdapter.requestsIntervalMinutes.toLong())
|
|
415
|
+
.setEverId(configAdapter.everId)
|
|
416
|
+
.sendAppVersionInEveryRequest(configAdapter.versionInEachRequest)
|
|
417
|
+
|
|
418
|
+
if (configAdapter.shouldMigrate) builder.enableMigration()
|
|
419
|
+
|
|
420
|
+
if (!configAdapter.autoTracking) builder.disableAutoTracking()
|
|
421
|
+
|
|
422
|
+
if (!configAdapter.activityAutoTracking) builder.disableActivityAutoTracking()
|
|
423
|
+
|
|
424
|
+
if (!configAdapter.fragmentsAutoTracking) builder.disableFragmentsAutoTracking()
|
|
425
|
+
|
|
426
|
+
Webtrekk.getInstance().init(reactContext.applicationContext, builder.build())
|
|
427
|
+
|
|
428
|
+
instance = Webtrekk.getInstance().apply {
|
|
429
|
+
this.anonymousTracking(configAdapter.anonymousTracking)
|
|
430
|
+
this.setTemporarySessionId(configAdapter.temporarySessionId)
|
|
431
|
+
}
|
|
432
|
+
}, whenInitialized = {})
|
|
433
|
+
promise.resolve(true)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Helper function to execute actions based on Webtrekk instance state
|
|
438
|
+
* Provide two functions as input parameters to be executed if instance is initialized or not
|
|
439
|
+
*/
|
|
440
|
+
private fun runOnPlugin(whenInitialized: () -> Unit, whenNotInitialized: (() -> Unit)? = null) {
|
|
441
|
+
if (::instance.isInitialized) whenInitialized.invoke()
|
|
442
|
+
else whenNotInitialized?.invoke()
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
@ReactMethod
|
|
446
|
+
private fun reset(promise: Promise) {
|
|
447
|
+
runOnPlugin(whenInitialized = {
|
|
448
|
+
reset { }
|
|
449
|
+
})
|
|
450
|
+
promise.resolve(true)
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Reset underlying SDK and set new values via
|
|
455
|
+
* @param presetAction - action that has access to WebtrekkConfiguration Builder
|
|
456
|
+
* to change existing configuration and set new values
|
|
457
|
+
*/
|
|
458
|
+
private fun reset(presetAction: (WebtrekkConfiguration.Builder) -> Unit) {
|
|
459
|
+
Webtrekk.reset(reactContext.applicationContext)
|
|
460
|
+
val trackIds = configAdapter.trackIds
|
|
461
|
+
val domain = configAdapter.trackDomain
|
|
462
|
+
|
|
463
|
+
instance.setIdsAndDomain(trackIds,domain)
|
|
464
|
+
// This requires some changes on native SDK
|
|
465
|
+
// val builder = WebtrekkConfiguration.Builder(trackIds, domain)
|
|
466
|
+
// presetAction.invoke(builder)
|
|
467
|
+
// val config = builder.build()
|
|
468
|
+
// Webtrekk.getInstance().init(reactContext.applicationContext, config = config)
|
|
469
|
+
// instance = Webtrekk.getInstance()
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
@ReactMethod
|
|
473
|
+
fun getCurrentConfig(promise: Promise) {
|
|
474
|
+
runOnPlugin(whenInitialized = {
|
|
475
|
+
val config = Webtrekk.getInstance().getCurrentConfiguration()
|
|
476
|
+
promise.resolve(config.toString())
|
|
477
|
+
}, whenNotInitialized = {
|
|
478
|
+
promise.resolve("")
|
|
479
|
+
})
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
override fun getName(): String {
|
|
483
|
+
return NAME
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
companion object {
|
|
487
|
+
const val NAME = "MappinteligencePlugin"
|
|
488
|
+
}
|
|
489
|
+
}
|