notifly-sdk 2.1.2 → 2.1.3
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 +6 -3
- package/package.json +1 -1
- package/src/constant.js +1 -1
- package/src/in_app_message.js +5 -2
- package/src/utils.js +27 -2
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
4
4
|
import messaging from '@react-native-firebase/messaging';
|
|
5
5
|
import logEvent from './src/log_event';
|
|
6
6
|
import { setUserProperties, removeUserId } from './src/user';
|
|
7
|
-
import { clickHandler, sessionStart } from './src/utils';
|
|
7
|
+
import { base64Decode, clickHandler, sessionStart } from './src/utils';
|
|
8
8
|
import { showInAppMessage } from './src/in_app_message';
|
|
9
9
|
|
|
10
10
|
exports.trackEvent = logEvent;
|
|
@@ -86,8 +86,10 @@ exports.initialize = async function (prjId, userName, password, useCustomClickHa
|
|
|
86
86
|
|
|
87
87
|
async function handleInAppMessage(remoteMessage, openedInAppWebViewCount) {
|
|
88
88
|
try {
|
|
89
|
-
if (remoteMessage.data?.notifly_message_type === 'in-app-message' && remoteMessage.data
|
|
90
|
-
|
|
89
|
+
if (remoteMessage.data?.notifly_message_type === 'in-app-message' && remoteMessage.data?.notifly_in_app_message_data) {
|
|
90
|
+
const decodedJsonString = base64Decode(remoteMessage.data?.notifly_in_app_message_data);
|
|
91
|
+
const notiflyInAppMessageData = JSON.parse(decodedJsonString);
|
|
92
|
+
showInAppMessage(notiflyInAppMessageData, openedInAppWebViewCount);
|
|
91
93
|
}
|
|
92
94
|
} catch (err) {
|
|
93
95
|
console.warn('[Notifly] In-app message handling failed:', err);
|
|
@@ -106,6 +108,7 @@ async function handleNotificationOpened(remoteMessage) {
|
|
|
106
108
|
type: 'message_event',
|
|
107
109
|
channel: 'push-notification',
|
|
108
110
|
campaign_id: remoteMessage.data.campaign_id,
|
|
111
|
+
notifly_message_id: remoteMessage.data?.notifly_message_id,
|
|
109
112
|
status: 'background',
|
|
110
113
|
},
|
|
111
114
|
null,
|
package/package.json
CHANGED
package/src/constant.js
CHANGED
package/src/in_app_message.js
CHANGED
|
@@ -25,7 +25,7 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
25
25
|
if (!(data?.url && data?.modal_properties)) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
const modalProperties =
|
|
28
|
+
const modalProperties = data.modal_properties || {};
|
|
29
29
|
const screenWidth = Dimensions.get('window').width;
|
|
30
30
|
const screenHeight = Dimensions.get('window').height;
|
|
31
31
|
const webViewProps = _translateWebviewProps(modalProperties, screenWidth, screenHeight);
|
|
@@ -54,6 +54,7 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
54
54
|
channel: 'in-app-message',
|
|
55
55
|
button_name: message.button_name,
|
|
56
56
|
campaign_id: data.campaign_id,
|
|
57
|
+
notifly_message_id: data.notifly_message_id,
|
|
57
58
|
},
|
|
58
59
|
null,
|
|
59
60
|
true
|
|
@@ -66,6 +67,7 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
66
67
|
channel: 'in-app-message',
|
|
67
68
|
button_name: message.button_name,
|
|
68
69
|
campaign_id: data.campaign_id,
|
|
70
|
+
notifly_message_id: data.notifly_message_id,
|
|
69
71
|
},
|
|
70
72
|
null,
|
|
71
73
|
true
|
|
@@ -85,6 +87,7 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
85
87
|
channel: 'in-app-message',
|
|
86
88
|
button_name: message.button_name,
|
|
87
89
|
campaign_id: data.campaign_id,
|
|
90
|
+
notifly_message_id: data.notifly_message_id,
|
|
88
91
|
},
|
|
89
92
|
null,
|
|
90
93
|
true
|
|
@@ -101,7 +104,7 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
|
|
|
101
104
|
openedInAppWebViewCount.count = openedInAppWebViewCount.count + 1;
|
|
102
105
|
logEvent(
|
|
103
106
|
'in_app_message_show',
|
|
104
|
-
{ type: 'message_event', channel: 'in-app-message', campaign_id: data.campaign_id },
|
|
107
|
+
{ type: 'message_event', channel: 'in-app-message', campaign_id: data.campaign_id, notifly_message_id: data.notifly_message_id },
|
|
105
108
|
null,
|
|
106
109
|
true
|
|
107
110
|
); // logging in app messaging delivered
|
package/src/utils.js
CHANGED
|
@@ -97,14 +97,14 @@ export async function clickHandler(remoteMessage) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
try {
|
|
100
|
-
const { data: { link, campaign_id } = {} } = remoteMessage;
|
|
100
|
+
const { data: { link, campaign_id, notifly_message_id } = {} } = remoteMessage;
|
|
101
101
|
|
|
102
102
|
if (link) {
|
|
103
103
|
Linking.openURL(link);
|
|
104
104
|
}
|
|
105
105
|
await logEvent(
|
|
106
106
|
'push_click',
|
|
107
|
-
{ channel: 'push-notification', type: 'message_event', campaign_id, status: 'quit' },
|
|
107
|
+
{ channel: 'push-notification', type: 'message_event', campaign_id, notifly_message_id, status: 'quit' },
|
|
108
108
|
null,
|
|
109
109
|
true
|
|
110
110
|
);
|
|
@@ -112,3 +112,28 @@ export async function clickHandler(remoteMessage) {
|
|
|
112
112
|
console.warn('[Notifly] custom click handler registration failed.');
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
// React Native does not support Buffer out of the box, so we need to implement our own base64 decoder.
|
|
117
|
+
export function base64Decode(input) {
|
|
118
|
+
const chars =
|
|
119
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
120
|
+
let str = '';
|
|
121
|
+
let output = '';
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < input.length; i += 4) {
|
|
124
|
+
const encoded1 = chars.indexOf(input[i]);
|
|
125
|
+
const encoded2 = chars.indexOf(input[i + 1]);
|
|
126
|
+
const encoded3 = chars.indexOf(input[i + 2]);
|
|
127
|
+
const encoded4 = chars.indexOf(input[i + 3]);
|
|
128
|
+
|
|
129
|
+
const decoded1 = (encoded1 << 2) | (encoded2 >> 4);
|
|
130
|
+
const decoded2 = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
131
|
+
const decoded3 = ((encoded3 & 3) << 6) | encoded4;
|
|
132
|
+
|
|
133
|
+
output += String.fromCharCode(decoded1);
|
|
134
|
+
if (encoded3 !== 64) output += String.fromCharCode(decoded2);
|
|
135
|
+
if (encoded4 !== 64) output += String.fromCharCode(decoded3);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return output;
|
|
139
|
+
}
|