@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
  import { AP_CONSTANTS, AP_LOG_MODULE } from '../core/constants.js';
3
3
  import { _ZAP, getConfig } from '../core/state.js';
4
4
  import { logFailure, Console } from '../core/logger.js';
@@ -7,6 +7,7 @@ import { engagement_transactions, getKeyFromDeviceInfo, setDeviceInfoKey } from
7
7
  import { is_apptics_disabled, getNetworkStatus, getOrientation, getConnectionType, getRam } from '../core/env.js';
8
8
  import { canTrackEngagement } from '../core/consent.js';
9
9
  import { withLock } from '../core/locks.js';
10
+ import { shield, quietly } from '../core/shield.js';
10
11
 
11
12
  /** The most recently started item of `type` that is still open (endtime 0). */
12
13
  function latestOpen(type, items) {
@@ -62,7 +63,7 @@ function closeScreensOf(session, time) {
62
63
  * @param sessionData A set of properties belonging to the session.
63
64
  */
64
65
  function trackSession(sessionData) {
65
- if (!canTrackEngagement('trackSession')) { // no i18n
66
+ if (!canTrackEngagement('trackSession', AP_CONSTANTS.SESSION)) { // no i18n
66
67
  return Promise.resolve();
67
68
  }
68
69
  if (sessionData && typeof sessionData !== 'object') { // no i18n
@@ -149,13 +150,12 @@ function holdTabLock() {
149
150
  holdingTabLock = false;
150
151
  });
151
152
  }
152
- /** Ends the open screen views of tabs that are gone. Resolves right away without Web Locks. */
153
- function closeScreensOfGoneTabs() {
153
+ /** The ids of tabs whose lock is held or waiting, or null without Web Locks (or if asking fails). */
154
+ function liveTabIds() {
154
155
  var locks = tabLocks();
155
156
  if (!locks) {
156
- return Promise.resolve();
157
+ return Promise.resolve(null);
157
158
  }
158
- var mine = tabId();
159
159
  return locks.query().then(function (state) {
160
160
  var alive = {};
161
161
  (state.held || []).concat(state.pending || []).forEach(function (lock) {
@@ -163,6 +163,42 @@ function closeScreensOfGoneTabs() {
163
163
  alive[lock.name.slice(TAB_LOCK_PREFIX.length)] = true;
164
164
  }
165
165
  });
166
+ return alive;
167
+ }, function () {
168
+ return null;
169
+ });
170
+ }
171
+ /**
172
+ * The other tabs still on a session. A tab that reloaded or closed before its leave was written
173
+ * stays listed, and would keep the session open for good: with Web Locks, a listed tab counts only
174
+ * while its lock is held. Without them every listed tab counts, as before.
175
+ */
176
+ function otherLiveTabs(session) {
177
+ var others = tabsOf(session).filter(function (tab) { return tab !== tabId(); });
178
+ if (!others.length) {
179
+ return Promise.resolve(others);
180
+ }
181
+ return liveTabIds().then(function (alive) {
182
+ if (!alive) {
183
+ return others;
184
+ }
185
+ var live = others.filter(function (tab) { return alive[tab] === true; });
186
+ if (live.length < others.length) {
187
+ Console.log('session: ' + (others.length - live.length) + ' tab(s) listed on it are gone'); // no i18n
188
+ }
189
+ return live;
190
+ });
191
+ }
192
+ /** Ends the open screen views of tabs that are gone. Resolves right away without Web Locks. */
193
+ function closeScreensOfGoneTabs() {
194
+ if (!tabLocks()) {
195
+ return Promise.resolve();
196
+ }
197
+ var mine = tabId();
198
+ return liveTabIds().then(function (alive) {
199
+ if (!alive) {
200
+ return;
201
+ }
166
202
  var now = nowMs();
167
203
  return engagement_transactions.all().then(function (items) {
168
204
  var gone = items.filter(function (item) {
@@ -305,10 +341,10 @@ function startNewSession(time) {
305
341
  // held, not stored: see pendingSession above
306
342
  pendingSession = _ZAP._current_session;
307
343
  clearPendingTimer();
308
- pendingTimer = setTimeout(function () {
344
+ pendingTimer = setTimeout(shield('session', function () {
309
345
  pendingTimer = null;
310
- commitPendingSession();
311
- }, minimum);
346
+ quietly('session', commitPendingSession()); // no i18n
347
+ }), minimum);
312
348
  return Promise.resolve();
313
349
  }
314
350
  /** The un-deferred path, for a minimum of 0. */
@@ -318,38 +354,130 @@ function commitNow(session) {
318
354
  }
319
355
  return trackSession(session);
320
356
  }
357
+ /** Whether this tab is inactive: hidden, minimised, or its window has lost focus. */
358
+ var inactive = false;
359
+ var inactivityTimer = null;
360
+ /**
361
+ * The tab went inactive. That moment becomes the session's lastactivetime, the time it ends at if
362
+ * the user does not come back within inactiveduration. If they do not, the session is ended at it
363
+ * then, and `onEnded` sends it, rather than staying open until they return or the tab closes.
364
+ * Going inactive twice (a window blur, then the tab hidden) keeps the first moment.
365
+ */
366
+ function markTabInactive(onEnded) {
367
+ var first = !inactive;
368
+ inactive = true;
369
+ if (inactivityTimer !== null) {
370
+ clearTimeout(inactivityTimer);
371
+ }
372
+ inactivityTimer = setTimeout(shield('inactive session', function () {
373
+ inactivityTimer = null;
374
+ quietly('inactive session', endInactiveSession().then(function (ended) {
375
+ if (ended) {
376
+ onEnded();
377
+ }
378
+ }));
379
+ }), _ZAP.inactiveduration * 60 * 1000 + 1000);
380
+ return first ? updateLastActiveTimeOfSession() : Promise.resolve();
381
+ }
382
+ /**
383
+ * The tab is active again. The caller then settles the session (checkAndUpdateSession): back
384
+ * within inactiveduration it continues, later it has ended and a new one starts.
385
+ */
386
+ function markTabActive() {
387
+ inactive = false;
388
+ if (inactivityTimer !== null) {
389
+ clearTimeout(inactivityTimer);
390
+ inactivityTimer = null;
391
+ }
392
+ }
393
+ /** reset(): no timer left running, and the tab counts as active. */
394
+ function resetInactivity() {
395
+ markTabActive();
396
+ }
397
+ /**
398
+ * inactiveduration has passed with the tab inactive: the session ends at its lastactivetime, when
399
+ * the user left, so the time away is not counted. Resolves true when it ended one. While another
400
+ * tab of the site is still on the session, this tab only leaves it; one whose lastactivetime is
401
+ * recent is in use elsewhere and is left alone.
402
+ */
403
+ function endInactiveSession() {
404
+ if (!_ZAP._token || is_apptics_disabled()) {
405
+ return Promise.resolve(false);
406
+ }
407
+ var ended = false;
408
+ return withSessionLock(function () {
409
+ return currentSession().then(function (_currentSession) {
410
+ if (!_currentSession || _currentSession.endtime !== 0) {
411
+ return;
412
+ }
413
+ var lastActive = Number(_currentSession.lastactivetime) || nowMs();
414
+ if (nowMs() - lastActive < _ZAP.inactiveduration * 60 * 1000) {
415
+ return;
416
+ }
417
+ var session = _currentSession;
418
+ return otherLiveTabs(session).then(function (others) {
419
+ if (others.length > 0) {
420
+ var left = Object.assign({}, session, { tabs: others });
421
+ _ZAP._current_session = left;
422
+ return engagement_transactions.update(left);
423
+ }
424
+ var endAt = Math.max(lastActive, Number(session.starttime) || lastActive);
425
+ var closed = Object.assign({}, session, { endtime: endAt, tabs: [] });
426
+ _ZAP._current_session = closed;
427
+ ended = true;
428
+ Console.log('session: inactive for ' + _ZAP.inactiveduration + ' minutes, so it ends when the user left, ' + endAt); // no i18n
429
+ return engagement_transactions.update(closed).then(function () {
430
+ return closeScreensOf(closed, endAt);
431
+ });
432
+ });
433
+ });
434
+ }).then(function () {
435
+ return ended;
436
+ });
437
+ }
321
438
  /**
322
439
  * This tab is closing, or the page is being replaced. The session ends here when this is the last
323
440
  * tab using it, so it can be sent; while another tab of the site is still on it, this tab only
324
441
  * leaves it, and the last tab to close ends it. Nothing happens when it is already closed.
442
+ *
443
+ * A tab closed while inactive ends the session when the user left (its lastactivetime), not when
444
+ * the tab closed: the time it sat hidden or in the background is not session time.
325
445
  */
326
446
  function endCurrentSession() {
327
447
  var time = nowMs();
448
+ var wasInactive = inactive;
449
+ markTabActive();
328
450
  // nothing was tracked and the minimum was never reached: this visit is not reported at all
329
451
  if (dropPendingSession()) {
330
452
  return Promise.resolve();
331
453
  }
332
454
  return withSessionLock(function () {
333
- return closeOrLeaveSession(time);
455
+ return closeOrLeaveSession(time, wasInactive);
334
456
  });
335
457
  }
336
- function closeOrLeaveSession(time) {
458
+ function closeOrLeaveSession(now, wasInactive) {
337
459
  return currentSession().then(function (_currentSession) {
338
460
  if (!_currentSession || _currentSession.endtime !== 0) {
339
461
  return;
340
462
  }
341
- var others = tabsOf(_currentSession).filter(function (tab) { return tab !== tabId(); });
342
- if (others.length > 0) {
343
- var left = Object.assign({}, _currentSession, { tabs: others, lastactivetime: time });
344
- _ZAP._current_session = left;
345
- Console.log('endCurrentSession: ' + others.length + ' other tab(s) still on this session, so it stays open'); // no i18n
346
- return engagement_transactions.update(left);
347
- }
348
- var closed = Object.assign({}, _currentSession, { endtime: time, lastactivetime: time, tabs: [] });
349
- _ZAP._current_session = closed;
350
- Console.log('endCurrentSession: closing the session opened at ' + closed.starttime); // no i18n
351
- return engagement_transactions.update(closed).then(function () {
352
- return closeScreensOf(closed, time);
463
+ var lastActive = Number(_currentSession.lastactivetime) || 0;
464
+ var time = wasInactive && lastActive > 0
465
+ ? Math.max(Math.min(lastActive, now), Number(_currentSession.starttime) || 0)
466
+ : now;
467
+ var session = _currentSession;
468
+ return otherLiveTabs(session).then(function (others) {
469
+ if (others.length > 0) {
470
+ var left = Object.assign({}, session, { tabs: others, lastactivetime: time });
471
+ _ZAP._current_session = left;
472
+ Console.log('endCurrentSession: ' + others.length + ' other tab(s) still on this session, so it stays open'); // no i18n
473
+ return engagement_transactions.update(left);
474
+ }
475
+ var closed = Object.assign({}, session, { endtime: time, lastactivetime: time, tabs: [] });
476
+ _ZAP._current_session = closed;
477
+ Console.log('endCurrentSession: closing the session opened at ' + closed.starttime); // no i18n
478
+ return engagement_transactions.update(closed).then(function () {
479
+ return closeScreensOf(closed, time);
480
+ });
353
481
  });
354
482
  });
355
483
  }
@@ -445,4 +573,4 @@ function touchSession() {
445
573
  });
446
574
  }
447
575
 
448
- export { checkAndUpdateSession, closeAbandonedSessions, closeScreen, closeScreensOfGoneTabs, commitPendingSession, currentSession, dropPendingSession, endCurrentSession, holdTabLock, startNewSession, tabId, trackSession, updateLastActiveTimeOfSession, updateScreenWithEndtime };
576
+ export { checkAndUpdateSession, closeAbandonedSessions, closeScreen, closeScreensOfGoneTabs, commitPendingSession, currentSession, dropPendingSession, endCurrentSession, holdTabLock, markTabActive, markTabInactive, resetInactivity, startNewSession, tabId, trackSession, updateLastActiveTimeOfSession, updateScreenWithEndtime };
@@ -1,12 +1,12 @@
1
1
  import type { Dict, Properties } from '../types.js';
2
2
  import { type DefinedEvent } from './defined-events.js';
3
3
  /**
4
- * Records an event: `trackEvent(name, group?, properties?)`, or a defined event with
4
+ * Records an event: `trackEvent(name, group, properties?)`, or a defined event with
5
5
  * `trackEvent(DefinedEvents.AP_USER_LOGIN, properties?)`, which brings its own group.
6
6
  *
7
- * As on Android, an invalid name or group is not logged. A group left out is `default`, so the
8
- * one-argument form keeps working; a group given but invalid is a mistake worth being told about,
9
- * not one to file quietly under `default`.
7
+ * The group is required. An event without one, or with an invalid name or group, is not logged,
8
+ * and the console says why (debug or not): filing it under a group the app never named would hide
9
+ * the mistake.
10
10
  */
11
11
  export declare function trackEvent(eventName: string | DefinedEvent, groupName?: string | Properties, jsonObj?: Properties): void;
12
12
  /** The app's own screen view. Automatic screen tracking calls recordScreen() instead. */
@@ -1,5 +1,5 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
2
- import { AP_LOG_MODULE, AP_CONSTANTS, AP_CONFIG } from '../core/constants.js';
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ import { AP_LOG_MODULE, AP_CONSTANTS } from '../core/constants.js';
3
3
  import { _ZAP } from '../core/state.js';
4
4
  import { logFailure, Console, warnAlways } from '../core/logger.js';
5
5
  import { isEmpty, nowMs, getNewUUID } from '../core/utils.js';
@@ -13,6 +13,7 @@ import { hooks } from '../core/hooks.js';
13
13
  import { urlTracked, normalizeApiPath } from './api-rules.js';
14
14
  import { asDefinedEvent } from './defined-events.js';
15
15
  import { automaticScreenName } from './auto-screen.js';
16
+ import { quietly } from '../core/shield.js';
16
17
 
17
18
  /** Messages already printed, so a name refused in a loop says so once. */
18
19
  var refusedSaid = {};
@@ -29,15 +30,15 @@ function refused(module, message) {
29
30
  }
30
31
  }
31
32
  /**
32
- * Records an event: `trackEvent(name, group?, properties?)`, or a defined event with
33
+ * Records an event: `trackEvent(name, group, properties?)`, or a defined event with
33
34
  * `trackEvent(DefinedEvents.AP_USER_LOGIN, properties?)`, which brings its own group.
34
35
  *
35
- * As on Android, an invalid name or group is not logged. A group left out is `default`, so the
36
- * one-argument form keeps working; a group given but invalid is a mistake worth being told about,
37
- * not one to file quietly under `default`.
36
+ * The group is required. An event without one, or with an invalid name or group, is not logged,
37
+ * and the console says why (debug or not): filing it under a group the app never named would hide
38
+ * the mistake.
38
39
  */
39
40
  function trackEvent(eventName, groupName, jsonObj) {
40
- if (!canTrackEngagement('trackEvent')) { // no i18n
41
+ if (!canTrackEngagement('trackEvent', AP_CONSTANTS.EVENT)) { // no i18n
41
42
  return;
42
43
  }
43
44
  var defined = asDefinedEvent(eventName);
@@ -52,10 +53,13 @@ function trackEvent(eventName, groupName, jsonObj) {
52
53
  refused(AP_LOG_MODULE.EVENT, 'AppticsEvent.addEvent: Invalid eventName: ' + String(eventName)); // no i18n
53
54
  return;
54
55
  }
55
- if (groupName === undefined || groupName === null || groupName === '') { // no i18n
56
- groupName = AP_CONFIG.default_group_name;
56
+ // the group is required: an event without one (or with its properties in the group's
57
+ // place) is not logged, and the console says why
58
+ if (groupName === undefined || groupName === null || groupName === '' || typeof groupName === 'object') { // no i18n
59
+ refused(AP_LOG_MODULE.EVENT, 'AppticsEvent.addEvent: groupName is required for "' + eventName + '": addEvent(eventName, groupName, properties?)'); // no i18n
60
+ return;
57
61
  }
58
- else if (typeof groupName !== 'string' || !validateEventOrGroup(groupName)) { // no i18n
62
+ if (typeof groupName !== 'string' || !validateEventOrGroup(groupName)) { // no i18n
59
63
  refused(AP_LOG_MODULE.EVENT, 'AppticsEvent.addEvent: Invalid groupName for "' + eventName + '": ' + String(groupName)); // no i18n
60
64
  return;
61
65
  }
@@ -79,10 +83,12 @@ function trackEvent(eventName, groupName, jsonObj) {
79
83
  };
80
84
  // save the event
81
85
  // the session may still be waiting out its minimum; this event is what earns it
82
- commitPendingSession();
86
+ quietly('session', commitPendingSession()); // no i18n
83
87
  noteDebugActivity();
84
88
  engagement_transactions.add(eventData);
85
- Console.log('AppticsEvent.addEvent(\'' + eventName + '\',\'' + groupName + '\',' + JSON.stringify(_jsonObj || {}) + ')'); // no i18n
89
+ // a push notification opened earlier may count this event as its conversion
90
+ hooks.pushEventTracked(String(eventName), String(groupName));
91
+ Console.log('AppticsEvent.addEvent(\'' + eventName + '\',' + '\'' + groupName + '\'' + ',' + JSON.stringify(_jsonObj || {}) + ')'); // no i18n
86
92
  Console.dir(eventData);
87
93
  }
88
94
  /**
@@ -105,7 +111,7 @@ function outScreenAt(id, endedAt) {
105
111
  logFailure(AP_LOG_MODULE.SCREEN, 'AppticsScreen.outScreen: no screen id given'); // no i18n
106
112
  return;
107
113
  }
108
- closeScreen(id, endedAt);
114
+ quietly('screen', closeScreen(id, endedAt)); // no i18n
109
115
  }
110
116
  /**
111
117
  * Queues a screen view and makes it the current screen.
@@ -115,7 +121,7 @@ function outScreenAt(id, endedAt) {
115
121
  * An open view is not sent until it is closed, as an open session is not.
116
122
  */
117
123
  function recordScreen(screenName, jsonObj, id, startedAt, implicit) {
118
- if (!canTrackEngagement('inScreen')) { // no i18n
124
+ if (!canTrackEngagement('inScreen', AP_CONSTANTS.SCREEN)) { // no i18n
119
125
  return;
120
126
  }
121
127
  if (!validateScreenName(screenName)) {
@@ -144,9 +150,9 @@ function recordScreen(screenName, jsonObj, id, startedAt, implicit) {
144
150
  // the screen being left ends where this one starts
145
151
  var previous = _ZAP._current_screen && _ZAP._current_screen.id;
146
152
  if (previous && previous !== screenData.id) {
147
- closeScreen(previous, time);
153
+ quietly('screen', closeScreen(previous, time)); // no i18n
148
154
  }
149
- commitPendingSession();
155
+ quietly('session', commitPendingSession()); // no i18n
150
156
  noteDebugActivity();
151
157
  engagement_transactions.add(screenData);
152
158
  // `implicit`: a view recorded only so a heatmap record has one to belong to. Kept on the
@@ -211,7 +217,7 @@ function withoutQueryForLog(path) {
211
217
  return String(path || '').split(/[?#]/)[0]; // no i18n
212
218
  }
213
219
  function trackApi(jsonObj) {
214
- if (!canTrackEngagement('trackApi')) { // no i18n
220
+ if (!canTrackEngagement('trackApi', AP_CONSTANTS.API)) { // no i18n
215
221
  return;
216
222
  }
217
223
  jsonObj = jsonObj || {};
@@ -316,7 +322,7 @@ function trackApi(jsonObj) {
316
322
  edge: _ZAP._device_info.connectionType || getConnectionType()
317
323
  };
318
324
  // save the api
319
- commitPendingSession();
325
+ quietly('session', commitPendingSession()); // no i18n
320
326
  noteDebugActivity();
321
327
  engagement_transactions.add(apiData);
322
328
  Console.log('AppticsApi(\'' + method + ' ' + scheme + '://' + hostname + path + '\')'); // no i18n
@@ -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
  import { _ZAP } from '../core/state.js';
3
3
  import { Console, warnAlways } from '../core/logger.js';
4
4
  import { cloneObject } from '../core/utils.js';
@@ -12,7 +12,7 @@ import { isPermanentRefusal } from '../core/transport.js';
12
12
  * Sends pending errors to the Apptics API.
13
13
  */
14
14
  function sendErrorData(forget) {
15
- // errortracking off (getupdates): queued errors stay until tracking is back on or they expire
15
+ // js_error off (getsdkconfig): queued errors stay until tracking is back on or they expire
16
16
  if (is_apptics_disabled() || !shouldTrackOrSendData() || !_ZAP._errorTracking) {
17
17
  return Promise.resolve();
18
18
  }
@@ -1,4 +1,5 @@
1
1
  import type { Properties } from '../types.js';
2
2
  export declare function trackError(errorEvent: any, jsonObj?: Properties): void;
3
- export declare function trackGlobalErrorHandler(status?: boolean): void;
3
+ /** AppticsError.setErrorTracking: uncaught errors on or off, as the `track_error` config sets it. */
4
+ export declare function setErrorTracking(status?: boolean): void;
4
5
  export declare function extractMethodNameFromStackTrace(stackTrace: string): string;
@@ -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
  import { AP_CONSTANTS } from '../core/constants.js';
3
3
  import { _ZAP } from '../core/state.js';
4
4
  import { Console } from '../core/logger.js';
@@ -9,6 +9,7 @@ import { getConnectionType, getNetworkStatus } from '../core/env.js';
9
9
  import { canTrackErrors } from '../core/consent.js';
10
10
  import { validateJSON } from '../core/validate.js';
11
11
  import { noteDebugActivity } from '../core/debug.js';
12
+ import { quietly } from '../core/shield.js';
12
13
 
13
14
  /**
14
15
  * The stack to report. Three sources, in order of how much they tell us:
@@ -111,14 +112,16 @@ function trackError(errorEvent, jsonObj) {
111
112
  };
112
113
  // save the error
113
114
  // an error is worth a session even in the first seconds of a visit
114
- commitPendingSession();
115
+ quietly('session', commitPendingSession()); // no i18n
115
116
  noteDebugActivity();
116
117
  error_transactions.add(errorData);
117
118
  Console.log('AppticsError.trackError(\'' + issuetype + '\',\'' + message + '\',' + JSON.stringify(_jsonObj || {}) + ')'); // no i18n
118
119
  Console.dir(errorData);
119
120
  }
120
- function trackGlobalErrorHandler(status) {
121
- _ZAP._isGlobalErrorTracking = typeof status === "boolean" ? status : true; // no i18n
121
+ /** AppticsError.setErrorTracking: uncaught errors on or off, as the `track_error` config sets it. */
122
+ function setErrorTracking(status) {
123
+ _ZAP._config.track_error = typeof status === "boolean" ? status : true; // no i18n
124
+ Console.log('automatic error tracking: ' + (_ZAP._config.track_error ? 'on' : 'off')); // no i18n
122
125
  }
123
126
  function extractMethodNameFromStackTrace(stackTrace) {
124
127
  let methodName = ''; // no i18n
@@ -160,4 +163,4 @@ function extractMethodNameFromStackTrace(stackTrace) {
160
163
  return methodName;
161
164
  }
162
165
 
163
- export { extractMethodNameFromStackTrace, trackError, trackGlobalErrorHandler };
166
+ export { extractMethodNameFromStackTrace, setErrorTracking, trackError };
@@ -12,6 +12,21 @@ export declare const logChoice: {
12
12
  includeLog?: boolean;
13
13
  includeDyninfo?: boolean;
14
14
  };
15
+ /** The entry the user picker has selected, for the same form rebuilt in another language. */
16
+ export declare function pickedUser(): string;
17
+ /** What the data viewer shows, while it is open: the same form rebuilt in another language shows it again. */
18
+ export interface ViewerShown {
19
+ titleKey: string;
20
+ content: string;
21
+ }
22
+ /** The viewer's title key and content while it is open, else null. */
23
+ export declare function shownViewer(): ViewerShown | null;
24
+ /** What a form rebuilt in another language keeps of the switches and the viewer. Unset decides as a new form does. */
25
+ export interface LogKeep {
26
+ includeLog?: boolean;
27
+ includeDyninfo?: boolean;
28
+ viewer?: ViewerShown | null;
29
+ }
15
30
  /**
16
31
  * Who a sendFeedback() report, made without the form, is attributed to: nobody when `anonymous`,
17
32
  * else the user AppticsUser.setUser set (or the active registered one, status 1). Returns a function
@@ -20,18 +35,35 @@ export declare const logChoice: {
20
35
  export declare function chooseUserForSend(anonymous: boolean): () => void;
21
36
  /**
22
37
  * The "User" dropdown above the description. It lists Anonymous plus every registered user, and
23
- * starts on the active one (status 1) unless the caller asked for anonymous.
38
+ * starts on the active one (status 1) unless the caller asked for anonymous; `keep`, the entry a
39
+ * form rebuilt in another language had selected, wins over both while it is still listed.
24
40
  */
25
- export declare function wireUserPicker(modal: HTMLElement, forceAnonymous: boolean): void;
41
+ export declare function wireUserPicker(modal: HTMLElement, forceAnonymous: boolean, keep?: string): void;
42
+ /** A language's own name, its label without the English name in brackets: Deutsch, Español – México. */
43
+ export declare function ownName(label: string): string;
44
+ /**
45
+ * The language dropdown in the header. It lists every language the form has, English first, each
46
+ * by its own name; picking one is remembered for the next form and hands over to `picked`, which
47
+ * builds this one again in it. Built as the user picker is, and closed the same way (focusout, so
48
+ * it works in a shadow root), with the keys a listbox takes: arrows to move, Enter or Space to
49
+ * pick, Escape to close.
50
+ */
51
+ export declare function wireLangPicker(modal: HTMLElement, picked: () => void): void;
26
52
  /**
27
53
  * The two "Include …" switches and the viewer behind their View links. A row is shown only when
28
54
  * there is something to include, and is then on by default, so a submission carries what the app
29
- * recorded unless the user turns it off.
55
+ * recorded unless the user turns it off. `keep` is what a form rebuilt in another language had.
30
56
  */
31
- export declare function wireLogControls(modal: HTMLElement, opts: Dict): void;
57
+ export declare function wireLogControls(modal: HTMLElement, opts: Dict, keep?: LogKeep): void;
32
58
  /**
33
59
  * Drags the dialog by its header. The right/bottom placement from the stylesheet is converted to
34
60
  * an explicit left/top on the first drag, so the offsets have something to add to, and the box is
35
61
  * kept inside the viewport.
36
62
  */
37
63
  export declare function wireDrag(box: HTMLElement): void;
64
+ /**
65
+ * Lets the recording timer be dragged anywhere on the page. A press that moves it is a drag, and
66
+ * does not also stop the recording, as a plain click on it does. Call before the click listener
67
+ * is added, so a drag's click is stopped ahead of it.
68
+ */
69
+ export declare function wireTimerDrag(timer: HTMLElement): void;