notifly-sdk 1.1.1 → 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/index.js +49 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.trackEvent = logEvent;
|
|
|
9
9
|
|
|
10
10
|
exports.setUserProperties = _setUserProperties
|
|
11
11
|
|
|
12
|
+
exports.clickHandler = _clickHandler
|
|
13
|
+
|
|
12
14
|
exports.setUserId = async function (userID) {
|
|
13
15
|
try {
|
|
14
16
|
if (userID) {
|
|
@@ -24,24 +26,7 @@ exports.setUserId = async function (userID) {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
async function
|
|
28
|
-
const apiLevel = rnDeviceInfo.getApiLevel(); // only android
|
|
29
|
-
const brand = rnDeviceInfo.getBrand(); // apple samsung
|
|
30
|
-
const model = rnDeviceInfo.getModel(); // 기종 SM-G960N or iPhone 8
|
|
31
|
-
const platform = Platform.OS;
|
|
32
|
-
const deviceInfo = await Promise.all([model, brand, apiLevel]);
|
|
33
|
-
const openAppEventParams = {
|
|
34
|
-
"platform": platform,
|
|
35
|
-
"device_model": deviceInfo[0],
|
|
36
|
-
"properties": {
|
|
37
|
-
"device_brand": deviceInfo[1],
|
|
38
|
-
"api_level": deviceInfo[2],
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
await logEvent("session_start", openAppEventParams, null, true)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
exports.initialize = async function (prjId, userName, password) {
|
|
29
|
+
exports.initialize = async function (prjId, userName, password, useCustomClickHandler = false) {
|
|
45
30
|
try {
|
|
46
31
|
await messaging().requestPermission();
|
|
47
32
|
|
|
@@ -53,19 +38,17 @@ exports.initialize = async function (prjId, userName, password) {
|
|
|
53
38
|
await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, null, true);
|
|
54
39
|
});
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const link = remoteMessage.data?.link
|
|
63
|
-
if (link) {
|
|
64
|
-
Linking.openURL(link);
|
|
41
|
+
if (!useCustomClickHandler) {
|
|
42
|
+
messaging()
|
|
43
|
+
.getInitialNotification()
|
|
44
|
+
.then(async (remoteMessage) => {
|
|
45
|
+
if (remoteMessage) {
|
|
46
|
+
await _clickHandler(remoteMessage)
|
|
65
47
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
messaging().getToken()
|
|
69
52
|
|
|
70
53
|
await Promise.all([
|
|
71
54
|
AsyncStorage.setItem('notiflyProjectId', prjId),
|
|
@@ -78,6 +61,25 @@ exports.initialize = async function (prjId, userName, password) {
|
|
|
78
61
|
}
|
|
79
62
|
}
|
|
80
63
|
|
|
64
|
+
async function _sessionStart() {
|
|
65
|
+
const apiLevel = rnDeviceInfo.getApiLevel(); // only android
|
|
66
|
+
const brand = rnDeviceInfo.getBrand(); // apple samsung
|
|
67
|
+
const model = rnDeviceInfo.getModel(); // 기종 SM-G960N or iPhone 8
|
|
68
|
+
const userAgent = rnDeviceInfo.getUserAgent() // User Agent String
|
|
69
|
+
const platform = Platform.OS;
|
|
70
|
+
const deviceInfo = await Promise.all([model, brand, apiLevel, userAgent]);
|
|
71
|
+
const openAppEventParams = {
|
|
72
|
+
"platform": platform,
|
|
73
|
+
"device_model": deviceInfo[0],
|
|
74
|
+
"properties": {
|
|
75
|
+
"device_brand": deviceInfo[1],
|
|
76
|
+
"api_level": deviceInfo[2],
|
|
77
|
+
"user_agent": deviceInfo[3],
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
await logEvent("session_start", openAppEventParams, null, true)
|
|
81
|
+
}
|
|
82
|
+
|
|
81
83
|
async function getCognitoIdToken(userName, password) {
|
|
82
84
|
const myHeaders = new Headers();
|
|
83
85
|
myHeaders.append("X-Amz-Target", "AWSCognitoIdentityProviderService.InitiateAuth");
|
|
@@ -243,6 +245,23 @@ async function logEvent(eventName, eventParams, segmentation_event_param_keys =
|
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
247
|
|
|
248
|
+
async function _clickHandler(remoteMessage) {
|
|
249
|
+
try {
|
|
250
|
+
if (remoteMessage) {
|
|
251
|
+
const link = remoteMessage.data?.link
|
|
252
|
+
if (link) {
|
|
253
|
+
Linking.openURL(link);
|
|
254
|
+
}
|
|
255
|
+
await logEvent("push_click", { "campaign_id": remoteMessage.data?.campaign_id, "status": "quit" }, null, true);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
console.warn('[Notifly] clickHandler receives a null remoteMessage.');
|
|
259
|
+
return;
|
|
260
|
+
} catch (err) {
|
|
261
|
+
console.warn('[Notifly] custom click handler registration failed.');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
246
265
|
async function _apiCall(apiUrl, requestOptions) {
|
|
247
266
|
const result = fetch(apiUrl, requestOptions)
|
|
248
267
|
.then(response => response.text());
|