@zoho_apptics/apptics-js-sdk 2.0.0-beta.1 → 2.0.0

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.
Files changed (253) hide show
  1. package/CHANGELOG.md +127 -16
  2. package/README.md +357 -215
  3. package/dist/apptics-pn-sw.js +3 -0
  4. package/dist/apptics-pn-sw.js.map +1 -0
  5. package/dist/apptics.esm.min.js +2 -2
  6. package/dist/apptics.esm.min.js.map +1 -1
  7. package/dist/apptics.min.js +2 -2
  8. package/dist/apptics.min.js.map +1 -1
  9. package/dist/chunks/batch-Axq9sTzR.min.js +3 -0
  10. package/dist/chunks/batch-Axq9sTzR.min.js.map +1 -0
  11. package/dist/chunks/lifecycle-Cvg78jN_.min.js +3 -0
  12. package/dist/chunks/lifecycle-Cvg78jN_.min.js.map +1 -0
  13. package/dist/chunks/send-DBpesydB.min.js +3 -0
  14. package/dist/chunks/send-DBpesydB.min.js.map +1 -0
  15. package/dist/chunks/transport-B21X39p4.min.js +3 -0
  16. package/dist/chunks/transport-B21X39p4.min.js.map +1 -0
  17. package/dist/cjs/core/attempts.js +1 -1
  18. package/dist/cjs/core/batch.js +4 -4
  19. package/dist/cjs/core/consent.d.ts +17 -4
  20. package/dist/cjs/core/consent.js +81 -14
  21. package/dist/cjs/core/console-call.d.ts +23 -0
  22. package/dist/cjs/core/console-call.js +63 -0
  23. package/dist/cjs/core/constants.d.ts +66 -17
  24. package/dist/cjs/core/constants.js +76 -19
  25. package/dist/cjs/core/db.js +31 -7
  26. package/dist/cjs/core/debug.d.ts +6 -4
  27. package/dist/cjs/core/debug.js +36 -12
  28. package/dist/cjs/core/env.d.ts +0 -3
  29. package/dist/cjs/core/env.js +1 -9
  30. package/dist/cjs/core/framework-id.d.ts +1 -1
  31. package/dist/cjs/core/framework-id.js +3 -3
  32. package/dist/cjs/core/guard.js +19 -4
  33. package/dist/cjs/core/hooks.d.ts +29 -0
  34. package/dist/cjs/core/hooks.js +12 -1
  35. package/dist/cjs/core/locks.js +1 -1
  36. package/dist/cjs/core/logger.js +1 -1
  37. package/dist/cjs/core/shield.d.ts +31 -0
  38. package/dist/cjs/core/shield.js +129 -0
  39. package/dist/cjs/core/state.d.ts +11 -5
  40. package/dist/cjs/core/state.js +4 -4
  41. package/dist/cjs/core/storage.d.ts +7 -0
  42. package/dist/cjs/core/storage.js +28 -9
  43. package/dist/cjs/core/stylesheet.js +1 -1
  44. package/dist/cjs/core/transport.d.ts +15 -4
  45. package/dist/cjs/core/transport.js +72 -25
  46. package/dist/cjs/core/utils.js +1 -1
  47. package/dist/cjs/core/validate.js +6 -5
  48. package/dist/cjs/device/appversion.d.ts +10 -1
  49. package/dist/cjs/device/appversion.js +26 -3
  50. package/dist/cjs/device/index.d.ts +17 -2
  51. package/dist/cjs/device/index.js +251 -35
  52. package/dist/cjs/engagement/api-rules.js +1 -1
  53. package/dist/cjs/engagement/auto-api.js +4 -3
  54. package/dist/cjs/engagement/auto-screen.js +10 -6
  55. package/dist/cjs/engagement/defined-events.d.ts +2 -3
  56. package/dist/cjs/engagement/defined-events.js +10 -16
  57. package/dist/cjs/engagement/send.js +7 -3
  58. package/dist/cjs/engagement/session.d.ts +17 -0
  59. package/dist/cjs/engagement/session.js +154 -23
  60. package/dist/cjs/engagement/track.d.ts +4 -4
  61. package/dist/cjs/engagement/track.js +23 -17
  62. package/dist/cjs/errors/send.js +2 -2
  63. package/dist/cjs/errors/track.d.ts +2 -1
  64. package/dist/cjs/errors/track.js +8 -5
  65. package/dist/cjs/feedback/controls.d.ts +36 -4
  66. package/dist/cjs/feedback/controls.js +302 -67
  67. package/dist/cjs/feedback/i18n/index.d.ts +31 -0
  68. package/dist/cjs/feedback/i18n/index.js +187 -0
  69. package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
  70. package/dist/cjs/feedback/i18n/strings.js +8 -0
  71. package/dist/cjs/feedback/index.js +1 -1
  72. package/dist/cjs/feedback/logs.d.ts +3 -6
  73. package/dist/cjs/feedback/logs.js +12 -21
  74. package/dist/cjs/feedback/quartz.js +5 -2
  75. package/dist/cjs/feedback/send.d.ts +6 -3
  76. package/dist/cjs/feedback/send.js +59 -41
  77. package/dist/cjs/feedback/styles.js +2 -2
  78. package/dist/cjs/feedback/template.d.ts +4 -2
  79. package/dist/cjs/feedback/template.js +73 -44
  80. package/dist/cjs/feedback/ui.d.ts +47 -4
  81. package/dist/cjs/feedback/ui.js +351 -97
  82. package/dist/cjs/heatmap/send.d.ts +2 -0
  83. package/dist/cjs/heatmap/send.js +3 -5
  84. package/dist/cjs/heatmap/track.js +13 -9
  85. package/dist/cjs/index.d.ts +1 -2
  86. package/dist/cjs/index.js +55 -18
  87. package/dist/cjs/lifecycle.d.ts +13 -2
  88. package/dist/cjs/lifecycle.js +233 -118
  89. package/dist/cjs/pushnotification/display.d.ts +65 -0
  90. package/dist/cjs/pushnotification/display.js +112 -0
  91. package/dist/cjs/pushnotification/index.d.ts +20 -0
  92. package/dist/cjs/pushnotification/index.js +96 -0
  93. package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
  94. package/dist/cjs/pushnotification/kept-opens.js +64 -0
  95. package/dist/cjs/pushnotification/notify.d.ts +45 -0
  96. package/dist/cjs/pushnotification/notify.js +476 -0
  97. package/dist/cjs/pushnotification/payload.d.ts +65 -0
  98. package/dist/cjs/pushnotification/payload.js +279 -0
  99. package/dist/cjs/pushnotification/session.d.ts +46 -0
  100. package/dist/cjs/pushnotification/session.js +413 -0
  101. package/dist/cjs/pushnotification/stats.d.ts +45 -0
  102. package/dist/cjs/pushnotification/stats.js +244 -0
  103. package/dist/cjs/pushnotification/wms.d.ts +30 -0
  104. package/dist/cjs/pushnotification/wms.js +374 -0
  105. package/dist/cjs/remoteconfig/country.js +1 -1
  106. package/dist/cjs/remoteconfig/custom.js +4 -3
  107. package/dist/cjs/remoteconfig/evaluate.js +1 -1
  108. package/dist/cjs/remoteconfig/fetch.d.ts +17 -10
  109. package/dist/cjs/remoteconfig/fetch.js +146 -32
  110. package/dist/cjs/remoteconfig/index.d.ts +9 -5
  111. package/dist/cjs/remoteconfig/index.js +24 -32
  112. package/dist/cjs/remoteconfig/store.d.ts +15 -7
  113. package/dist/cjs/remoteconfig/store.js +68 -35
  114. package/dist/cjs/remoteconfig/tz-countries.js +1 -1
  115. package/dist/cjs/{core → remotelog}/callsite.d.ts +5 -4
  116. package/dist/cjs/{core → remotelog}/callsite.js +6 -5
  117. package/dist/cjs/remotelog/gate.js +1 -1
  118. package/dist/cjs/remotelog/logger.js +2 -2
  119. package/dist/cjs/remotelog/send.js +6 -5
  120. package/dist/cjs/remotelogger/index.js +1 -1
  121. package/dist/cjs/scheduler.d.ts +3 -1
  122. package/dist/cjs/scheduler.js +34 -25
  123. package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
  124. package/dist/cjs/sw/timers.d.ts +44 -0
  125. package/dist/cjs/types.d.ts +90 -29
  126. package/dist/cjs/user/index.d.ts +7 -0
  127. package/dist/cjs/user/index.js +25 -3
  128. package/dist/esm/core/attempts.js +1 -1
  129. package/dist/esm/core/batch.js +4 -4
  130. package/dist/esm/core/consent.d.ts +17 -4
  131. package/dist/esm/core/consent.js +84 -20
  132. package/dist/esm/core/console-call.d.ts +23 -0
  133. package/dist/esm/core/console-call.js +60 -0
  134. package/dist/esm/core/constants.d.ts +66 -17
  135. package/dist/esm/core/constants.js +73 -20
  136. package/dist/esm/core/db.js +31 -7
  137. package/dist/esm/core/debug.d.ts +6 -4
  138. package/dist/esm/core/debug.js +37 -13
  139. package/dist/esm/core/env.d.ts +0 -3
  140. package/dist/esm/core/env.js +2 -9
  141. package/dist/esm/core/framework-id.d.ts +1 -1
  142. package/dist/esm/core/framework-id.js +3 -3
  143. package/dist/esm/core/guard.js +19 -4
  144. package/dist/esm/core/hooks.d.ts +29 -0
  145. package/dist/esm/core/hooks.js +12 -1
  146. package/dist/esm/core/locks.js +1 -1
  147. package/dist/esm/core/logger.js +1 -1
  148. package/dist/esm/core/shield.d.ts +31 -0
  149. package/dist/esm/core/shield.js +119 -0
  150. package/dist/esm/core/state.d.ts +11 -5
  151. package/dist/esm/core/state.js +4 -4
  152. package/dist/esm/core/storage.d.ts +7 -0
  153. package/dist/esm/core/storage.js +28 -11
  154. package/dist/esm/core/stylesheet.js +1 -1
  155. package/dist/esm/core/transport.d.ts +15 -4
  156. package/dist/esm/core/transport.js +73 -28
  157. package/dist/esm/core/utils.js +1 -1
  158. package/dist/esm/core/validate.js +6 -5
  159. package/dist/esm/device/appversion.d.ts +10 -1
  160. package/dist/esm/device/appversion.js +26 -4
  161. package/dist/esm/device/index.d.ts +17 -2
  162. package/dist/esm/device/index.js +255 -42
  163. package/dist/esm/engagement/api-rules.js +1 -1
  164. package/dist/esm/engagement/auto-api.js +4 -3
  165. package/dist/esm/engagement/auto-screen.js +10 -6
  166. package/dist/esm/engagement/defined-events.d.ts +2 -3
  167. package/dist/esm/engagement/defined-events.js +10 -16
  168. package/dist/esm/engagement/send.js +7 -3
  169. package/dist/esm/engagement/session.d.ts +17 -0
  170. package/dist/esm/engagement/session.js +152 -24
  171. package/dist/esm/engagement/track.d.ts +4 -4
  172. package/dist/esm/engagement/track.js +24 -18
  173. package/dist/esm/errors/send.js +2 -2
  174. package/dist/esm/errors/track.d.ts +2 -1
  175. package/dist/esm/errors/track.js +8 -5
  176. package/dist/esm/feedback/controls.d.ts +36 -4
  177. package/dist/esm/feedback/controls.js +298 -68
  178. package/dist/esm/feedback/i18n/index.d.ts +31 -0
  179. package/dist/esm/feedback/i18n/index.js +178 -0
  180. package/dist/esm/feedback/i18n/strings.d.ts +9 -0
  181. package/dist/esm/feedback/i18n/strings.js +4 -0
  182. package/dist/esm/feedback/index.js +1 -1
  183. package/dist/esm/feedback/logs.d.ts +3 -6
  184. package/dist/esm/feedback/logs.js +12 -21
  185. package/dist/esm/feedback/quartz.js +5 -2
  186. package/dist/esm/feedback/send.d.ts +6 -3
  187. package/dist/esm/feedback/send.js +61 -44
  188. package/dist/esm/feedback/styles.js +2 -2
  189. package/dist/esm/feedback/template.d.ts +4 -2
  190. package/dist/esm/feedback/template.js +73 -44
  191. package/dist/esm/feedback/ui.d.ts +47 -4
  192. package/dist/esm/feedback/ui.js +353 -99
  193. package/dist/esm/heatmap/send.d.ts +2 -0
  194. package/dist/esm/heatmap/send.js +3 -5
  195. package/dist/esm/heatmap/track.js +13 -9
  196. package/dist/esm/index.d.ts +1 -2
  197. package/dist/esm/index.js +58 -21
  198. package/dist/esm/lifecycle.d.ts +13 -2
  199. package/dist/esm/lifecycle.js +238 -125
  200. package/dist/esm/pushnotification/display.d.ts +65 -0
  201. package/dist/esm/pushnotification/display.js +95 -0
  202. package/dist/esm/pushnotification/index.d.ts +20 -0
  203. package/dist/esm/pushnotification/index.js +91 -0
  204. package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
  205. package/dist/esm/pushnotification/kept-opens.js +62 -0
  206. package/dist/esm/pushnotification/notify.d.ts +45 -0
  207. package/dist/esm/pushnotification/notify.js +469 -0
  208. package/dist/esm/pushnotification/payload.d.ts +65 -0
  209. package/dist/esm/pushnotification/payload.js +272 -0
  210. package/dist/esm/pushnotification/session.d.ts +46 -0
  211. package/dist/esm/pushnotification/session.js +402 -0
  212. package/dist/esm/pushnotification/stats.d.ts +45 -0
  213. package/dist/esm/pushnotification/stats.js +238 -0
  214. package/dist/esm/pushnotification/wms.d.ts +30 -0
  215. package/dist/esm/pushnotification/wms.js +368 -0
  216. package/dist/esm/remoteconfig/country.js +1 -1
  217. package/dist/esm/remoteconfig/custom.js +4 -3
  218. package/dist/esm/remoteconfig/evaluate.js +1 -1
  219. package/dist/esm/remoteconfig/fetch.d.ts +17 -10
  220. package/dist/esm/remoteconfig/fetch.js +147 -33
  221. package/dist/esm/remoteconfig/index.d.ts +9 -5
  222. package/dist/esm/remoteconfig/index.js +24 -32
  223. package/dist/esm/remoteconfig/store.d.ts +15 -7
  224. package/dist/esm/remoteconfig/store.js +68 -36
  225. package/dist/esm/remoteconfig/tz-countries.js +1 -1
  226. package/dist/esm/{core → remotelog}/callsite.d.ts +5 -4
  227. package/dist/esm/{core → remotelog}/callsite.js +6 -5
  228. package/dist/esm/remotelog/gate.js +1 -1
  229. package/dist/esm/remotelog/logger.js +2 -2
  230. package/dist/esm/remotelog/send.js +6 -5
  231. package/dist/esm/remotelogger/index.js +1 -1
  232. package/dist/esm/scheduler.d.ts +3 -1
  233. package/dist/esm/scheduler.js +35 -27
  234. package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
  235. package/dist/esm/sw/timers.d.ts +44 -0
  236. package/dist/esm/types.d.ts +90 -29
  237. package/dist/esm/user/index.d.ts +7 -0
  238. package/dist/esm/user/index.js +26 -5
  239. package/dist/feedback.esm.min.js +2 -2
  240. package/dist/feedback.esm.min.js.map +1 -1
  241. package/dist/pushnotification.esm.min.js +3 -0
  242. package/dist/pushnotification.esm.min.js.map +1 -0
  243. package/dist/remoteconfig.esm.min.js +3 -0
  244. package/dist/remoteconfig.esm.min.js.map +1 -0
  245. package/dist/remotelogger.esm.min.js +3 -0
  246. package/dist/remotelogger.esm.min.js.map +1 -0
  247. package/package.json +17 -3
  248. package/dist/chunks/lifecycle-VYr43KcB.min.js +0 -3
  249. package/dist/chunks/lifecycle-VYr43KcB.min.js.map +0 -1
  250. package/dist/cjs/auto-init.d.ts +0 -8
  251. package/dist/cjs/auto-init.js +0 -32
  252. package/dist/esm/auto-init.d.ts +0 -8
  253. package/dist/esm/auto-init.js +0 -29
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var constants = require('../core/constants.js');
@@ -11,6 +11,7 @@ var env = require('../core/env.js');
11
11
  var consent = require('../core/consent.js');
