notifly-sdk 2.1.3 → 2.1.4

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
@@ -6,11 +6,69 @@ import logEvent from './src/log_event';
6
6
  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
10
  exports.trackEvent = logEvent;
11
11
  exports.setUserProperties = setUserProperties;
12
12
  exports.clickHandler = clickHandler;
13
13
 
14
+ /**
15
+ * Sets the background message handler for the Notifly SDK.
16
+ * This method should be called in the index.js file of your app.
17
+ * Should be used when you don't have a custom background message handler.
18
+ * @returns {Promise<void>} - A promise that resolves when the background message handler is set.
19
+ * @example
20
+ * setNotiflyBackgroundMessageHandler();
21
+ */
22
+ async function setNotiflyBackgroundMessageHandler() {
23
+ messaging().setBackgroundMessageHandler(notiflyBackgroundHandler);
24
+ }
25
+
26
+ /**
27
+ * The background message handler for the Notifly SDK.
28
+ * This method should be called in the index.js file of your app.
29
+ * Should be used when you have a custom background message handler.
30
+ * @param {Object} remoteMessage - The remote message to handle.
31
+ * @returns {Promise<void>} - A promise that resolves when the background message handler is set.
32
+ * @example
33
+ * messaging().setBackgroundMessageHandler(async remoteMessage => {
34
+ console.log('Existing handler: Background message received:', remoteMessage);
35
+ await notiflyBackgroundHandler(remoteMessage);
36
+ });
37
+ */
38
+ async function notiflyBackgroundHandler(remoteMessage) {
39
+ if (!remoteMessage.notification) {
40
+ return; // TODO(minyong): Discuss if we should log only when notifly_message_type is push-notitification.
41
+ }
42
+ if (!isSetBackgroundHandler) {
43
+ await logEvent(
44
+ 'push_delivered',
45
+ {
46
+ type: 'message_event',
47
+ channel: 'push-notification',
48
+ campaign_id: remoteMessage?.data?.campaign_id,
49
+ notifly_message_id: remoteMessage?.data?.notifly_message_id,
50
+ status: 'quit',
51
+ },
52
+ null,
53
+ true,
54
+ );
55
+ isSetBackgroundHandler = true;
56
+ return;
57
+ }
58
+ await logEvent(
59
+ 'push_delivered',
60
+ {
61
+ type: 'message_event',
62
+ channel: 'push-notification',
63
+ campaign_id: remoteMessage?.data?.campaign_id,
64
+ notifly_message_id: remoteMessage.data?.notifly_message_id,
65
+ status: 'background',
66
+ },
67
+ null,
68
+ true,
69
+ );
70
+ }
71
+
14
72
  /**
15
73
  * Sets the external user ID for the user.
16
74
  *
@@ -52,7 +110,6 @@ exports.setUserId = async function (userID) {
52
110
  exports.initialize = async function (prjId, userName, password, useCustomClickHandler = false) {
53
111
  try {
54
112
  await messaging().requestPermission();
55
-
56
113
  // in-app-message
57
114
  const openedInAppWebViewCount = { count: 0 };
58
115
  messaging().onMessage((remoteMessage) => {
@@ -72,6 +129,7 @@ exports.initialize = async function (prjId, userName, password, useCustomClickHa
72
129
  }
73
130
 
74
131
  messaging().getToken();
132
+ messaging().setDeliveryMetricsExportToBigQuery(true);
75
133
 
76
134
  await Promise.all([
77
135
  AsyncStorage.setItem('notiflyProjectId', prjId),
@@ -118,3 +176,6 @@ async function handleNotificationOpened(remoteMessage) {
118
176
  console.warn('[Notifly] Notification opened handling failed:', err);
119
177
  }
120
178
  }
179
+
180
+ exports.setNotiflyBackgroundMessageHandler = setNotiflyBackgroundMessageHandler;
181
+ exports.notiflyBackgroundHandler = notiflyBackgroundHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifly-sdk",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
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.1.3';
1
+ export const SDK_VERSION = '2.2.4';
2
2
 
3
3
  export const NAMESPACE = {
4
4
  'EVENTID': '830b5f7b-e392-43db-a17b-d835f0bcab2b',
package/src/utils.js CHANGED
@@ -51,15 +51,17 @@ export async function sessionStart() {
51
51
  const brandPromise = rnDeviceInfo.getBrand();
52
52
  const modelPromise = rnDeviceInfo.getModel();
53
53
  const userAgentPromise = rnDeviceInfo.getUserAgent();
54
+ const notifAuthStatusPromise = messaging().hasPermission();
54
55
 
55
- const [deviceModel, deviceBrand, apiLevel, userAgent] = await Promise.all([
56
+ const [deviceModel, deviceBrand, apiLevel, userAgent, notifAuthStatus] = await Promise.all([
56
57
  modelPromise,
57
58
  brandPromise,
58
59
  apiLevelPromise,
59
60
  userAgentPromise,
61
+ notifAuthStatusPromise,
60
62
  ]);
61
63
 
62
- const openAppEventParams = {
64
+ const sessionStartEventParams = {
63
65
  platform,
64
66
  type: 'session_start_event',
65
67
  device_model: deviceModel,
@@ -68,8 +70,9 @@ export async function sessionStart() {
68
70
  api_level: apiLevel,
69
71
  user_agent: userAgent,
70
72
  },
73
+ notif_auth_status: notifAuthStatus,
71
74
  };
72
- await logEvent('session_start', openAppEventParams, null, true);
75
+ await logEvent('session_start', sessionStartEventParams, null, true);
73
76
  }
74
77
 
75
78
  /**