@dashx/react-native 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +6 -2
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/com/dashx/rn/sdk/DashXActivityLifecycleCallbacks.kt +5 -5
- package/android/src/main/java/com/dashx/rn/sdk/DashXClientInterceptor.kt +16 -14
- package/android/src/main/java/com/dashx/rn/sdk/DashXExceptionHandler.kt +8 -3
- package/android/src/main/java/com/dashx/rn/sdk/DashXMessagingService.kt +4 -1
- package/android/src/main/java/com/dashx/rn/sdk/DashXModule.kt +18 -18
- package/ios/DashXClient.swift +18 -4
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -97,8 +97,12 @@ dependencies {
|
|
|
97
97
|
|
|
98
98
|
implementation 'com.google.code.gson:gson:2.8.6'
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
// Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom)
|
|
101
|
+
implementation platform('com.google.firebase:firebase-bom:28.3.0')
|
|
102
|
+
implementation 'com.google.firebase:firebase-messaging-ktx'
|
|
103
|
+
|
|
104
|
+
// The Firebase SDK for Google Analytics is needed for delivery reports
|
|
105
|
+
implementation 'com.google.firebase:firebase-analytics-ktx'
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
def configureReactNativePom(def pom) {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
package="com.dashx.rn.sdk">
|
|
3
3
|
|
|
4
4
|
<application>
|
|
5
|
-
<service android:name="
|
|
6
|
-
<intent-filter
|
|
7
|
-
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
|
|
5
|
+
<service android:name=".DashXMessagingService" android:exported="false">
|
|
6
|
+
<intent-filter>
|
|
7
|
+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
8
8
|
</intent-filter>
|
|
9
9
|
</service>
|
|
10
10
|
</application>
|
|
@@ -12,7 +12,7 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
12
12
|
private var startSession = System.currentTimeMillis().toDouble()
|
|
13
13
|
|
|
14
14
|
init {
|
|
15
|
-
dashXClient
|
|
15
|
+
dashXClient?.trackAppStarted()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
override fun onActivityPaused(activity: Activity) {
|
|
@@ -20,7 +20,7 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
20
20
|
return
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
dashXClient
|
|
23
|
+
dashXClient?.trackAppSession(System.currentTimeMillis().toDouble() - startSession)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
override fun onActivityResumed(activity: Activity) {
|
|
@@ -29,7 +29,7 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
startSession = System.currentTimeMillis().toDouble()
|
|
32
|
-
dashXClient
|
|
32
|
+
dashXClient?.trackAppStarted(fromBackground = true)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
override fun onActivityStarted(activity: Activity) {
|
|
@@ -37,10 +37,10 @@ class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
val packageManager = activity
|
|
40
|
+
val packageManager = activity.packageManager
|
|
41
41
|
val info = packageManager?.getActivityInfo(activity.componentName, PackageManager.GET_META_DATA)
|
|
42
42
|
val activityLabel = info?.loadLabel(packageManager)
|
|
43
|
-
activityLabel?.let { it -> dashXClient
|
|
43
|
+
activityLabel?.let { it -> dashXClient?.screen(it.toString(), hashMapOf()) }
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
override fun onActivityDestroyed(activity: Activity) {
|
|
@@ -16,35 +16,37 @@ class DashXClientInterceptor private constructor() {
|
|
|
16
16
|
|
|
17
17
|
fun createDashXClient(reactApplicationContext: ReactApplicationContext, publicKey: String, baseURI: String?, targetEnvironment: String?, targetInstallation: String?) {
|
|
18
18
|
this.reactApplicationContext = reactApplicationContext
|
|
19
|
-
client = DashX(reactApplicationContext.applicationContext, publicKey
|
|
19
|
+
client = DashX(reactApplicationContext.applicationContext, publicKey, baseURI, targetEnvironment, targetInstallation)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
fun getDashXClient(): com.dashx.sdk.DashXClient {
|
|
23
|
-
|
|
24
|
-
throw Exception("DashXClient not initialised")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return client!!
|
|
22
|
+
fun getDashXClient(): com.dashx.sdk.DashXClient? {
|
|
23
|
+
return client
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
fun handleMessage(remoteMessage: RemoteMessage) {
|
|
31
|
-
val
|
|
27
|
+
val notificationData = remoteMessage.getData()
|
|
28
|
+
|
|
29
|
+
DashXLog.d(tag, "Notification Data: " + notificationData)
|
|
30
|
+
|
|
32
31
|
val eventProperties: WritableMap = Arguments.createMap()
|
|
33
|
-
DashXLog.d(tag, "Data: " + remoteMessage.data)
|
|
34
32
|
|
|
35
33
|
try {
|
|
36
|
-
eventProperties.putMap("data", convertToWritableMap(
|
|
34
|
+
eventProperties.putMap("data", convertToWritableMap(notificationData, listOf(dashXNotificationFilter)))
|
|
37
35
|
} catch (e: Exception) {
|
|
38
|
-
DashXLog.d(tag, "Encountered an error while parsing notification data")
|
|
39
36
|
e.printStackTrace()
|
|
37
|
+
DashXLog.d(tag, "Encountered an error while parsing notification data.")
|
|
40
38
|
}
|
|
41
39
|
|
|
40
|
+
val notification = remoteMessage.getNotification()
|
|
41
|
+
|
|
42
42
|
if (notification != null) {
|
|
43
43
|
val notificationProperties: WritableMap = Arguments.createMap()
|
|
44
|
-
notificationProperties.putString("title", notification.
|
|
45
|
-
notificationProperties.putString("body", notification.
|
|
44
|
+
notificationProperties.putString("title", notification.getTitle())
|
|
45
|
+
notificationProperties.putString("body", notification.getBody())
|
|
46
|
+
|
|
46
47
|
eventProperties.putMap("notification", notificationProperties)
|
|
47
|
-
|
|
48
|
+
|
|
49
|
+
DashXLog.d(tag, "onMessageReceived with Title: " + notification.getTitle() + " and Body: " + notification.getBody())
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
sendJsEvent("messageReceived", eventProperties)
|
|
@@ -11,13 +11,18 @@ class DashXExceptionHandler(private val mainExceptionHandler: Thread.UncaughtExc
|
|
|
11
11
|
return
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (defaultExceptionHandler != null) {
|
|
15
|
+
val dashXExceptionHandler = DashXExceptionHandler(defaultExceptionHandler)
|
|
16
|
+
Thread.setDefaultUncaughtExceptionHandler(dashXExceptionHandler)
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
override fun uncaughtException(thread: Thread, exception: Throwable) {
|
|
20
|
-
dashXClient
|
|
22
|
+
if (dashXClient != null) {
|
|
23
|
+
dashXClient.trackAppCrashed(exception)
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
mainExceptionHandler.uncaughtException(thread, exception)
|
|
22
27
|
}
|
|
23
28
|
}
|
|
@@ -10,8 +10,11 @@ class DashXMessagingService : FirebaseMessagingService() {
|
|
|
10
10
|
|
|
11
11
|
override fun onNewToken(token: String) {
|
|
12
12
|
super.onNewToken(token)
|
|
13
|
-
dashXClient.setDeviceToken(token)
|
|
14
13
|
DashXLog.d(tag, "onNewToken: $token")
|
|
14
|
+
|
|
15
|
+
if (dashXClient != null) {
|
|
16
|
+
dashXClient.setDeviceToken(token)
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
|
@@ -3,7 +3,7 @@ package com.dashx.rn.sdk
|
|
|
3
3
|
import com.facebook.react.bridge.*
|
|
4
4
|
import com.dashx.sdk.DashXLog
|
|
5
5
|
import com.google.android.gms.tasks.OnCompleteListener
|
|
6
|
-
import com.google.firebase.
|
|
6
|
+
import com.google.firebase.messaging.FirebaseMessaging
|
|
7
7
|
|
|
8
8
|
class DashXModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
9
9
|
private val tag = DashXModule::class.java.simpleName
|
|
@@ -28,7 +28,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
28
28
|
options.getStringIfPresent("targetEnvironment"),
|
|
29
29
|
options.getStringIfPresent("targetInstallation")
|
|
30
30
|
)
|
|
31
|
-
interceptor.getDashXClient()
|
|
31
|
+
interceptor.getDashXClient()?.generateAnonymousUid()
|
|
32
32
|
|
|
33
33
|
if (options.hasKey("trackAppLifecycleEvents") && options.getBoolean("trackAppLifecycleEvents")) {
|
|
34
34
|
DashXExceptionHandler.enable()
|
|
@@ -39,28 +39,28 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
39
39
|
DashXActivityLifecycleCallbacks.enableScreenTracking(reactContext.applicationContext)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
FirebaseMessaging.getInstance().getToken()
|
|
43
43
|
.addOnCompleteListener(OnCompleteListener { task ->
|
|
44
44
|
if (!task.isSuccessful) {
|
|
45
|
-
DashXLog.d(tag, "
|
|
45
|
+
DashXLog.d(tag, "FirebaseMessaging.getInstance().getToken() failed: $task.exception")
|
|
46
46
|
return@OnCompleteListener
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
val token = task.
|
|
50
|
-
token?.let { it -> interceptor.getDashXClient()
|
|
49
|
+
val token = task.getResult()
|
|
50
|
+
token?.let { it -> interceptor.getDashXClient()?.setDeviceToken(it) }
|
|
51
51
|
DashXLog.d(tag, "Firebase Initialised with: $token")
|
|
52
|
-
})
|
|
52
|
+
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
@ReactMethod
|
|
56
56
|
fun identify(uid: String?, options: ReadableMap?) {
|
|
57
57
|
val optionsHashMap = options?.toHashMap()
|
|
58
|
-
interceptor.getDashXClient()
|
|
58
|
+
interceptor.getDashXClient()?.identify(uid, optionsHashMap as HashMap<String, String>?)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
@ReactMethod
|
|
62
62
|
fun reset() {
|
|
63
|
-
interceptor.getDashXClient()
|
|
63
|
+
interceptor.getDashXClient()?.reset()
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
@ReactMethod
|
|
@@ -72,22 +72,22 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
72
72
|
return
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
interceptor.getDashXClient()
|
|
75
|
+
interceptor.getDashXClient()?.track(event, jsonData)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
@ReactMethod
|
|
79
79
|
fun screen(screenName: String, data: ReadableMap?) {
|
|
80
|
-
interceptor.getDashXClient()
|
|
80
|
+
interceptor.getDashXClient()?.screen(screenName, data?.toHashMap() as HashMap<String, String>)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
@ReactMethod
|
|
84
84
|
fun setIdentityToken(identityToken: String) {
|
|
85
|
-
interceptor.getDashXClient()
|
|
85
|
+
interceptor.getDashXClient()?.setIdentityToken(identityToken)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
@ReactMethod
|
|
89
89
|
fun fetchContent(urn: String, options: ReadableMap?, promise: Promise) {
|
|
90
|
-
interceptor.getDashXClient()
|
|
90
|
+
interceptor.getDashXClient()?.fetchContent(
|
|
91
91
|
urn,
|
|
92
92
|
options?.getBooleanIfPresent("preview"),
|
|
93
93
|
options?.getStringIfPresent("language"),
|
|
@@ -119,7 +119,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
119
119
|
throw Exception("Encountered an error while parsing order")
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
interceptor.getDashXClient()
|
|
122
|
+
interceptor.getDashXClient()?.searchContent(
|
|
123
123
|
contentType,
|
|
124
124
|
options?.getString("returnType") ?: "all",
|
|
125
125
|
jsonFilter,
|
|
@@ -159,7 +159,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
159
159
|
throw Exception("Encountered an error while parsing custom")
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
interceptor.getDashXClient()
|
|
162
|
+
interceptor.getDashXClient()?.addItemToCart(
|
|
163
163
|
itemId,
|
|
164
164
|
pricingId,
|
|
165
165
|
quantity,
|
|
@@ -176,7 +176,7 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
176
176
|
|
|
177
177
|
@ReactMethod
|
|
178
178
|
fun fetchCart(promise: Promise) {
|
|
179
|
-
interceptor.getDashXClient()
|
|
179
|
+
interceptor.getDashXClient()?.fetchCart(
|
|
180
180
|
onError = {
|
|
181
181
|
promise.reject("EUNSPECIFIED", it)
|
|
182
182
|
},
|
|
@@ -185,9 +185,9 @@ class DashXModule(private val reactContext: ReactApplicationContext) : ReactCont
|
|
|
185
185
|
}
|
|
186
186
|
)
|
|
187
187
|
}
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
@ReactMethod
|
|
190
190
|
fun subscribe() {
|
|
191
|
-
interceptor.getDashXClient()
|
|
191
|
+
interceptor.getDashXClient()?.subscribe()
|
|
192
192
|
}
|
|
193
193
|
}
|
package/ios/DashXClient.swift
CHANGED
|
@@ -119,6 +119,18 @@ class DashXClient {
|
|
|
119
119
|
|
|
120
120
|
track(Constants.INTERNAL_EVENT_APP_SCREEN_VIEWED, withData: properties?.merging([ "name": screenName], uniquingKeysWith: { (_, new) in new }) as NSDictionary?)
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
// https://stackoverflow.com/a/11197770
|
|
124
|
+
func getDeviceModel() -> String {
|
|
125
|
+
var systemInfo = utsname()
|
|
126
|
+
uname(&systemInfo)
|
|
127
|
+
let machineMirror = Mirror(reflecting: systemInfo.machine)
|
|
128
|
+
return machineMirror.children.reduce("") { identifier, element in
|
|
129
|
+
guard let value = element.value as? Int8, value != 0 else { return identifier }
|
|
130
|
+
return identifier + String(UnicodeScalar(UInt8(value)))
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
// MARK: -- subscribe
|
|
123
135
|
|
|
124
136
|
func subscribe() {
|
|
@@ -129,8 +141,6 @@ class DashXClient {
|
|
|
129
141
|
|
|
130
142
|
self.mustSubscribe = false
|
|
131
143
|
|
|
132
|
-
let deviceKind = "IOS"
|
|
133
|
-
|
|
134
144
|
let preferences = UserDefaults.standard
|
|
135
145
|
let deviceTokenKey = Constants.USER_PREFERENCES_KEY_DEVICE_TOKEN
|
|
136
146
|
|
|
@@ -142,9 +152,13 @@ class DashXClient {
|
|
|
142
152
|
let subscribeContactInput = DashXGql.SubscribeContactInput(
|
|
143
153
|
accountUid: uid,
|
|
144
154
|
accountAnonymousUid: anonymousUid!,
|
|
145
|
-
name:
|
|
155
|
+
name: UIDevice.current.model,
|
|
146
156
|
kind: .ios,
|
|
147
|
-
value: deviceToken
|
|
157
|
+
value: deviceToken!,
|
|
158
|
+
osName: UIDevice.current.systemName,
|
|
159
|
+
osVersion: UIDevice.current.systemVersion,
|
|
160
|
+
deviceModel: getDeviceModel(),
|
|
161
|
+
deviceManufacturer: "Apple"
|
|
148
162
|
)
|
|
149
163
|
|
|
150
164
|
DashXLog.d(tag: #function, "Calling subscribe with \(subscribeContactInput)")
|