notifly-sdk 2.1.4 → 2.2.5

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 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
- // push
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifly-sdk",
3
- "version": "2.1.4",
3
+ "version": "2.2.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/constant.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = '2.2.4';
1
+ export const SDK_VERSION = '2.2.5';
2
2
 
3
3
  export const NAMESPACE = {
4
4
  'EVENTID': '830b5f7b-e392-43db-a17b-d835f0bcab2b',
@@ -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,6 +39,7 @@ 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
  `;
@@ -98,6 +100,21 @@ export async function showInAppMessage(data, openedInAppWebViewCount) {
98
100
  [key]: true,
99
101
  });
100
102
  }
103
+ } else if (message.type === 'survey_submit_button') {
104
+ modal.destroy();
105
+ openedInAppWebViewCount.count = openedInAppWebViewCount.count - 1;
106
+ logEvent(
107
+ 'survey_submit_button_click', {
108
+ type: 'message_event',
109
+ channel: 'in-app-message',
110
+ button_name: message.button_name,
111
+ campaign_id: data.campaign_id,
112
+ notifly_message_id: data.notifly_message_id,
113
+ notifly_extra_data: message.extra_data,
114
+ },
115
+ null,
116
+ true
117
+ );
101
118
  }
102
119
  };
103
120
 
package/src/log_event.js CHANGED
@@ -169,6 +169,7 @@ function _getBodyForLogEvent(
169
169
  os_version: osVersion,
170
170
  app_version: appVersion,
171
171
  sdk_version: SDK_VERSION,
172
+ sdk_type: "react_native",
172
173
  external_user_id: externalUserId || undefined,
173
174
  });
174
175
 
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;