notifly-sdk 1.0.0 → 1.0.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/index.js +13 -17
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -18,12 +18,9 @@ exports.sessionStart = async function () {
|
|
|
18
18
|
const apiLevel = rnDeviceInfo.getApiLevel(); // only android
|
|
19
19
|
const brand = rnDeviceInfo.getBrand(); // apple samsung
|
|
20
20
|
const model = rnDeviceInfo.getModel(); // 기종 SM-G960N or iPhone 8
|
|
21
|
-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
22
21
|
const platform = Platform.OS;
|
|
23
22
|
const deviceInfo = await Promise.all([model, brand, apiLevel]);
|
|
24
23
|
const openAppEventParams = {
|
|
25
|
-
"timezone": timezone,
|
|
26
|
-
"app_id": 'test_app',
|
|
27
24
|
"platform": platform,
|
|
28
25
|
"device_model": deviceInfo[0],
|
|
29
26
|
"properties": {
|
|
@@ -31,14 +28,13 @@ exports.sessionStart = async function () {
|
|
|
31
28
|
"api_level": deviceInfo[2],
|
|
32
29
|
},
|
|
33
30
|
}
|
|
34
|
-
await logEvent("session_start", openAppEventParams, true)
|
|
35
|
-
|
|
31
|
+
await logEvent("session_start", openAppEventParams, null, true)
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
exports.initialize = async function (prjId, userName, password) {
|
|
39
35
|
try {
|
|
40
36
|
messaging().onNotificationOpenedApp(async (remoteMessage) => {
|
|
41
|
-
await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, true);
|
|
37
|
+
await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, null, true);
|
|
42
38
|
});
|
|
43
39
|
|
|
44
40
|
messaging().getToken()
|
|
@@ -51,14 +47,14 @@ exports.initialize = async function (prjId, userName, password) {
|
|
|
51
47
|
if (link) {
|
|
52
48
|
Linking.openURL(remoteMessage.notification?.android?.link);
|
|
53
49
|
}
|
|
54
|
-
await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, true);
|
|
55
|
-
await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, true);
|
|
50
|
+
await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, null, true);
|
|
51
|
+
await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, null, true);
|
|
56
52
|
|
|
57
53
|
}
|
|
58
54
|
});
|
|
59
55
|
|
|
60
56
|
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
|
|
61
|
-
await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, true);
|
|
57
|
+
await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, null, true);
|
|
62
58
|
return
|
|
63
59
|
})
|
|
64
60
|
|
|
@@ -85,7 +81,7 @@ exports.initialize = async function (prjId, userName, password) {
|
|
|
85
81
|
switch (type) {
|
|
86
82
|
case 3:
|
|
87
83
|
try {
|
|
88
|
-
await logEvent("push_delivered", { "campaign_id": campaign_id, "status": "background-notifee" }, true);
|
|
84
|
+
await logEvent("push_delivered", { "campaign_id": campaign_id, "status": "background-notifee" }, null, true);
|
|
89
85
|
} catch (err) {
|
|
90
86
|
console.error('[Notifly]: ', err);
|
|
91
87
|
}
|
|
@@ -107,7 +103,7 @@ exports.foregroundSetting = function () {
|
|
|
107
103
|
channelId: "foreground",
|
|
108
104
|
},
|
|
109
105
|
});
|
|
110
|
-
await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "foreground" }, true);
|
|
106
|
+
await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "foreground" }, null, true);
|
|
111
107
|
});
|
|
112
108
|
notifee.onForegroundEvent(async ({ type, detail }) => {
|
|
113
109
|
const { notification } = detail;
|
|
@@ -119,10 +115,8 @@ exports.foregroundSetting = function () {
|
|
|
119
115
|
try {
|
|
120
116
|
if (notification.data.link) {
|
|
121
117
|
Linking.openURL(notification.data.link)
|
|
122
|
-
await logEvent("push_click", { "campaign_id": campaign_id, "status": "foreground" }, true);
|
|
123
|
-
} else {
|
|
124
|
-
await logEvent("push_click", { "campaign_id": campaign_id, "status": "foreground" }, true);
|
|
125
118
|
}
|
|
119
|
+
await logEvent("push_click", { "campaign_id": campaign_id, "status": "foreground" }, null, true);
|
|
126
120
|
} catch (err) {
|
|
127
121
|
console.error('[Notifly]: ', err);
|
|
128
122
|
}
|
|
@@ -172,15 +166,16 @@ async function _getNotiflyUserId() {
|
|
|
172
166
|
|
|
173
167
|
async function _setUserProperties(params) {
|
|
174
168
|
if (params.external_user_id) {
|
|
169
|
+
params['previous_notifly_user_id'] = await _getNotiflyUserId();
|
|
175
170
|
await Promise.all([
|
|
176
171
|
AsyncStorage.setItem('notiflyExternalUserId', params.external_user_id),
|
|
177
172
|
AsyncStorage.removeItem('notiflyUserId'),
|
|
178
173
|
]);
|
|
179
174
|
}
|
|
180
|
-
return await logEvent("set_user_properties", params, true);
|
|
175
|
+
return (await logEvent("set_user_properties", params, null, true));
|
|
181
176
|
}
|
|
182
177
|
|
|
183
|
-
async function logEvent(eventName, eventParams, isInternalEvent = false) {
|
|
178
|
+
async function logEvent(eventName, eventParams, segmentation_event_param_keys = null, isInternalEvent = false) {
|
|
184
179
|
try {
|
|
185
180
|
let token;
|
|
186
181
|
const [savedCognitoToken, notiflyUserId, externalUserId, prjId, externalDeviceId, osVersion, appVersion] = await Promise.all([
|
|
@@ -225,6 +220,7 @@ async function logEvent(eventName, eventParams, isInternalEvent = false) {
|
|
|
225
220
|
"external_device_id": externalDeviceId,
|
|
226
221
|
"device_token": deviceToken,
|
|
227
222
|
"is_internal_event": isInternalEvent,
|
|
223
|
+
"segmentation_event_param_keys": segmentation_event_param_keys,
|
|
228
224
|
"project_id": prjId,
|
|
229
225
|
"platform": Platform.OS,
|
|
230
226
|
"os_version": osVersion,
|
|
@@ -261,7 +257,7 @@ async function logEvent(eventName, eventParams, isInternalEvent = false) {
|
|
|
261
257
|
const [userName, password] = await Promise.all([AsyncStorage.getItem('notiflyUserName'), AsyncStorage.getItem('notiflyUserPassword')])
|
|
262
258
|
const newToken = await getCognitoIdToken(userName, password);
|
|
263
259
|
await AsyncStorage.setItem("notiflyCognitoIdToken", newToken);
|
|
264
|
-
await logEvent(eventName, eventParams)
|
|
260
|
+
await logEvent(eventName, eventParams, segmentation_event_param_keys, isInternalEvent)
|
|
265
261
|
}
|
|
266
262
|
|
|
267
263
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notifly-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,5 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"author": "daeseongKim",
|
|
18
18
|
"license": "ISC",
|
|
19
|
-
"type": "module"
|
|
19
|
+
"type": "module",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"notifly-sdk": "^1.0.0"
|
|
22
|
+
}
|
|
20
23
|
}
|