12
12
  var transport = require('../core/transport.js');
13
13
  var hooks = require('../core/hooks.js');
14
+ var shield = require('../core/shield.js');
14
15
  var appversion = require('./appversion.js');
15
16
 
16
17
  /** Server-assigned ids, never sent back in device payloads. */
@@ -108,10 +109,19 @@ function checkAndUpdateDeviceInfo() {
108
109
  storage.user_defaults.add('device_info', state._ZAP._device_info); // no i18n
109
110
  addOrUpdateDeviceID(state._ZAP._device_info, previous);
110
111
  }
112
+ /**
113
+ * Whether device/add has registered this device: it has a deviceid, and while tracking is
114
+ * anonymous the anonymousid its data goes out by. Outside anonymous tracking the anonymousid is
115
+ * not required: nothing else sends it, and requiring it had a server that leaves it out register
116
+ * the same device again on every page load.
117
+ */
118
+ function isRegistered(info) {
119
+ return !!info && !utils.isEmpty(info.deviceid) && (!consent.isAnonymous() || !utils.isEmpty(info.anonymousid));
120
+ }
111
121
  function addOrUpdateDeviceID(device_info, previous) {
112
122
  var old_device_info = previous !== undefined ? previous : storage.user_defaults.item('device_info') || {}; // no i18n
113
123
  // Compare the old and new device infos and update the server if anything changed in the new.
114
- if (device_info.deviceid == null || device_info.frameworkid == null || device_info.anonymousid == null) {
124
+ if (!isRegistered(device_info) || device_info.frameworkid == null) {
115
125
  device_info.frameworkid = state._ZAP._frameworkID;
116
126
  logger.Console.log('addOrUpdateDeviceID: Initiated register the device'); // no i18n
117
127
  registerDeviceWithApptics().then(function (result_device_info) {
@@ -148,6 +158,20 @@ function addOrUpdateDeviceID(device_info, previous) {
148
158
  * out as an empty header.
149
159
  */
150
160
  const DEVICE_RESPONSE_KEYS = ['deviceid', 'anonymousid', 'aaid', 'apid', 'mapid', 'appversionid', 'osversionid', 'timezoneid', 'platformid', 'devicetypeid', 'modelid']; // no i18n
161
+ /** Whether this page has said the server left the anonymousid out; said once, not per call. */
162
+ var missingAnonymousIdSaid = false;
163
+ /**
164
+ * An anonymous browser's data waits for the anonymousid, so an answer to its device/add without
165
+ * one is said out loud, debug or not: otherwise the data sits in storage with no sign of why, and
166
+ * expires after batch_request_timeout.
167
+ */
168
+ function noteMissingAnonymousId(data) {
169
+ if (missingAnonymousIdSaid || !consent.isAnonymous() || !utils.isEmpty(data.anonymousid) || !utils.isEmpty(state._ZAP._device_info.anonymousid)) {
170
+ return;
171
+ }
172
+ missingAnonymousIdSaid = true;
173
+ logger.warnAlways('apptics: device/add answered with no anonymousid for anonymous tracking, so anonymous data is kept, and anonymous feedback not sent, until it does'); // no i18n
174
+ }
151
175
  /** Copies server-assigned ids into state and persists device info; resolves once it is stored. */
152
176
  function applyDeviceResponse(data) {
153
177
  DEVICE_RESPONSE_KEYS.forEach(function (key) {
@@ -165,7 +189,10 @@ function applyDeviceResponse(data) {
165
189
  state._ZAP._mapid = data.mapid;
166
190
  }
167
191
  // stored before the registration counts as done, so another tab waiting to register reads it
168
- return storage.user_defaults.save('device_info', state._ZAP._device_info); // no i18n
192
+ return storage.user_defaults.save('device_info', state._ZAP._device_info).then(function () {
193
+ // push registers by these ids, and may have been waiting for the anonymousid
194
+ hooks.hooks.pushDeviceIdsChanged();
195
+ });
169
196
  }
170
197
  /**
171
198
  * The browser's uuid: the one in storage, or a new one stored now. Every tab of the site uses the
@@ -188,7 +215,7 @@ function useStoredUuid() {
188
215
  function adoptRegisteredDevice() {
189
216
  return storage.reloadSettings(['device_info']).then(function () {
190
217
  var stored = storage.user_defaults.item('device_info') || {}; // no i18n
191
- if (utils.isEmpty(stored.deviceid) || utils.isEmpty(stored.anonymousid)) {
218
+ if (!isRegistered(stored)) {
192
219
  return null;
193
220
  }
194
221
  // the device is registered under the uuid the other tab sent
@@ -213,7 +240,7 @@ function adoptRegisteredDevice() {
213
240
  */
214
241
  function prepareDevice() {
215
242
  var cached = storage.user_defaults.item('device_info') || {}; // no i18n
216
- if (!utils.isEmpty(cached.deviceid) && !utils.isEmpty(cached.anonymousid)) {
243
+ if (isRegistered(cached)) {
217
244
  useStoredUuid();
218
245
  checkAndUpdateDeviceInfo();
219
246
  return Promise.resolve();
@@ -238,7 +265,7 @@ function prepareDevice() {
238
265
  function needsDevice() {
239
266
  // the app ids from app/addversion, and the deviceid from device/add: either missing, and the
240
267
  // device is registered before anything stored is sent
241
- return (utils.isEmpty(transport.getHeaderParams('apid')) && utils.isEmpty(transport.getHeaderParams('mapid'))) || !transport.hasDeviceId(); // no i18n
268
+ return (utils.isEmpty(transport.getHeaderParams('apid')) && utils.isEmpty(transport.getHeaderParams('mapid'))) || !transport.hasSendIds(); // no i18n
242
269
  }
243
270
  /**
244
271
  * Resolves once a registration that is in flight has settled, succeeded or not, and right away
@@ -278,7 +305,7 @@ function registerDeviceWithApptics() {
278
305
  if (offline) {
279
306
  return offline;
280
307
  }
281
- if (state._ZAP._device_info.deviceid && state._ZAP._device_info.anonymousid) {
308
+ if (isRegistered(state._ZAP._device_info)) {
282
309
  return Promise.resolve(state._ZAP._device_info);
283
310
  }
284
311
  return new Promise((resolve, reject) => {
@@ -299,6 +326,7 @@ function registerDeviceWithApptics() {
299
326
  // the time registration runs, so the first call can carry them like every later one.
300
327
  var headers = { zak: transport.getHeaderParams('zak'), uuid: transport.getHeaderParams('uuid'), ...transport.apiHeaders() }; // no i18n
301
328
  return transport.postToApptics('regdevice', payload, headers, label).then(function (result) {
329
+ noteMissingAnonymousId(result.data || {});
302
330
  return applyDeviceResponse(result.data || {}).then(function () {
303
331
  return result;
304
332
  });
@@ -306,8 +334,10 @@ function registerDeviceWithApptics() {
306
334
  }).then(function (result) {
307
335
  settleRegistration(true, result);
308
336
  resolve(result);
309
- // first visit: the ids exist now, so fetch the server settings right away
310
- refreshServerSettings();
337
+ // first visit: the ids exist now, so fetch the server settings right away. A device
338
+ // registered again later (its details or the framework id changed) asks nothing more:
339
+ // start-up has already asked on this page load
340
+ startServerSettingChecks();
311
341
  }).catch(function (err) {
312
342
  settleRegistration(false, err);
313
343
  reject(err);
@@ -324,14 +354,15 @@ function updateDeviceWithApptics(device_info) {
324
354
  var payload = deviceBody(device_info);
325
355
  var headers = { zak: transport.getHeaderParams('zak'), uuid: transport.getHeaderParams('uuid'), ...transport.apiHeaders() }; // no i18n
326
356
  return transport.postToApptics('regdevice', payload, headers, label).then(function (result) {
327
- applyDeviceResponse(result.data || {});
357
+ noteMissingAnonymousId(result.data || {});
358
+ shield.quietly('device/add', applyDeviceResponse(result.data || {})); // no i18n
328
359
  return result;
329
360
  });
330
361
  }
331
362
  // Function to get updates from the server
332
363
  function getUpdatesFromServer() {
333
364
  var label = 'getUpdatesFromServer'; // no i18n
334
- var blocked = transport.rejectIfOffline(label) || transport.rejectIfNoDeviceIds(label);
365
+ var blocked = transport.rejectIfOffline(label) || transport.rejectIfNoDeviceIds(label, 'sdkconfig');
335
366
  if (blocked) {
336
367
  return blocked;
337
368
  }
@@ -339,9 +370,15 @@ function getUpdatesFromServer() {
339
370
  return transport.postToApptics('sdkconfig', '', transport.apiHeaders(), label).then(function (result) {
340
371
  var data = result.data || {};
341
372
  applyServerFlags(data);
373
+ if (state._ZAP._nextConfigCheck === 0) {
374
+ // no next_check_after: getupdates_interval from now, stored so a later page load
375
+ // can tell whether the answer is still current
376
+ state._ZAP._nextConfigCheck = utils.nowMs() + state.getConfig('getupdates_interval'); // no i18n
377
+ state._ZAP._trackinfo.next_check_after = state._ZAP._nextConfigCheck;
378
+ }
342
379
  // the visitor's tracking status lives in trackinfo too, and is not the server's to replace
343
380
  var saved = storage.storedTrackingStatus();
344
- storage.user_defaults.add('trackinfo', saved === undefined ? state._ZAP._trackinfo : Object.assign({}, state._ZAP._trackinfo, { tracking_status: saved })); // no i18n
381
+ storage.user_defaults.add('trackinfo', saved === undefined ? state._ZAP._trackinfo : Object.assign({}, state._ZAP._trackinfo, { tracking_status: storage.trackingStatusCode(saved) })); // no i18n
345
382
  logger.Console.log('getUpdatesFromServer: ' + JSON.stringify(state._ZAP._trackinfo)); // no i18n
346
383
  return data;
347
384
  });
@@ -374,6 +411,10 @@ function applyServerFlags(data) {
374
411
  if (data.hasOwnProperty('tracking_enabled')) { // no i18n
375
412
  state._ZAP._shouldTrack = data.tracking_enabled !== false;
376
413
  }
414
+ else if (data.hasOwnProperty('shouldtrack')) { // no i18n
415
+ // what this SDK saves, read back on the next visit
416
+ state._ZAP._shouldTrack = data.shouldtrack !== false;
417
+ }
377
418
  else {
378
419
  // the old shape: archived versions and untracked customer groups
379
420
  var versionArchived = !data.hasOwnProperty('versionarchivestatus') || utils.isEmpty(data.versionarchivestatus)
@@ -383,9 +424,14 @@ function applyServerFlags(data) {
383
424
  state._ZAP._shouldTrack = versionArchived || !customerGroupTracking;
384
425
  }
385
426
  if (hasModules) {
386
- // sessions carry screens, events and api calls, so module 11 gates all of engagement
387
- state._ZAP._engagementTracking = moduleEnabled(status, constants.SDK_MODULE.SESSION);
388
- state._ZAP._errorTracking = moduleEnabled(status, constants.SDK_MODULE.CRASH);
427
+ // each kind of engagement item has its own module, so the server can turn one off alone
428
+ state._ZAP._engagementTracking = {
429
+ event: moduleEnabled(status, constants.SDK_MODULE.EVENT),
430
+ api: moduleEnabled(status, constants.SDK_MODULE.API),
431
+ screen: moduleEnabled(status, constants.SDK_MODULE.SCREEN),
432
+ session: moduleEnabled(status, constants.SDK_MODULE.SESSION),
433
+ };
434
+ state._ZAP._errorTracking = moduleEnabled(status, constants.SDK_MODULE.JS_ERROR);
389
435
  state._ZAP._heatmapTracking = moduleEnabled(status, constants.SDK_MODULE.HEATMAP);
390
436
  state._ZAP._remoteLoggerEnabled = moduleEnabled(status, constants.SDK_MODULE.REMOTE_LOGGER);
391
437
  state._ZAP._feedbackEnabled = moduleEnabled(status, constants.SDK_MODULE.FEEDBACK);
@@ -394,12 +440,30 @@ function applyServerFlags(data) {
394
440
  state._ZAP._remoteConfigEnabled = moduleEnabled(status, constants.SDK_MODULE.REMOTE_CONFIG);
395
441
  }
396
442
  else {
397
- state._ZAP._engagementTracking = data.engagementtracking !== false;
398
- state._ZAP._errorTracking = data.errortracking !== false;
399
- state._ZAP._heatmapTracking = data.heatmaptracking !== false;
400
- state._ZAP._remoteLoggerEnabled = data.remoteloggerenabled !== false;
401
- state._ZAP._feedbackEnabled = data.feedbackenabled !== false;
443
+ // this SDK saves one flag per kind under engagement; an earlier build saved one
444
+ // engagementtracking flag for all four
445
+ var saved = (data.engagement && typeof data.engagement === 'object' // no i18n
446
+ ? data.engagement : null);
447
+ var kindOn = function (kind) {
448
+ return saved ? saved[kind] !== false : data.engagementtracking !== false;
449
+ };
450
+ state._ZAP._engagementTracking = { event: kindOn('event'), api: kindOn('api'), screen: kindOn('screen'), session: kindOn('session') }; // no i18n
451
+ // the same for the others: read the short key this SDK saves, else the earlier build's
452
+ var flagOn = function (key, oldKey) {
453
+ return (data.hasOwnProperty(key) ? data[key] : data[oldKey]) !== false;
454
+ };
455
+ state._ZAP._errorTracking = flagOn('error', 'errortracking'); // no i18n
456
+ state._ZAP._heatmapTracking = flagOn('heatmap', 'heatmaptracking'); // no i18n
457
+ state._ZAP._remoteLoggerEnabled = flagOn('remotelogger', 'remoteloggerenabled'); // no i18n
458
+ state._ZAP._feedbackEnabled = flagOn('feedback', 'feedbackenabled'); // no i18n
402
459
  }
460
+ // push notification: module 16 and the wms block it comes with. Live, the module flag decides;
461
+ // restored, the flag this SDK saved; with neither, the block itself, which the server sends
462
+ // only when push is on. Either way it is off without a usable wms block
463
+ state._ZAP._wmsConfig = wmsConfigFrom(data.wms);
464
+ var pushFlag = hasModules ? moduleEnabled(status, constants.SDK_MODULE.PUSH_NOTIFICATION)
465
+ : (data.hasOwnProperty('push') ? data.push === true : true); // no i18n
466
+ state._ZAP._pushEnabled = pushFlag && state._ZAP._wmsConfig !== null;
403
467
  // screen recording, set up in the console: everything the form needs comes from here
404
468
  var quartz = (data.quartz && typeof data.quartz === 'object' ? data.quartz : {});
405
469
  var text = function (value) {
@@ -412,16 +476,15 @@ function applyServerFlags(data) {
412
476
  domain: text(quartz.quartz_domain),
413
477
  cdnUrl: text(quartz.quartz_cdn_url),
414
478
  };
415
- // when to ask again, which replaces polling on a fixed interval
416
- if (typeof data.next_check_after === 'number' && data.next_check_after > 0) {
417
- state._ZAP._nextConfigCheck = data.next_check_after;
418
- }
479
+ // when to ask again, which replaces polling on a fixed interval. Kept as a timestamp, so the
480
+ // stored copy reads back the same. An answer without one falls back to getupdates_interval
481
+ state._ZAP._nextConfigCheck = nextCheckTime(data.next_check_after, utils.nowMs());
419
482
  state._ZAP._trackinfo = {
420
- engagementtracking: state._ZAP._engagementTracking,
421
- errortracking: state._ZAP._errorTracking,
422
- heatmaptracking: state._ZAP._heatmapTracking,
423
- remoteloggerenabled: state._ZAP._remoteLoggerEnabled,
424
- feedbackenabled: state._ZAP._feedbackEnabled,
483
+ engagement: state._ZAP._engagementTracking,
484
+ error: state._ZAP._errorTracking,
485
+ heatmap: state._ZAP._heatmapTracking,
486
+ remotelogger: state._ZAP._remoteLoggerEnabled,
487
+ feedback: state._ZAP._feedbackEnabled,
425
488
  // in the server's own shape, so restoring it on the next visit reads it the same way
426
489
  quartz: {
427
490
  quartz_enabled: state._ZAP._quartz.enabled,
@@ -431,7 +494,27 @@ function applyServerFlags(data) {
431
494
  quartz_cdn_url: state._ZAP._quartz.cdnUrl,
432
495
  },
433
496
  shouldtrack: state._ZAP._shouldTrack,
434
- next_check_after: state._ZAP._nextConfigCheck
497
+ next_check_after: state._ZAP._nextConfigCheck,
498
+ push: state._ZAP._pushEnabled,
499
+ wms: state._ZAP._wmsConfig,
500
+ };
501
+ // a no-op unless the push entry was imported, which sets the hook
502
+ hooks.hooks.pushConfigChanged();
503
+ }
504
+ /** getsdkconfig's wms block, or null when it has no wms_js_url to load. */
505
+ function wmsConfigFrom(value) {
506
+ if (!value || typeof value !== 'object') { // no i18n
507
+ return null;
508
+ }
509
+ var wms = value;
510
+ if (typeof wms.wms_js_url !== 'string' || wms.wms_js_url.trim() === '') { // no i18n
511
+ return null;
512
+ }
513
+ var sriValues = wms.wms_sri_values && typeof wms.wms_sri_values === 'object' ? wms.wms_sri_values : null; // no i18n
514
+ return {
515
+ wms_js_url: wms.wms_js_url.trim(),
516
+ wms_sri: typeof wms.wms_sri === 'string' ? wms.wms_sri : '', // no i18n
517
+ wms_sri_values: sriValues,
435
518
  };
436
519
  }
437
520
  /**
@@ -442,31 +525,164 @@ function restoreServerSettings() {
442
525
  var saved = storage.user_defaults.item('trackinfo'); // no i18n
443
526
  if (saved && typeof saved === 'object') { // no i18n
444
527
  applyServerFlags(saved);
528
+ // saved by an earlier build under the old names: store it again in this SDK's shape now,
529
+ // rather than at the next getsdkconfig, which may be a while off. The visitor's tracking
530
+ // status is kept as it is
531
+ if (OLD_TRACKINFO_KEYS.some(function (key) { return saved.hasOwnProperty(key); })) {
532
+ storage.user_defaults.add('trackinfo', saved.tracking_status === undefined ? state._ZAP._trackinfo // no i18n
533
+ : Object.assign({}, state._ZAP._trackinfo, { tracking_status: saved.tracking_status }));
534
+ }
445
535
  logger.Console.log('restoreServerSettings: ' + JSON.stringify(state._ZAP._trackinfo)); // no i18n
446
536
  }
447
537
  }
538
+ /** trackinfo keys an earlier build saved, which this SDK saves under shorter names. */
539
+ var OLD_TRACKINFO_KEYS = ['engagementtracking', 'errortracking', 'heatmaptracking', 'remoteloggerenabled', 'feedbackenabled']; // no i18n
448
540
  /**
449
- * Fetches the server settings now if the device is registered. On a first visit the ids don't
450
- * exist yet; registerDeviceWithApptics calls this as soon as device/add succeeds.
541
+ * next_check_after as a time: the server's value is milliseconds, either a timestamp or a wait
542
+ * from now. Anything below 1e12 (2001 as a timestamp) can only be a wait.
543
+ */
544
+ function nextCheckTime(value, now) {
545
+ if (typeof value !== 'number' || !(value > 0)) { // no i18n
546
+ return 0;
547
+ }
548
+ return value >= 1e12 ? value : now + value;
549
+ }
550
+ /** setTimeout's longest wait; a longer one fires straight away. */
551
+ var MAX_TIMEOUT = 2147483647;
552
+ var configTimer = null;
553
+ var configInFlight = false;
554
+ /** Bumped by stopServerSettingChecks(), so an answer to an ask from before a reset schedules nothing. */
555
+ var configRound = 0;
556
+ /** Whether this page load has asked, or set the timer from the saved answer instead. */
557
+ var configAsked = false;
558
+ /** A user registered, or getupdates reported a change, while a getsdkconfig was in flight: asked again when it answers. */
559
+ var configAskAgain = false;
560
+ /** When the next getsdkconfig is due, as a timestamp. 0 until the first answer. */
561
+ var configDueAt = 0;
562
+ /**
563
+ * Asks for the server settings now if the device is registered, then schedules the next ask
564
+ * for the time the answer gave in next_check_after. On a first visit the ids don't exist yet;
565
+ * registerDeviceWithApptics calls this as soon as device/add succeeds.
451
566
  */
452
567
  function refreshServerSettings() {
453
- if (utils.isEmpty(transport.getHeaderParams('apid')) && utils.isEmpty(transport.getHeaderParams('mapid'))) { // no i18n
568
+ if (configInFlight || !transport.hasDeviceId() || (utils.isEmpty(transport.getHeaderParams('apid')) && utils.isEmpty(transport.getHeaderParams('mapid')))) { // no i18n
454
569
  return;
455
570
  }
456
- getUpdatesFromServer().catch(function (err) {
571
+ if (configTimer !== null) {
572
+ clearTimeout(configTimer);
573
+ configTimer = null;
574
+ }
575
+ configInFlight = true;
576
+ configAsked = true;
577
+ markTabAsked();
578
+ var round = configRound;
579
+ var askedAt = utils.nowMs();
580
+ shield.quietly('getsdkconfig', getUpdatesFromServer().catch(function (err) {
457
581
  logger.Console.log(err);
458
- });
582
+ }).then(function () {
583
+ if (round !== configRound) {
584
+ // stopServerSettingChecks() ran while this was in flight
585
+ return;
586
+ }
587
+ configInFlight = false;
588
+ if (configAskAgain) {
589
+ configAskAgain = false;
590
+ refreshServerSettings();
591
+ return;
592
+ }
593
+ // an answer without a usable next_check_after, or a failed call, waits getupdates_interval
594
+ configDueAt = state._ZAP._nextConfigCheck > utils.nowMs() ? state._ZAP._nextConfigCheck : askedAt + state.getConfig('getupdates_interval'); // no i18n
595
+ scheduleServerSettingCheck();
596
+ }));
597
+ }
598
+ /**
599
+ * getsdkconfig now, not at the next check: setUser registered a user, or getupdates reported a
600
+ * module changed.
601
+ */
602
+ function askServerSettings() {
603
+ if (configInFlight) {
604
+ // the one in flight went out before the change: ask again once it answers
605
+ configAskAgain = true;
606
+ return;
607
+ }
608
+ refreshServerSettings();
609
+ }
610
+ /**
611
+ * Start-up's getsdkconfig. Asked on a first visit and on the first page load in each tab; any
612
+ * other load (a reload, a link to another page of the site, back/forward) uses the saved answer
613
+ * and waits for its next_check_after, unless that has already passed. Nothing happens if one has
614
+ * gone out already on this load (after device/add).
615
+ */
616
+ function startServerSettingChecks() {
617
+ if (configAsked) {
618
+ return;
619
+ }
620
+ if (tabHasAsked() && state._ZAP._nextConfigCheck > utils.nowMs()) {
621
+ logger.Console.log('getsdkconfig: the saved answer is still current'); // no i18n
622
+ configAsked = true;
623
+ configDueAt = state._ZAP._nextConfigCheck;
624
+ scheduleServerSettingCheck();
625
+ return;
626
+ }
627
+ refreshServerSettings();
628
+ }
629
+ /** sessionStorage: per tab, and kept across a reload and the site's own links. */
630
+ var TAB_ASKED_KEY = '_apptics_sdkconfig_asked'; // no i18n
631
+ /** Whether getsdkconfig has gone out in this tab before, on an earlier page load. */
632
+ function tabHasAsked() {
633
+ try {
634
+ return sessionStorage.getItem(TAB_ASKED_KEY) === '1'; // no i18n
635
+ }
636
+ catch (e) {
637
+ return false; // no sessionStorage (private mode, sandboxed frame): every load asks
638
+ }
639
+ }
640
+ function markTabAsked() {
641
+ try {
642
+ sessionStorage.setItem(TAB_ASKED_KEY, '1'); // no i18n
643
+ }
644
+ catch (e) {
645
+ // as above: without it, every load asks
646
+ }
647
+ }
648
+ /** Sets the timer for the next getsdkconfig, at configDueAt. */
649
+ function scheduleServerSettingCheck() {
650
+ if (configTimer !== null) {
651
+ clearTimeout(configTimer);
652
+ }
653
+ var wait = Math.min(Math.max(configDueAt - utils.nowMs(), 0), MAX_TIMEOUT);
654
+ logger.Console.log('getsdkconfig: next check in ' + wait + ' ms'); // no i18n
655
+ configTimer = setTimeout(shield.shield('getsdkconfig', function () {
656
+ configTimer = null;
657
+ refreshServerSettings();
658
+ }), wait);
659
+ }
660
+ /** reset(): no more checks, and the next init() asks again straight away. */
661
+ function stopServerSettingChecks() {
662
+ if (configTimer !== null) {
663
+ clearTimeout(configTimer);
664
+ }
665
+ configTimer = null;
666
+ configRound++;
667
+ configInFlight = false;
668
+ configAsked = false;
669
+ configAskAgain = false;
670
+ configDueAt = 0;
459
671
  }
460
672
  hooks.hooks.updateDevice = updateDeviceWithApptics;
461
673
  hooks.hooks.refreshDeviceInfo = checkAndUpdateDeviceInfo;
674
+ hooks.hooks.askServerSettings = askServerSettings;
462
675
 
463
676
  exports.addOrUpdateDeviceID = addOrUpdateDeviceID;
464
677
  exports.checkAndUpdateDeviceInfo = checkAndUpdateDeviceInfo;
465
678
  exports.deviceReady = deviceReady;
466
679
  exports.getUpdatesFromServer = getUpdatesFromServer;
467
680
  exports.needsDevice = needsDevice;
681
+ exports.nextCheckTime = nextCheckTime;
468
682
  exports.prepareDevice = prepareDevice;
469
683
  exports.refreshServerSettings = refreshServerSettings;
470
684
  exports.registerDeviceWithApptics = registerDeviceWithApptics;
471
685
  exports.restoreServerSettings = restoreServerSettings;
686
+ exports.startServerSettingChecks = startServerSettingChecks;
687
+ exports.stopServerSettingChecks = stopServerSettingChecks;
472
688
  exports.updateDeviceWithApptics = updateDeviceWithApptics;
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var logger = require('../core/logger.js');
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var state = require('../core/state.js');
@@ -6,6 +6,7 @@ var logger = require('../core/logger.js');
6
6
  var utils = require('../core/utils.js');
7
7
  var track = require('./track.js');
8
8
  var apiRules = require('./api-rules.js');
9
+ var shield = require('../core/shield.js');
9
10
 
10
11
  /**
11
12
  * Automatic API tracking: wraps XMLHttpRequest and fetch so calls the app makes are recorded
@@ -131,10 +132,10 @@ function installXhr() {
131
132
  tracked.starttime = utils.nowMs();
132
133
  // loadend fires for success, error, abort and timeout alike, so one listener covers
133
134
  // every ending; status 0 is how a network failure arrives here
134
- this.addEventListener('loadend', function () {
135
+ this.addEventListener('loadend', shield.shield('automatic api tracking', function () {
135
136
  var message = this.status === 0 ? 'Network Error' : (this.statusText || '-'); // no i18n
136
137
  record(tracked.method, tracked.url, tracked.starttime, this.status, message);
137
- });
138
+ }));
138
139
  }
139
140
  return originalSend.apply(this, arguments);
140
141
  };
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var logger = require('../core/logger.js');
@@ -6,6 +6,7 @@ var hooks = require('../core/hooks.js');
6
6
  var state = require('../core/state.js');
7
7
  var utils = require('../core/utils.js');
8
8
  var track = require('./track.js');
9
+ var shield = require('../core/shield.js');
9
10
 
10
11
  /**
11
12
  * Automatic screen tracking: a screen view for the page the SDK starts on, and one for every
@@ -165,7 +166,7 @@ function check() {
165
166
  state._ZAP._current_screen = Object.assign({}, state._ZAP._current_screen, { screen: name });
166
167
  pendingName = name;
167
168
  pendingAt = utils.nowMs();
168
- settleTimer = setTimeout(settle, settleMs);
169
+ settleTimer = setTimeout(shield.shield('automatic screen tracking', settle), settleMs); // no i18n
169
170
  }
170
171
  function settle() {
171
172
  settleTimer = null;
@@ -200,7 +201,10 @@ function cancelPending() {
200
201
  * that followed found the url already seen and recorded nothing: the page went untracked and the
201
202
  * view before it was never ended.
202
203
  */
203
- function navigated() {
204
+ const checkShielded = shield.shield('automatic screen tracking', check); // no i18n
205
+ // shielded: it runs inside the app's own history.pushState and replaceState calls, and a throw
206
+ // here would reach the app's code
207
+ const navigated = shield.shield('automatic screen tracking', function () {
204
208
  var name = currentName();
205
209
  if (name !== '' && (name === pendingName || (pendingName === '' && name === lastName))) { // no i18n
206
210
  return;
@@ -208,9 +212,9 @@ function navigated() {
208
212
  if (timer === null) {
209
213
  claimed = false;
210
214
  cancelPending();
211
- timer = setTimeout(check, 0);
215
+ timer = setTimeout(checkShielded, 0);
212
216
  }
213
- }
217
+ });
214
218
  /** The app recorded a screen itself; the automatic view of this navigation gives way to it. */
215
219
  function screenTrackedByApp() {
216
220
  claimed = true;
@@ -272,7 +276,7 @@ function enableScreenTracking(enabled, wait) {
272
276
  // the page the SDK starts on. Not through navigated(): a inScreen() the app made during
273
277
  // start-up was replayed just before this, and it is this screen's, so its claim stands
274
278
  if (timer === null) {
275
- timer = setTimeout(check, 0);
279
+ timer = setTimeout(checkShielded, 0);
276
280
  }
277
281
  return;
278
282
  }
@@ -1,13 +1,12 @@
1
1
  /**
2
- * Apptics' defined events, as Android's DefinedEvents: ready-made names in reserved `AP_` groups,
2
+ * Apptics' defined events for the browser: ready-made names in reserved `AP_` groups,
3
3
  * logged with trackEvent like any other event and never tracked automatically.
4
4
  *
5
5
  * trackEvent(DefinedEvents.AP_USER_LOGIN);
6
6
  * trackEvent(DefinedEvents.AP_SEARCH, { query_length: 12 });
7
7
  *
8
8
  * They are the only events allowed the `ap_` prefix: an app's own event, group or property may
9
- * not start with it. The list is Android's, so the console reads them the same from every platform;
10
- * some (battery, OS update, uninstall) have no meaning in a browser and are simply never sent.
9
+ * not start with it.
11
10
  */
12
11
  /** One defined event: the name and the group it is sent under. */
13
12
  export interface DefinedEvent {
@@ -1,35 +1,29 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  /**
5
- * Apptics' defined events, as Android's DefinedEvents: ready-made names in reserved `AP_` groups,
5
+ * Apptics' defined events for the browser: ready-made names in reserved `AP_` groups,
6
6
  * logged with trackEvent like any other event and never tracked automatically.
7
7
  *
8
8
  * trackEvent(DefinedEvents.AP_USER_LOGIN);
9
9
  * trackEvent(DefinedEvents.AP_SEARCH, { query_length: 12 });
10
10
  *
11
11
  * They are the only events allowed the `ap_` prefix: an app's own event, group or property may
12
- * not start with it. The list is Android's, so the console reads them the same from every platform;
13
- * some (battery, OS update, uninstall) have no meaning in a browser and are simply never sent.
12
+ * not start with it.
14
13
  */
15
14
  const GROUPS = {
16
- AP_APP_LIFE_CYCLE: [
17
- 'AP_APP_INSTALL', 'AP_APP_UNINSTALL', 'AP_APP_UPDATE', 'AP_APP_CRACKED', 'AP_APP_OPEN', 'AP_APP_CLEAR_DATA', // no i18n
18
- 'AP_APP_FOREGROUND', 'AP_APP_BACKGROUND', 'AP_APP_OUT_OF_MEMORY', 'AP_APP_FIRST_OPEN', 'AP_APP_LAUNCHING', // no i18n
19
- 'AP_APP_RESIGN_ACTIVE', 'AP_APP_WILL_CONNECT', // no i18n
20
- ],
21
15
  AP_USER_LIFE_CYCLE: ['AP_USER_SIGNUP', 'AP_USER_LOGIN', 'AP_USER_LOGOUT'], // no i18n
16
+ AP_PAGE_LIFE_CYCLE: ['AP_PAGE_LOAD', 'AP_PAGE_VISIBLE', 'AP_PAGE_HIDDEN', 'AP_PAGE_UNLOAD', 'AP_PAGE_PRINT'], // no i18n
22
17
  AP_APPLICATION: [
23
- 'AP_DEEP_LINK_OPEN', 'AP_DEEP_LINK_UPDATE', 'AP_DEEP_LINK_FIRST_OPEN', 'AP_IN_APP_PURCHASE', // no i18n
24
- 'AP_NOTIFICATION_RECEIVE', 'AP_NOTIFICATION_OPEN', 'AP_NOTIFICATION_DISMISS', 'AP_NOTIFICATION_FOREGROUND', // no i18n
25
- 'AP_SEARCH', 'AP_BATTERY_LOW', 'AP_BATTERY_FULL', 'AP_LOW_POWER_MODE_ON', 'AP_LOW_POWER_MODE_OFF', // no i18n
18
+ 'AP_PWA_INSTALL', 'AP_PWA_LAUNCH', 'AP_PURCHASE', 'AP_SEARCH', 'AP_SHARE', 'AP_FILE_DOWNLOAD', 'AP_COPY', // no i18n
19
+ 'AP_NOTIFICATION_RECEIVE', 'AP_NOTIFICATION_OPEN', 'AP_NOTIFICATION_DISMISS', // no i18n
20
+ 'AP_NOTIFICATION_PERMISSION_GRANTED', 'AP_NOTIFICATION_PERMISSION_DENIED', // no i18n
26
21
  ],
27
22
  AP_OTHERS: [
28
- 'AP_NETWORK_REACHABILITY_CHANGE', 'AP_NETWORK_BANDWIDTH_CHANGE', 'AP_SWITCH_THEME_LIGHT', // no i18n
29
- 'AP_SWITCH_THEME_DARK', 'AP_SWITCH_THEME_CUSTOM', 'AP_SWITCH_ORIENTATION_LANDSCAPE', // no i18n
30
- 'AP_SWITCH_ORIENTATION_PORTRAIT', // no i18n
23
+ 'AP_NETWORK_ONLINE', 'AP_NETWORK_OFFLINE', 'AP_SWITCH_THEME_LIGHT', 'AP_SWITCH_THEME_DARK', // no i18n
24
+ 'AP_SWITCH_THEME_CUSTOM', 'AP_SWITCH_LANGUAGE', 'AP_FULLSCREEN_ENTER', 'AP_FULLSCREEN_EXIT', // no i18n
31
25
  ],
32
- AP_OS: ['AP_OS_UPDATE', 'AP_OS_UNSUPPORTED'], // no i18n
26
+ AP_BROWSER: ['AP_BROWSER_UPDATE', 'AP_BROWSER_UNSUPPORTED'], // no i18n
33
27
  };
34
28
  function build() {
35
29
  var out = {};
@@ -1,4 +1,4 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
2
  'use strict';
3
3
 
4
4
  var constants = require('../core/constants.js');
@@ -15,8 +15,7 @@ var transport = require('../core/transport.js');
15
15
  * Sends pending engagements to the Apptics API.
16
16
  */
17
17
  function sendEngagementData(forget) {
18
- // engagementtracking off (getupdates): queued items stay until tracking is back on or they expire
19
- if (env.is_apptics_disabled() || !consent.shouldTrackOrSendData() || !state._ZAP._engagementTracking) {
18
+ if (env.is_apptics_disabled() || !consent.shouldTrackOrSendData()) {
20
19
  return Promise.resolve();
21
20
  }
22
21
  if (navigator.onLine == false) {
@@ -39,6 +38,11 @@ function sendEngagementData(forget) {
39
38
  var _payload = {};
40
39
  var sent = [];
41
40
  utils.cloneObject(engagement_items).forEach(function (item) {
41
+ // a kind the server has turned off (getsdkconfig's event, api, screen or session
42
+ // module) stays queued until it is back on or the item expires
43
+ if (state._ZAP._engagementTracking[item.type] === false) {
44
+ return;
45
+ }
42
46
  const itemWithId = { ...item };
43
47
  if (item.type == constants.AP_CONSTANTS.EVENT) {
44
48
  eventObj.push(item);