notifly-sdk 2.2.4 → 2.2.6
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 +11 -2
- package/package.json +1 -1
- package/src/constant.js +1 -1
- package/src/in_app_message.js +31 -1
- package/src/log_event.js +1 -0
- package/src/utils.js +3 -0
package/index.js
CHANGED
|
@@ -7,6 +7,9 @@ import { setUserProperties, removeUserId } from './src/user';
|
|
|
7
7
|
import { base64Decode, clickHandler, sessionStart } from './src/utils';
|
|
8
8
|
import { showInAppMessage } from './src/in_app_message';
|
|
9
9
|
let isSetBackgroundHandler = false;
|
|
10
|
+
let isNotiflyInitialized = false;
|
|
11
|
+
const openedInAppWebViewCount = { count: 0 };
|
|
12
|
+
|
|
10
13
|
exports.trackEvent = logEvent;
|
|
11
14
|
exports.setUserProperties = setUserProperties;
|
|
12
15
|
exports.clickHandler = clickHandler;
|
|
@@ -108,16 +111,18 @@ exports.setUserId = async function (userID) {
|
|
|
108
111
|
* await initialize('myProjectId', 'myUserName', 'myPassword');
|
|
109
112
|
*/
|
|
110
113
|
exports.initialize = async function (prjId, userName, password, useCustomClickHandler = false) {
|
|
114
|
+
if (isNotiflyInitialized) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
111
117
|
try {
|
|
112
118
|
await messaging().requestPermission();
|
|
113
119
|
// in-app-message
|
|
114
|
-
const openedInAppWebViewCount = { count: 0 };
|
|
115
120
|
messaging().onMessage((remoteMessage) => {
|
|
116
121
|
new RootSiblings(null).destroy();
|
|
117
122
|
handleInAppMessage(remoteMessage, openedInAppWebViewCount);
|
|
118
123
|
});
|
|
119
124
|
|
|
120
|
-
|
|
125
|
+
|
|
121
126
|
messaging().onNotificationOpenedApp(handleNotificationOpened);
|
|
122
127
|
|
|
123
128
|
// custom push click handler
|
|
@@ -137,6 +142,7 @@ exports.initialize = async function (prjId, userName, password, useCustomClickHa
|
|
|
137
142
|
AsyncStorage.setItem('notiflyUserPassword', password),
|
|
138
143
|
]);
|
|
139
144
|
await sessionStart();
|
|
145
|
+
isNotiflyInitialized = true;
|
|
140
146
|
} catch (err) {
|
|
141
147
|
console.warn('[Notifly]: ', err);
|
|
142
148
|
}
|
|
@@ -156,6 +162,9 @@ async function handleInAppMessage(remoteMessage, openedInAppWebViewCount) {
|
|
|
156
162
|
|
|
157
163
|
async function handleNotificationOpened(remoteMessage) {
|
|
158
164
|
try {
|
|
165
|
+
if (remoteMessage.data?.notifly_message_type != 'push-notification') {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
159
168
|
const link = remoteMessage.data?.link;
|
|
160
169
|
if (link) {
|
|
161
170
|
Linking.openURL(link);
|
package/package.json
CHANGED
package/src/constant.js
CHANGED
package/src/in_app_message.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { View, Linking, Dimensions } from 'react-native';
|
|
2
3
|
import RootSiblings from 'react-native-root-siblings';
|
|
3
4
|
import Modal from 'react-native-modal';
|
|
@@ -38,9 +39,11 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
38
39
|
type: event.notifly_button_click_type,
|
|
39
40
|
button_name: event.notifly_button_name,
|
|
40
41
|
link: event.notifly_button_click_link,
|
|
42
|
+
extra_data: event.notifly_extra_data,
|
|
41
43
|
}));
|
|
42
44
|
});
|
|
43
45
|
`;
|
|
46
|
+
const backdropOpacity = _getBackgroundOpacity(modalProperties?.backgroundOpacity);
|
|
44
47
|
|
|
45
48
|
const webviewMessageHandler = (e) => {
|
|
46
49
|
const message = JSON.parse(e.nativeEvent.data);
|
|
@@ -98,6 +101,21 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
98
101
|
[key]: true,
|
|
99
102
|
});
|
|
100
103
|
}
|
|
104
|
+
} else if (message.type === 'survey_submit_button') {
|
|
105
|
+
modal.destroy();
|
|
106
|
+
openedInAppWebViewCount.count = openedInAppWebViewCount.count - 1;
|
|
107
|
+
logEvent(
|
|
108
|
+
'survey_submit_button_click', {
|
|
109
|
+
type: 'message_event',
|
|
110
|
+
channel: 'in-app-message',
|
|
111
|
+
button_name: message.button_name,
|
|
112
|
+
campaign_id: data.campaign_id,
|
|
113
|
+
notifly_message_id: data.notifly_message_id,
|
|
114
|
+
notifly_extra_data: message.extra_data,
|
|
115
|
+
},
|
|
116
|
+
null,
|
|
117
|
+
true
|
|
118
|
+
);
|
|
101
119
|
}
|
|
102
120
|
};
|
|
103
121
|
|
|
@@ -121,7 +139,7 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
121
139
|
openedInAppWebViewCount.count = openedInAppWebViewCount.count - 1;
|
|
122
140
|
modal.destroy();
|
|
123
141
|
}}
|
|
124
|
-
backdropOpacity={
|
|
142
|
+
backdropOpacity={backdropOpacity}
|
|
125
143
|
style={webViewProps.modalStyle}
|
|
126
144
|
>
|
|
127
145
|
<View>
|
|
@@ -226,3 +244,15 @@ function _getViewHeight(modalProps, screenWidth, screenHeight) {
|
|
|
226
244
|
|
|
227
245
|
return viewHeight;
|
|
228
246
|
}
|
|
247
|
+
|
|
248
|
+
function _getBackgroundOpacity(backgroundOpacity) {
|
|
249
|
+
// if backgroundOpacity is not defined, default value is 0.2
|
|
250
|
+
if (backgroundOpacity === undefined) {
|
|
251
|
+
return 0.2;
|
|
252
|
+
}
|
|
253
|
+
// if backgroundOpacity is not between 0 and 1, default value is 0.2
|
|
254
|
+
if (backgroundOpacity < 0 || backgroundOpacity > 1) {
|
|
255
|
+
return 0.2;
|
|
256
|
+
}
|
|
257
|
+
return backgroundOpacity;
|
|
258
|
+
}
|
package/src/log_event.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -98,6 +98,9 @@ export async function clickHandler(remoteMessage) {
|
|
|
98
98
|
console.warn('[Notifly] clickHandler receives a null remoteMessage.');
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
+
if (remoteMessage.data?.notifly_message_type != 'push-notification') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
101
104
|
|
|
102
105
|
try {
|
|
103
106
|
const { data: { link, campaign_id, notifly_message_id } = {} } = remoteMessage;
|