@screeb/react-native 1.0.0-rc.2 → 2.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/android/.gradle/7.6/checksums/checksums.lock +0 -0
- package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.6/gc.properties +0 -0
- package/android/.gradle/7.6.2/checksums/checksums.lock +0 -0
- package/android/.gradle/7.6.2/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.6.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.6.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.6.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.6.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.6.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.6.2/gc.properties +0 -0
- package/android/.gradle/8.0/checksums/checksums.lock +0 -0
- package/android/.gradle/8.0/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.0/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.0/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.0/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.0/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +2 -2
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/main/java/com/screebmodule/ScreebModuleModule.kt +42 -4
- package/ios/ScreebModule.m +5 -4
- package/ios/ScreebModule.swift +33 -6
- package/lib/commonjs/index.js +111 -0
- package/lib/module/index.js +96 -0
- package/lib/typescript/index.d.ts +12 -0
- package/package.json +1 -1
- package/screeb-module.podspec +1 -1
- package/src/index.tsx +100 -24
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
package/android/build.gradle
CHANGED
|
@@ -123,6 +123,6 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
|
123
123
|
dependencies {
|
|
124
124
|
// noinspection GradleDynamicVersion
|
|
125
125
|
api 'com.facebook.react:react-native:+'
|
|
126
|
-
implementation "app.screeb.sdk:survey:2.0.
|
|
127
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.
|
|
126
|
+
implementation "app.screeb.sdk:survey:2.0.1"
|
|
127
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22"
|
|
128
128
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
|
4
3
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
4
|
zipStorePath=wrapper/dists
|
|
5
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-all.zip
|
|
@@ -5,6 +5,10 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
|
5
5
|
import com.facebook.react.bridge.ReactMethod
|
|
6
6
|
import com.facebook.react.bridge.Promise
|
|
7
7
|
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.facebook.react.bridge.ReadableArray
|
|
9
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
10
|
+
import com.facebook.react.bridge.Arguments
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
8
12
|
import java.util.HashMap
|
|
9
13
|
import androidx.annotation.NonNull
|
|
10
14
|
import android.content.Context
|
|
@@ -21,14 +25,31 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
|
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
@ReactMethod
|
|
24
|
-
fun initSdk(channelId: String, userId: String?, properties: ReadableMap?) {
|
|
28
|
+
fun initSdk(channelId: String, userId: String?, properties: ReadableMap?, hooks: ReadableMap?) {
|
|
25
29
|
Log.d("ScreebModule", "Called initSdk : $userId")
|
|
26
30
|
var map: HashMap<String, Any?>? = null
|
|
27
31
|
if (properties != null) {
|
|
28
32
|
map = properties.toHashMap()
|
|
29
33
|
}
|
|
34
|
+
var mapHooks:HashMap<String, Any>? = null
|
|
35
|
+
if (hooks != null) {
|
|
36
|
+
mapHooks = hashMapOf<String, Any>()
|
|
37
|
+
val hooksKeys = hooks.keySetIterator()
|
|
38
|
+
while (hooksKeys.hasNextKey()) {
|
|
39
|
+
val key = hooksKeys.nextKey()
|
|
40
|
+
val value = hooks.getString(key)
|
|
41
|
+
if (key == "version"){
|
|
42
|
+
mapHooks[key] = value!!
|
|
43
|
+
} else {
|
|
44
|
+
mapHooks[key] = { payload:Any -> this.reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit("ScreebEvent", Arguments.createMap().apply {
|
|
45
|
+
putString("hookId", value!!)
|
|
46
|
+
putString("payload", payload.toString())
|
|
47
|
+
}) }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
30
51
|
Handler(Looper.getMainLooper()).post {
|
|
31
|
-
Screeb.pluginInit(channelId, userId, map)
|
|
52
|
+
Screeb.pluginInit(channelId, userId, map, mapHooks)
|
|
32
53
|
}
|
|
33
54
|
}
|
|
34
55
|
|
|
@@ -104,14 +125,31 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
|
|
|
104
125
|
}
|
|
105
126
|
|
|
106
127
|
@ReactMethod
|
|
107
|
-
fun startSurvey(surveyId: String, allowMultipleResponses: Boolean? = true, hiddenFields: ReadableMap? = null, ignoreSurveyStatus: Boolean? = true) {
|
|
128
|
+
fun startSurvey(surveyId: String, allowMultipleResponses: Boolean? = true, hiddenFields: ReadableMap? = null, ignoreSurveyStatus: Boolean? = true, hooks: ReadableMap? = null) {
|
|
108
129
|
Log.e("ScreebModule", "Called startSurvey : $surveyId")
|
|
109
130
|
var map: HashMap<String, Any>? = null
|
|
110
131
|
if (hiddenFields != null) {
|
|
111
132
|
map = hiddenFields.toHashMap()
|
|
112
133
|
}
|
|
134
|
+
var mapHooks:HashMap<String, Any>? = null
|
|
135
|
+
if (hooks != null) {
|
|
136
|
+
mapHooks = hashMapOf<String, Any>()
|
|
137
|
+
val hooksKeys = hooks.keySetIterator()
|
|
138
|
+
while (hooksKeys.hasNextKey()) {
|
|
139
|
+
val key = hooksKeys.nextKey()
|
|
140
|
+
val value = hooks.getString(key)
|
|
141
|
+
if (key == "version"){
|
|
142
|
+
mapHooks[key] = value!!
|
|
143
|
+
} else {
|
|
144
|
+
mapHooks[key] = { payload:Any -> this.reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit("ScreebEvent", Arguments.createMap().apply {
|
|
145
|
+
putString("hookId", value!!)
|
|
146
|
+
putString("payload", payload.toString())
|
|
147
|
+
}) }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
113
151
|
Handler(Looper.getMainLooper()).post {
|
|
114
|
-
Screeb.startSurvey(surveyId, allowMultipleResponses ?: true, map, ignoreSurveyStatus ?: true)
|
|
152
|
+
Screeb.startSurvey(surveyId, allowMultipleResponses ?: true, map, ignoreSurveyStatus ?: true, mapHooks)
|
|
115
153
|
}
|
|
116
154
|
}
|
|
117
155
|
|
package/ios/ScreebModule.m
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
2
3
|
|
|
3
|
-
@interface RCT_EXTERN_MODULE(ScreebModule,
|
|
4
|
+
@interface RCT_EXTERN_MODULE(ScreebModule, RCTEventEmitter)
|
|
4
5
|
|
|
5
|
-
RCT_EXTERN_METHOD(initSdk:(NSString *)channelId userId:(NSString *)userId_ properties:(NSDictionary<NSString *, id> *)properties_)
|
|
6
|
+
RCT_EXTERN_METHOD(initSdk:(NSString *)channelId userId:(NSString *)userId_ properties:(NSDictionary<NSString *, id> *)properties_ hooks:(NSDictionary<NSString *, id> *)hooks_)
|
|
6
7
|
RCT_EXTERN_METHOD(setIdentity:(NSString *)userId properties:(NSDictionary<NSString *, id> *)properties_)
|
|
7
8
|
RCT_EXTERN_METHOD(setProperties:(NSDictionary<NSString *, id> *)properties)
|
|
8
9
|
RCT_EXTERN_METHOD(assignGroup:(NSString *)type name:(NSString *)name_ properties:(NSDictionary<NSString *, id> *)properties_)
|
|
9
10
|
RCT_EXTERN_METHOD(unassignGroup:(NSString *)type name:(NSString *)name_ properties:(NSDictionary<NSString *, id> *)properties_)
|
|
10
11
|
RCT_EXTERN_METHOD(trackEvent:(NSString *)eventId properties:(NSDictionary<NSString *, id> *)properties_)
|
|
11
12
|
RCT_EXTERN_METHOD(trackScreen:(NSString *)screen properties:(NSDictionary<NSString *, id> *)properties_)
|
|
12
|
-
RCT_EXTERN_METHOD(startSurvey:(NSString *)surveyId allowMultipleResponses:(BOOL)allowMultipleResponses_ hiddenFields:(NSDictionary<NSString *, id> *)hiddenFields_ ignoreSurveyStatus:(BOOL)ignoreSurveyStatus_)
|
|
13
|
+
RCT_EXTERN_METHOD(startSurvey:(NSString *)surveyId allowMultipleResponses:(BOOL)allowMultipleResponses_ hiddenFields:(NSDictionary<NSString *, id> *)hiddenFields_ ignoreSurveyStatus:(BOOL)ignoreSurveyStatus_ hooks:(NSDictionary<NSString *, id> *)hooks_)
|
|
13
14
|
RCT_EXTERN_METHOD(debug)
|
|
14
15
|
RCT_EXTERN_METHOD(debugTargeting)
|
|
15
16
|
RCT_EXTERN_METHOD(closeSdk)
|
|
@@ -18,4 +19,4 @@ RCT_EXTERN_METHOD(resetIdentity)
|
|
|
18
19
|
{
|
|
19
20
|
return YES;
|
|
20
21
|
}
|
|
21
|
-
@end
|
|
22
|
+
@end
|
package/ios/ScreebModule.swift
CHANGED
|
@@ -3,20 +3,32 @@ import UIKit
|
|
|
3
3
|
import Foundation
|
|
4
4
|
|
|
5
5
|
@objc(ScreebModule)
|
|
6
|
-
class ScreebModule:
|
|
6
|
+
class ScreebModule: RCTEventEmitter {
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
@objc(initSdk:userId:properties:hooks:)
|
|
9
9
|
func initSdk(
|
|
10
10
|
_ channelId: String,
|
|
11
11
|
userId userId_: String?,
|
|
12
|
-
properties properties_: [String: Any]
|
|
12
|
+
properties properties_: [String: Any]?,
|
|
13
|
+
hooks hooks_: [String: Any]?) {
|
|
13
14
|
var map: [String: AnyEncodable?] = [:]
|
|
14
15
|
if (properties_ != nil) {
|
|
15
16
|
map = self.mapToAnyEncodable(map: properties_!)
|
|
16
17
|
}
|
|
18
|
+
var mapHooks: [String: Any?]? = nil
|
|
19
|
+
if (hooks_ != nil) {
|
|
20
|
+
mapHooks = [:]
|
|
21
|
+
hooks_?.forEach{ hook in
|
|
22
|
+
if(hook.key == "version"){
|
|
23
|
+
mapHooks![hook.key] = hook.value as? String
|
|
24
|
+
} else {
|
|
25
|
+
mapHooks![hook.key] = {(payload:Any) -> () in self.sendEvent(withName: "ScreebEvent", body: ["hookId":hook.value,"payload":String(describing: payload)]) }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
17
29
|
if let controller = UIApplication.shared.keyWindow?.rootViewController {
|
|
18
30
|
DispatchQueue.main.async {
|
|
19
|
-
Screeb.initSdk(context: controller, channelId: channelId, identity: userId_, visitorProperty: map)
|
|
31
|
+
Screeb.initSdk(context: controller, channelId: channelId, identity: userId_, visitorProperty: map, hooks: mapHooks)
|
|
20
32
|
}
|
|
21
33
|
} else {
|
|
22
34
|
print("Screeb : error init, could not find rootViewController")
|
|
@@ -61,13 +73,24 @@ class ScreebModule: NSObject {
|
|
|
61
73
|
}
|
|
62
74
|
}
|
|
63
75
|
|
|
64
|
-
@objc func startSurvey(_ surveyId: String, allowMultipleResponses allowMultipleResponses_: Bool, hiddenFields hiddenFields_: [String: Any]?,ignoreSurveyStatus ignoreSurveyStatus_: Bool) {
|
|
76
|
+
@objc func startSurvey(_ surveyId: String, allowMultipleResponses allowMultipleResponses_: Bool, hiddenFields hiddenFields_: [String: Any]?,ignoreSurveyStatus ignoreSurveyStatus_: Bool, hooks hooks_: [String: Any]?) {
|
|
65
77
|
var map: [String: AnyEncodable] = [:]
|
|
66
78
|
if (hiddenFields_ != nil) {
|
|
67
79
|
map = self.mapToAnyEncodable(map: hiddenFields_!).filter({ $0.value != nil }).mapValues({ $0! })
|
|
68
80
|
}
|
|
81
|
+
var mapHooks: [String: Any?]? = nil
|
|
82
|
+
if (hooks_ != nil) {
|
|
83
|
+
mapHooks = [:]
|
|
84
|
+
hooks_?.forEach{ hook in
|
|
85
|
+
if(hook.key == "version"){
|
|
86
|
+
mapHooks![hook.key] = hook.value as? String
|
|
87
|
+
} else {
|
|
88
|
+
mapHooks![hook.key] = {(payload:Any) -> () in self.sendEvent(withName: "ScreebEvent", body: ["hookId":hook.value,"payload":String(describing: payload)]) }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
69
92
|
DispatchQueue.main.async {
|
|
70
|
-
|
|
93
|
+
Screeb.startSurvey(surveyId: surveyId, allowMultipleResponses: allowMultipleResponses_, hiddenFields: map, ignoreSurveyStatus: ignoreSurveyStatus_, hooks: mapHooks)
|
|
71
94
|
}
|
|
72
95
|
}
|
|
73
96
|
|
|
@@ -132,4 +155,8 @@ class ScreebModule: NSObject {
|
|
|
132
155
|
return nil
|
|
133
156
|
}
|
|
134
157
|
}
|
|
158
|
+
|
|
159
|
+
override func supportedEvents() -> [String]! {
|
|
160
|
+
return ["ScreebEvent"]
|
|
161
|
+
}
|
|
135
162
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.closeSdk = exports.resetIdentity = exports.debugTargeting = exports.debug = exports.startSurvey = exports.trackScreen = exports.trackEvent = exports.unassignGroup = exports.assignGroup = exports.setProperties = exports.setIdentity = exports.initSdk = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const LINKING_ERROR = `The package '@screeb/react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
6
|
+
react_native_1.Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
7
|
+
"- You rebuilt the app after installing the package\n" +
|
|
8
|
+
"- You are not using Expo managed workflow\n";
|
|
9
|
+
const ScreebModule = react_native_1.NativeModules.ScreebModule
|
|
10
|
+
? react_native_1.NativeModules.ScreebModule
|
|
11
|
+
: new Proxy({}, {
|
|
12
|
+
get() {
|
|
13
|
+
throw new Error(LINKING_ERROR);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
let hooksRegistry = new Map();
|
|
17
|
+
function initSdk(androidChannelId, iosChannelId, userId, properties, hooks) {
|
|
18
|
+
const emitter = react_native_1.Platform.OS === "ios"
|
|
19
|
+
? new react_native_1.NativeEventEmitter(react_native_1.NativeModules.ScreebModule)
|
|
20
|
+
: react_native_1.DeviceEventEmitter;
|
|
21
|
+
emitter.addListener("ScreebEvent", handleEvent);
|
|
22
|
+
let mapHooksId = undefined;
|
|
23
|
+
if (hooks != null) {
|
|
24
|
+
mapHooksId = new Object();
|
|
25
|
+
Object.keys(hooks).map((key) => {
|
|
26
|
+
if (key == "version") {
|
|
27
|
+
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Random id
|
|
31
|
+
let uuid = Date.now().toString() + Math.random().toString();
|
|
32
|
+
hooksRegistry.set(uuid, hooks[key]);
|
|
33
|
+
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (react_native_1.Platform.OS === "ios") {
|
|
38
|
+
return ScreebModule.initSdk(iosChannelId, userId, properties, mapHooksId);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return ScreebModule.initSdk(androidChannelId, userId, properties, mapHooksId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.initSdk = initSdk;
|
|
45
|
+
function setIdentity(userId, properties) {
|
|
46
|
+
return ScreebModule.setIdentity(userId, properties);
|
|
47
|
+
}
|
|
48
|
+
exports.setIdentity = setIdentity;
|
|
49
|
+
function setProperties(properties) {
|
|
50
|
+
return ScreebModule.setProperties(properties);
|
|
51
|
+
}
|
|
52
|
+
exports.setProperties = setProperties;
|
|
53
|
+
function assignGroup(type, name, properties) {
|
|
54
|
+
return ScreebModule.assignGroup(type, name, properties);
|
|
55
|
+
}
|
|
56
|
+
exports.assignGroup = assignGroup;
|
|
57
|
+
function unassignGroup(type, name, properties) {
|
|
58
|
+
return ScreebModule.unassignGroup(type, name, properties);
|
|
59
|
+
}
|
|
60
|
+
exports.unassignGroup = unassignGroup;
|
|
61
|
+
function trackEvent(name, properties) {
|
|
62
|
+
return ScreebModule.trackEvent(name, properties);
|
|
63
|
+
}
|
|
64
|
+
exports.trackEvent = trackEvent;
|
|
65
|
+
function trackScreen(name, properties) {
|
|
66
|
+
return ScreebModule.trackScreen(name, properties);
|
|
67
|
+
}
|
|
68
|
+
exports.trackScreen = trackScreen;
|
|
69
|
+
function startSurvey(surveyId, allowMultipleResponses, hiddenFields, ignoreSurveyStatus, hooks) {
|
|
70
|
+
let mapHooksId = undefined;
|
|
71
|
+
if (hooks != undefined) {
|
|
72
|
+
mapHooksId = new Object();
|
|
73
|
+
Object.keys(hooks).map((key) => {
|
|
74
|
+
if (key == "version") {
|
|
75
|
+
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Random id
|
|
79
|
+
let uuid = Date.now().toString() + Math.random().toString();
|
|
80
|
+
hooksRegistry.set(uuid, hooks[key]);
|
|
81
|
+
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return ScreebModule.startSurvey(surveyId, allowMultipleResponses ?? true, hiddenFields, ignoreSurveyStatus ?? true, mapHooksId);
|
|
86
|
+
}
|
|
87
|
+
exports.startSurvey = startSurvey;
|
|
88
|
+
function debug() {
|
|
89
|
+
return ScreebModule.debug();
|
|
90
|
+
}
|
|
91
|
+
exports.debug = debug;
|
|
92
|
+
function debugTargeting() {
|
|
93
|
+
return ScreebModule.debugTargeting();
|
|
94
|
+
}
|
|
95
|
+
exports.debugTargeting = debugTargeting;
|
|
96
|
+
function resetIdentity() {
|
|
97
|
+
return ScreebModule.resetIdentity();
|
|
98
|
+
}
|
|
99
|
+
exports.resetIdentity = resetIdentity;
|
|
100
|
+
function closeSdk() {
|
|
101
|
+
return ScreebModule.closeSdk();
|
|
102
|
+
}
|
|
103
|
+
exports.closeSdk = closeSdk;
|
|
104
|
+
function handleEvent(event) {
|
|
105
|
+
if (event?.hookId != null) {
|
|
106
|
+
let hook = hooksRegistry.get(event.hookId);
|
|
107
|
+
if (hook != null) {
|
|
108
|
+
hook(event.payload);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DeviceEventEmitter, NativeEventEmitter, NativeModules, Platform, } from "react-native";
|
|
2
|
+
const LINKING_ERROR = `The package '@screeb/react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
3
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
4
|
+
"- You rebuilt the app after installing the package\n" +
|
|
5
|
+
"- You are not using Expo managed workflow\n";
|
|
6
|
+
const ScreebModule = NativeModules.ScreebModule
|
|
7
|
+
? NativeModules.ScreebModule
|
|
8
|
+
: new Proxy({}, {
|
|
9
|
+
get() {
|
|
10
|
+
throw new Error(LINKING_ERROR);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
let hooksRegistry = new Map();
|
|
14
|
+
export function initSdk(androidChannelId, iosChannelId, userId, properties, hooks) {
|
|
15
|
+
const emitter = Platform.OS === "ios"
|
|
16
|
+
? new NativeEventEmitter(NativeModules.ScreebModule)
|
|
17
|
+
: DeviceEventEmitter;
|
|
18
|
+
emitter.addListener("ScreebEvent", handleEvent);
|
|
19
|
+
let mapHooksId = undefined;
|
|
20
|
+
if (hooks != null) {
|
|
21
|
+
mapHooksId = new Object();
|
|
22
|
+
Object.keys(hooks).map((key) => {
|
|
23
|
+
if (key == "version") {
|
|
24
|
+
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Random id
|
|
28
|
+
let uuid = Date.now().toString() + Math.random().toString();
|
|
29
|
+
hooksRegistry.set(uuid, hooks[key]);
|
|
30
|
+
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (Platform.OS === "ios") {
|
|
35
|
+
return ScreebModule.initSdk(iosChannelId, userId, properties, mapHooksId);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return ScreebModule.initSdk(androidChannelId, userId, properties, mapHooksId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function setIdentity(userId, properties) {
|
|
42
|
+
return ScreebModule.setIdentity(userId, properties);
|
|
43
|
+
}
|
|
44
|
+
export function setProperties(properties) {
|
|
45
|
+
return ScreebModule.setProperties(properties);
|
|
46
|
+
}
|
|
47
|
+
export function assignGroup(type, name, properties) {
|
|
48
|
+
return ScreebModule.assignGroup(type, name, properties);
|
|
49
|
+
}
|
|
50
|
+
export function unassignGroup(type, name, properties) {
|
|
51
|
+
return ScreebModule.unassignGroup(type, name, properties);
|
|
52
|
+
}
|
|
53
|
+
export function trackEvent(name, properties) {
|
|
54
|
+
return ScreebModule.trackEvent(name, properties);
|
|
55
|
+
}
|
|
56
|
+
export function trackScreen(name, properties) {
|
|
57
|
+
return ScreebModule.trackScreen(name, properties);
|
|
58
|
+
}
|
|
59
|
+
export function startSurvey(surveyId, allowMultipleResponses, hiddenFields, ignoreSurveyStatus, hooks) {
|
|
60
|
+
let mapHooksId = undefined;
|
|
61
|
+
if (hooks != undefined) {
|
|
62
|
+
mapHooksId = new Object();
|
|
63
|
+
Object.keys(hooks).map((key) => {
|
|
64
|
+
if (key == "version") {
|
|
65
|
+
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Random id
|
|
69
|
+
let uuid = Date.now().toString() + Math.random().toString();
|
|
70
|
+
hooksRegistry.set(uuid, hooks[key]);
|
|
71
|
+
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return ScreebModule.startSurvey(surveyId, allowMultipleResponses ?? true, hiddenFields, ignoreSurveyStatus ?? true, mapHooksId);
|
|
76
|
+
}
|
|
77
|
+
export function debug() {
|
|
78
|
+
return ScreebModule.debug();
|
|
79
|
+
}
|
|
80
|
+
export function debugTargeting() {
|
|
81
|
+
return ScreebModule.debugTargeting();
|
|
82
|
+
}
|
|
83
|
+
export function resetIdentity() {
|
|
84
|
+
return ScreebModule.resetIdentity();
|
|
85
|
+
}
|
|
86
|
+
export function closeSdk() {
|
|
87
|
+
return ScreebModule.closeSdk();
|
|
88
|
+
}
|
|
89
|
+
function handleEvent(event) {
|
|
90
|
+
if (event?.hookId != null) {
|
|
91
|
+
let hook = hooksRegistry.get(event.hookId);
|
|
92
|
+
if (hook != null) {
|
|
93
|
+
hook(event.payload);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function initSdk(androidChannelId: string, iosChannelId: string, userId?: string, properties?: Map<string, any>, hooks?: any): any;
|
|
2
|
+
export declare function setIdentity(userId: string, properties?: Map<string, any>): any;
|
|
3
|
+
export declare function setProperties(properties?: Map<string, any>): any;
|
|
4
|
+
export declare function assignGroup(type: string | null, name: string, properties?: Map<string, any>): any;
|
|
5
|
+
export declare function unassignGroup(type: string | null, name: string, properties?: Map<string, any>): any;
|
|
6
|
+
export declare function trackEvent(name: string, properties?: Map<string, any>): any;
|
|
7
|
+
export declare function trackScreen(name: string, properties?: Map<string, any>): any;
|
|
8
|
+
export declare function startSurvey(surveyId: string, allowMultipleResponses?: boolean, hiddenFields?: Map<string, any>, ignoreSurveyStatus?: boolean, hooks?: any): any;
|
|
9
|
+
export declare function debug(): any;
|
|
10
|
+
export declare function debugTargeting(): any;
|
|
11
|
+
export declare function resetIdentity(): any;
|
|
12
|
+
export declare function closeSdk(): any;
|
package/package.json
CHANGED
package/screeb-module.podspec
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,31 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DeviceEventEmitter,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
NativeModules,
|
|
5
|
+
Platform,
|
|
6
|
+
} from "react-native";
|
|
2
7
|
|
|
3
8
|
const LINKING_ERROR =
|
|
4
9
|
`The package '@screeb/react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default:
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
11
|
+
"- You rebuilt the app after installing the package\n" +
|
|
12
|
+
"- You are not using Expo managed workflow\n";
|
|
8
13
|
|
|
9
14
|
const ScreebModule = NativeModules.ScreebModule
|
|
10
15
|
? NativeModules.ScreebModule
|
|
11
16
|
: new Proxy(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
{},
|
|
18
|
+
{
|
|
19
|
+
get() {
|
|
20
|
+
throw new Error(LINKING_ERROR);
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
let hooksRegistry = new Map<string, any>();
|
|
19
26
|
|
|
20
27
|
export function initSdk(
|
|
21
28
|
androidChannelId: string,
|
|
22
29
|
iosChannelId: string,
|
|
23
30
|
userId?: string,
|
|
24
|
-
properties?: Map<string, any
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
properties?: Map<string, any>,
|
|
32
|
+
hooks?: any
|
|
33
|
+
) {
|
|
34
|
+
const emitter =
|
|
35
|
+
Platform.OS === "ios"
|
|
36
|
+
? new NativeEventEmitter(NativeModules.ScreebModule)
|
|
37
|
+
: DeviceEventEmitter;
|
|
38
|
+
emitter.addListener("ScreebEvent", handleEvent);
|
|
39
|
+
let mapHooksId: any = undefined;
|
|
40
|
+
if (hooks != null) {
|
|
41
|
+
mapHooksId = new Object();
|
|
42
|
+
Object.keys(hooks).map((key) => {
|
|
43
|
+
if (key == "version") {
|
|
44
|
+
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
45
|
+
} else {
|
|
46
|
+
// Random id
|
|
47
|
+
let uuid = Date.now().toString() + Math.random().toString();
|
|
48
|
+
hooksRegistry.set(uuid, hooks[key]);
|
|
49
|
+
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (Platform.OS === "ios") {
|
|
54
|
+
return ScreebModule.initSdk(iosChannelId, userId, properties, mapHooksId);
|
|
27
55
|
} else {
|
|
28
|
-
return ScreebModule.initSdk(
|
|
56
|
+
return ScreebModule.initSdk(
|
|
57
|
+
androidChannelId,
|
|
58
|
+
userId,
|
|
59
|
+
properties,
|
|
60
|
+
mapHooksId
|
|
61
|
+
);
|
|
29
62
|
}
|
|
30
63
|
}
|
|
31
64
|
export function setIdentity(userId: string, properties?: Map<string, any>) {
|
|
@@ -34,10 +67,18 @@ export function setIdentity(userId: string, properties?: Map<string, any>) {
|
|
|
34
67
|
export function setProperties(properties?: Map<string, any>) {
|
|
35
68
|
return ScreebModule.setProperties(properties);
|
|
36
69
|
}
|
|
37
|
-
export function assignGroup(
|
|
70
|
+
export function assignGroup(
|
|
71
|
+
type: string | null,
|
|
72
|
+
name: string,
|
|
73
|
+
properties?: Map<string, any>
|
|
74
|
+
) {
|
|
38
75
|
return ScreebModule.assignGroup(type, name, properties);
|
|
39
76
|
}
|
|
40
|
-
export function unassignGroup(
|
|
77
|
+
export function unassignGroup(
|
|
78
|
+
type: string | null,
|
|
79
|
+
name: string,
|
|
80
|
+
properties?: Map<string, any>
|
|
81
|
+
) {
|
|
41
82
|
return ScreebModule.unassignGroup(type, name, properties);
|
|
42
83
|
}
|
|
43
84
|
export function trackEvent(name: string, properties?: Map<string, any>) {
|
|
@@ -46,18 +87,53 @@ export function trackEvent(name: string, properties?: Map<string, any>) {
|
|
|
46
87
|
export function trackScreen(name: string, properties?: Map<string, any>) {
|
|
47
88
|
return ScreebModule.trackScreen(name, properties);
|
|
48
89
|
}
|
|
49
|
-
export function startSurvey(
|
|
50
|
-
|
|
90
|
+
export function startSurvey(
|
|
91
|
+
surveyId: string,
|
|
92
|
+
allowMultipleResponses?: boolean,
|
|
93
|
+
hiddenFields?: Map<string, any>,
|
|
94
|
+
ignoreSurveyStatus?: boolean,
|
|
95
|
+
hooks?: any
|
|
96
|
+
) {
|
|
97
|
+
let mapHooksId: any = undefined;
|
|
98
|
+
if (hooks != undefined) {
|
|
99
|
+
mapHooksId = new Object();
|
|
100
|
+
Object.keys(hooks).map((key) => {
|
|
101
|
+
if (key == "version") {
|
|
102
|
+
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
103
|
+
} else {
|
|
104
|
+
// Random id
|
|
105
|
+
let uuid = Date.now().toString() + Math.random().toString();
|
|
106
|
+
hooksRegistry.set(uuid, hooks[key]);
|
|
107
|
+
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return ScreebModule.startSurvey(
|
|
112
|
+
surveyId,
|
|
113
|
+
allowMultipleResponses ?? true,
|
|
114
|
+
hiddenFields,
|
|
115
|
+
ignoreSurveyStatus ?? true,
|
|
116
|
+
mapHooksId
|
|
117
|
+
);
|
|
51
118
|
}
|
|
52
|
-
export function debug(){
|
|
119
|
+
export function debug() {
|
|
53
120
|
return ScreebModule.debug();
|
|
54
121
|
}
|
|
55
|
-
export function debugTargeting(){
|
|
122
|
+
export function debugTargeting() {
|
|
56
123
|
return ScreebModule.debugTargeting();
|
|
57
124
|
}
|
|
58
|
-
export function resetIdentity(){
|
|
125
|
+
export function resetIdentity() {
|
|
59
126
|
return ScreebModule.resetIdentity();
|
|
60
127
|
}
|
|
61
|
-
export function closeSdk(){
|
|
128
|
+
export function closeSdk() {
|
|
62
129
|
return ScreebModule.closeSdk();
|
|
63
|
-
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function handleEvent(event: any) {
|
|
133
|
+
if (event?.hookId != null) {
|
|
134
|
+
let hook = hooksRegistry.get(event.hookId);
|
|
135
|
+
if (hook != null) {
|
|
136
|
+
hook(event.payload);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|