@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
@@ -35,10 +35,27 @@ export declare function dropPendingSession(): boolean;
35
35
  /** Whether a session is waiting to be written. Used by tests and by the page-closing path. */
36
36
  export declare function hasPendingSession(): boolean;
37
37
  export declare function startNewSession(time: number): Promise<void>;
38
+ /**
39
+ * The tab went inactive. That moment becomes the session's lastactivetime, the time it ends at if
40
+ * the user does not come back within inactiveduration. If they do not, the session is ended at it
41
+ * then, and `onEnded` sends it, rather than staying open until they return or the tab closes.
42
+ * Going inactive twice (a window blur, then the tab hidden) keeps the first moment.
43
+ */
44
+ export declare function markTabInactive(onEnded: () => void): Promise<void>;
45
+ /**
46
+ * The tab is active again. The caller then settles the session (checkAndUpdateSession): back
47
+ * within inactiveduration it continues, later it has ended and a new one starts.
48
+ */
49
+ export declare function markTabActive(): void;
50
+ /** reset(): no timer left running, and the tab counts as active. */
51
+ export declare function resetInactivity(): void;
38
52
  /**
39
53
  * This tab is closing, or the page is being replaced. The session ends here when this is the last
40
54
  * tab using it, so it can be sent; while another tab of the site is still on it, this tab only
41
55
  * leaves it, and the last tab to close ends it. Nothing happens when it is already closed.
56
+ *
57
+ * A tab closed while inactive ends the session when the user left (its lastactivetime), not when
58
+ * the tab closed: the time it sat hidden or in the background is not session time.
42
59
  */
43
60
  export declare function endCurrentSession(): Promise<void>;
44
61
  /**
@@ -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');
@@ -9,6 +9,7 @@ var storage = require('../core/storage.js');
9
9
  var env = require('../core/env.js');
10
10
  var consent = require('../core/consent.js');
11
11
  var locks = require('../core/locks.js');
12
+ var shield = require('../core/shield.js');
12
13
 
13
14
  /** The most recently started item of `type` that is still open (endtime 0). */
14
15
  function latestOpen(type, items) {
@@ -64,7 +65,7 @@ function closeScreensOf(session, time) {
64
65
  * @param sessionData A set of properties belonging to the session.
65
66
  */
66
67
  function trackSession(sessionData) {
67
- if (!consent.canTrackEngagement('trackSession')) { // no i18n
68
+ if (!consent.canTrackEngagement('trackSession', constants.AP_CONSTANTS.SESSION)) { // no i18n
68
69
  return Promise.resolve();
69
70
  }
70
71
  if (sessionData && typeof sessionData !== 'object') { // no i18n
@@ -151,13 +152,12 @@ function holdTabLock() {
151
152
  holdingTabLock = false;
152
153
  });
153
154
  }
154
- /** Ends the open screen views of tabs that are gone. Resolves right away without Web Locks. */
155
- function closeScreensOfGoneTabs() {
155
+ /** The ids of tabs whose lock is held or waiting, or null without Web Locks (or if asking fails). */
156
+ function liveTabIds() {
156
157
  var locks = tabLocks();
157
158
  if (!locks) {
158
- return Promise.resolve();
159
+ return Promise.resolve(null);
159
160
  }
160
- var mine = tabId();
161
161
  return locks.query().then(function (state) {
162
162
  var alive = {};
163
163
  (state.held || []).concat(state.pending || []).forEach(function (lock) {
@@ -165,6 +165,42 @@ function closeScreensOfGoneTabs() {
165
165
  alive[lock.name.slice(TAB_LOCK_PREFIX.length)] = true;
166
166
  }
167
167
  });
168
+ return alive;
169
+ }, function () {
170
+ return null;
171
+ });
172
+ }
173
+ /**
174
+ * The other tabs still on a session. A tab that reloaded or closed before its leave was written
175
+ * stays listed, and would keep the session open for good: with Web Locks, a listed tab counts only
176
+ * while its lock is held. Without them every listed tab counts, as before.
177
+ */
178
+ function otherLiveTabs(session) {
179
+ var others = tabsOf(session).filter(function (tab) { return tab !== tabId(); });
180
+ if (!others.length) {
181
+ return Promise.resolve(others);
182
+ }
183
+ return liveTabIds().then(function (alive) {
184
+ if (!alive) {
185
+ return others;
186
+ }
187
+ var live = others.filter(function (tab) { return alive[tab] === true; });
188
+ if (live.length < others.length) {
189
+ logger.Console.log('session: ' + (others.length - live.length) + ' tab(s) listed on it are gone'); // no i18n
190
+ }
191
+ return live;
192
+ });
193
+ }
194
+ /** Ends the open screen views of tabs that are gone. Resolves right away without Web Locks. */
195
+ function closeScreensOfGoneTabs() {
196
+ if (!tabLocks()) {
197
+ return Promise.resolve();
198
+ }
199
+ var mine = tabId();
200
+ return liveTabIds().then(function (alive) {
201
+ if (!alive) {
202
+ return;
203
+ }
168
204
  var now = utils.nowMs();
169
205
  return storage.engagement_transactions.all().then(function (items) {
170
206
  var gone = items.filter(function (item) {
@@ -307,10 +343,10 @@ function startNewSession(time) {
307
343
  // held, not stored: see pendingSession above
308
344
  pendingSession = state._ZAP._current_session;
309
345
  clearPendingTimer();
310
- pendingTimer = setTimeout(function () {
346
+ pendingTimer = setTimeout(shield.shield('session', function () {
311
347
  pendingTimer = null;
312
- commitPendingSession();
313
- }, minimum);
348
+ shield.quietly('session', commitPendingSession()); // no i18n
349
+ }), minimum);
314
350
  return Promise.resolve();
315
351
  }
316
352
  /** The un-deferred path, for a minimum of 0. */
@@ -320,38 +356,130 @@ function commitNow(session) {
320
356
  }
321
357
  return trackSession(session);
322
358
  }
359
+ /** Whether this tab is inactive: hidden, minimised, or its window has lost focus. */
360
+ var inactive = false;
361
+ var inactivityTimer = null;
362
+ /**
363
+ * The tab went inactive. That moment becomes the session's lastactivetime, the time it ends at if
364
+ * the user does not come back within inactiveduration. If they do not, the session is ended at it
365
+ * then, and `onEnded` sends it, rather than staying open until they return or the tab closes.
366
+ * Going inactive twice (a window blur, then the tab hidden) keeps the first moment.
367
+ */
368
+ function markTabInactive(onEnded) {
369
+ var first = !inactive;
370
+ inactive = true;
371
+ if (inactivityTimer !== null) {
372
+ clearTimeout(inactivityTimer);
373
+ }
374
+ inactivityTimer = setTimeout(shield.shield('inactive session', function () {
375
+ inactivityTimer = null;
376
+ shield.quietly('inactive session', endInactiveSession().then(function (ended) {
377
+ if (ended) {
378
+ onEnded();
379
+ }
380
+ }));
381
+ }), state._ZAP.inactiveduration * 60 * 1000 + 1000);
382
+ return first ? updateLastActiveTimeOfSession() : Promise.resolve();
383
+ }
384
+ /**
385
+ * The tab is active again. The caller then settles the session (checkAndUpdateSession): back
386
+ * within inactiveduration it continues, later it has ended and a new one starts.
387
+ */
388
+ function markTabActive() {
389
+ inactive = false;
390
+ if (inactivityTimer !== null) {
391
+ clearTimeout(inactivityTimer);
392
+ inactivityTimer = null;
393
+ }
394
+ }
395
+ /** reset(): no timer left running, and the tab counts as active. */
396
+ function resetInactivity() {
397
+ markTabActive();
398
+ }
399
+ /**
400
+ * inactiveduration has passed with the tab inactive: the session ends at its lastactivetime, when
401
+ * the user left, so the time away is not counted. Resolves true when it ended one. While another
402
+ * tab of the site is still on the session, this tab only leaves it; one whose lastactivetime is
403
+ * recent is in use elsewhere and is left alone.
404
+ */
405
+ function endInactiveSession() {
406
+ if (!state._ZAP._token || env.is_apptics_disabled()) {
407
+ return Promise.resolve(false);
408
+ }
409
+ var ended = false;
410
+ return withSessionLock(function () {
411
+ return currentSession().then(function (_currentSession) {
412
+ if (!_currentSession || _currentSession.endtime !== 0) {
413
+ return;
414
+ }
415
+ var lastActive = Number(_currentSession.lastactivetime) || utils.nowMs();
416
+ if (utils.nowMs() - lastActive < state._ZAP.inactiveduration * 60 * 1000) {
417
+ return;
418
+ }
419
+ var session = _currentSession;
420
+ return otherLiveTabs(session).then(function (others) {
421
+ if (others.length > 0) {
422
+ var left = Object.assign({}, session, { tabs: others });
423
+ state._ZAP._current_session = left;
424
+ return storage.engagement_transactions.update(left);
425
+ }
426
+ var endAt = Math.max(lastActive, Number(session.starttime) || lastActive);
427
+ var closed = Object.assign({}, session, { endtime: endAt, tabs: [] });
428
+ state._ZAP._current_session = closed;
429
+ ended = true;
430
+ logger.Console.log('session: inactive for ' + state._ZAP.inactiveduration + ' minutes, so it ends when the user left, ' + endAt); // no i18n
431
+ return storage.engagement_transactions.update(closed).then(function () {
432
+ return closeScreensOf(closed, endAt);
433
+ });
434
+ });
435
+ });
436
+ }).then(function () {
437
+ return ended;
438
+ });
439
+ }
323
440
  /**
324
441
  * This tab is closing, or the page is being replaced. The session ends here when this is the last
325
442
  * tab using it, so it can be sent; while another tab of the site is still on it, this tab only
326
443
  * leaves it, and the last tab to close ends it. Nothing happens when it is already closed.
444
+ *
445
+ * A tab closed while inactive ends the session when the user left (its lastactivetime), not when
446
+ * the tab closed: the time it sat hidden or in the background is not session time.
327
447
  */
328
448
  function endCurrentSession() {
329
449
  var time = utils.nowMs();
450
+ var wasInactive = inactive;
451
+ markTabActive();
330
452
  // nothing was tracked and the minimum was never reached: this visit is not reported at all
331
453
  if (dropPendingSession()) {
332
454
  return Promise.resolve();
333
455
  }
334
456
  return withSessionLock(function () {
335
- return closeOrLeaveSession(time);
457
+ return closeOrLeaveSession(time, wasInactive);
336
458
  });
337
459
  }
338
- function closeOrLeaveSession(time) {
460
+ function closeOrLeaveSession(now, wasInactive) {
339
461
  return currentSession().then(function (_currentSession) {
340
462
  if (!_currentSession || _currentSession.endtime !== 0) {
341
463
  return;
342
464
  }
343
- var others = tabsOf(_currentSession).filter(function (tab) { return tab !== tabId(); });
344
- if (others.length > 0) {
345
- var left = Object.assign({}, _currentSession, { tabs: others, lastactivetime: time });
346
- state._ZAP._current_session = left;
347
- logger.Console.log('endCurrentSession: ' + others.length + ' other tab(s) still on this session, so it stays open'); // no i18n
348
- return storage.engagement_transactions.update(left);
349
- }
350
- var closed = Object.assign({}, _currentSession, { endtime: time, lastactivetime: time, tabs: [] });
351
- state._ZAP._current_session = closed;
352
- logger.Console.log('endCurrentSession: closing the session opened at ' + closed.starttime); // no i18n
353
- return storage.engagement_transactions.update(closed).then(function () {
354
- return closeScreensOf(closed, time);
465
+ var lastActive = Number(_currentSession.lastactivetime) || 0;
466
+ var time = wasInactive && lastActive > 0
467
+ ? Math.max(Math.min(lastActive, now), Number(_currentSession.starttime) || 0)
468
+ : now;
469
+ var session = _currentSession;
470
+ return otherLiveTabs(session).then(function (others) {
471
+ if (others.length > 0) {
472
+ var left = Object.assign({}, session, { tabs: others, lastactivetime: time });
473
+ state._ZAP._current_session = left;
474
+ logger.Console.log('endCurrentSession: ' + others.length + ' other tab(s) still on this session, so it stays open'); // no i18n
475
+ return storage.engagement_transactions.update(left);
476
+ }
477
+ var closed = Object.assign({}, session, { endtime: time, lastactivetime: time, tabs: [] });
478
+ state._ZAP._current_session = closed;
479
+ logger.Console.log('endCurrentSession: closing the session opened at ' + closed.starttime); // no i18n
480
+ return storage.engagement_transactions.update(closed).then(function () {
481
+ return closeScreensOf(closed, time);
482
+ });
355
483
  });
356
484
  });
357
485
  }
@@ -456,6 +584,9 @@ exports.currentSession = currentSession;
456
584
  exports.dropPendingSession = dropPendingSession;
457
585
  exports.endCurrentSession = endCurrentSession;
458
586
  exports.holdTabLock = holdTabLock;
587
+ exports.markTabActive = markTabActive;
588
+ exports.markTabInactive = markTabInactive;
589
+ exports.resetInactivity = resetInactivity;
459
590
  exports.startNewSession = startNewSession;
460
591
  exports.tabId = tabId;
461
592
  exports.trackSession = trackSession;
@@ -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,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,6 +15,7 @@ var hooks = require('../core/hooks.js');
15
15
  var apiRules = require('./api-rules.js');
16
16
  var definedEvents = require('./defined-events.js');
17
17
  var autoScreen = require('./auto-screen.js');
18
+ var shield = require('../core/shield.js');
18
19
 
19
20
  /** Messages already printed, so a name refused in a loop says so once. */
20
21
  var refusedSaid = {};
@@ -31,15 +32,15 @@ function refused(module, message) {
31
32
  }
32
33
  }
33
34
  /**
34
- * Records an event: `trackEvent(name, group?, properties?)`, or a defined event with
35
+ * Records an event: `trackEvent(name, group, properties?)`, or a defined event with
35
36
  * `trackEvent(DefinedEvents.AP_USER_LOGIN, properties?)`, which brings its own group.
36
37
  *
37
- * As on Android, an invalid name or group is not logged. A group left out is `default`, so the
38
- * one-argument form keeps working; a group given but invalid is a mistake worth being told about,
39
- * not one to file quietly under `default`.
38
+ * The group is required. An event without one, or with an invalid name or group, is not logged,
39
+ * and the console says why (debug or not): filing it under a group the app never named would hide
40
+ * the mistake.
40
41
  */
41
42
  function trackEvent(eventName, groupName, jsonObj) {
42
- if (!consent.canTrackEngagement('trackEvent')) { // no i18n
43
+ if (!consent.canTrackEngagement('trackEvent', constants.AP_CONSTANTS.EVENT)) { // no i18n
43
44
  return;
44
45
  }
45
46
  var defined = definedEvents.asDefinedEvent(eventName);
@@ -54,10 +55,13 @@ function trackEvent(eventName, groupName, jsonObj) {
54
55
  refused(constants.AP_LOG_MODULE.EVENT, 'AppticsEvent.addEvent: Invalid eventName: ' + String(eventName)); // no i18n
55
56
  return;
56
57
  }
57
- if (groupName === undefined || groupName === null || groupName === '') { // no i18n
58
- groupName = constants.AP_CONFIG.default_group_name;
58
+ // the group is required: an event without one (or with its properties in the group's
59
+ // place) is not logged, and the console says why
60
+ if (groupName === undefined || groupName === null || groupName === '' || typeof groupName === 'object') { // no i18n
61
+ refused(constants.AP_LOG_MODULE.EVENT, 'AppticsEvent.addEvent: groupName is required for "' + eventName + '": addEvent(eventName, groupName, properties?)'); // no i18n
62
+ return;
59
63
  }
60
- else if (typeof groupName !== 'string' || !validate.validateEventOrGroup(groupName)) { // no i18n
64
+ if (typeof groupName !== 'string' || !validate.validateEventOrGroup(groupName)) { // no i18n
61
65
  refused(constants.AP_LOG_MODULE.EVENT, 'AppticsEvent.addEvent: Invalid groupName for "' + eventName + '": ' + String(groupName)); // no i18n
62
66
  return;
63
67
  }
@@ -81,10 +85,12 @@ function trackEvent(eventName, groupName, jsonObj) {
81
85
  };
82
86
  // save the event
83
87
  // the session may still be waiting out its minimum; this event is what earns it
84
- session.commitPendingSession();
88
+ shield.quietly('session', session.commitPendingSession()); // no i18n
85
89
  debug.noteDebugActivity();
86
90
  storage.engagement_transactions.add(eventData);
87
- logger.Console.log('AppticsEvent.addEvent(\'' + eventName + '\',\'' + groupName + '\',' + JSON.stringify(_jsonObj || {}) + ')'); // no i18n
91
+ // a push notification opened earlier may count this event as its conversion
92
+ hooks.hooks.pushEventTracked(String(eventName), String(groupName));
93
+ logger.Console.log('AppticsEvent.addEvent(\'' + eventName + '\',' + '\'' + groupName + '\'' + ',' + JSON.stringify(_jsonObj || {}) + ')'); // no i18n
88
94
  logger.Console.dir(eventData);
89
95
  }
90
96
  /**
@@ -107,7 +113,7 @@ function outScreenAt(id, endedAt) {
107
113
  logger.logFailure(constants.AP_LOG_MODULE.SCREEN, 'AppticsScreen.outScreen: no screen id given'); // no i18n
108
114
  return;
109
115
  }
110
- session.closeScreen(id, endedAt);
116
+ shield.quietly('screen', session.closeScreen(id, endedAt)); // no i18n
111
117
  }
112
118
  /**
113
119
  * Queues a screen view and makes it the current screen.
@@ -117,7 +123,7 @@ function outScreenAt(id, endedAt) {
117
123
  * An open view is not sent until it is closed, as an open session is not.
118
124
  */
119
125
  function recordScreen(screenName, jsonObj, id, startedAt, implicit) {
120
- if (!consent.canTrackEngagement('inScreen')) { // no i18n
126
+ if (!consent.canTrackEngagement('inScreen', constants.AP_CONSTANTS.SCREEN)) { // no i18n
121
127
  return;
122
128
  }
123
129
  if (!validate.validateScreenName(screenName)) {
@@ -146,9 +152,9 @@ function recordScreen(screenName, jsonObj, id, startedAt, implicit) {
146
152
  // the screen being left ends where this one starts
147
153
  var previous = state._ZAP._current_screen && state._ZAP._current_screen.id;
148
154
  if (previous && previous !== screenData.id) {
149
- session.closeScreen(previous, time);
155
+ shield.quietly('screen', session.closeScreen(previous, time)); // no i18n
150
156
  }
151
- session.commitPendingSession();
157
+ shield.quietly('session', session.commitPendingSession()); // no i18n
152
158
  debug.noteDebugActivity();
153
159
  storage.engagement_transactions.add(screenData);
154
160
  // `implicit`: a view recorded only so a heatmap record has one to belong to. Kept on the
@@ -213,7 +219,7 @@ function withoutQueryForLog(path) {
213
219
  return String(path || '').split(/[?#]/)[0]; // no i18n
214
220
  }
215
221
  function trackApi(jsonObj) {
216
- if (!consent.canTrackEngagement('trackApi')) { // no i18n
222
+ if (!consent.canTrackEngagement('trackApi', constants.AP_CONSTANTS.API)) { // no i18n
217
223
  return;
218
224
  }
219
225
  jsonObj = jsonObj || {};
@@ -318,7 +324,7 @@ function trackApi(jsonObj) {
318
324
  edge: state._ZAP._device_info.connectionType || env.getConnectionType()
319
325
  };
320
326
  // save the api
321
- session.commitPendingSession();
327
+ shield.quietly('session', session.commitPendingSession()); // no i18n
322
328
  debug.noteDebugActivity();
323
329
  storage.engagement_transactions.add(apiData);
324
330
  logger.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
  'use strict';
3
3
 
4
4
  var state = require('../core/state.js');
@@ -14,7 +14,7 @@ var transport = require('../core/transport.js');
14
14
  * Sends pending errors to the Apptics API.
15
15
  */
16
16
  function sendErrorData(forget) {
17
- // errortracking off (getupdates): queued errors stay until tracking is back on or they expire
17
+ // js_error off (getsdkconfig): queued errors stay until tracking is back on or they expire
18
18
  if (env.is_apptics_disabled() || !consent.shouldTrackOrSendData() || !state._ZAP._errorTracking) {
19
19
  return Promise.resolve();
20
20
  }
@@ -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
  '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 validate = require('../core/validate.js');
13
13
  var debug = require('../core/debug.js');
14
+ var shield = require('../core/shield.js');
14
15
 
15
16
  /**
16
17
  * The stack to report. Three sources, in order of how much they tell us:
@@ -113,14 +114,16 @@ function trackError(errorEvent, jsonObj) {
113
114
  };
114
115
  // save the error
115
116
  // an error is worth a session even in the first seconds of a visit
116
- session.commitPendingSession();
117
+ shield.quietly('session', session.commitPendingSession()); // no i18n
117
118
  debug.noteDebugActivity();
118
119
  storage.error_transactions.add(errorData);
119
120
  logger.Console.log('AppticsError.trackError(\'' + issuetype + '\',\'' + message + '\',' + JSON.stringify(_jsonObj || {}) + ')'); // no i18n
120
121
  logger.Console.dir(errorData);
121
122
  }
122
- function trackGlobalErrorHandler(status) {
123
- state._ZAP._isGlobalErrorTracking = typeof status === "boolean" ? status : true; // no i18n
123
+ /** AppticsError.setErrorTracking: uncaught errors on or off, as the `track_error` config sets it. */
124
+ function setErrorTracking(status) {
125
+ state._ZAP._config.track_error = typeof status === "boolean" ? status : true; // no i18n
126
+ logger.Console.log('automatic error tracking: ' + (state._ZAP._config.track_error ? 'on' : 'off')); // no i18n
124
127
  }
125
128
  function extractMethodNameFromStackTrace(stackTrace) {
126
129
  let methodName = ''; // no i18n
@@ -163,5 +166,5 @@ function extractMethodNameFromStackTrace(stackTrace) {
163
166
  }
164
167
 
165
168
  exports.extractMethodNameFromStackTrace = extractMethodNameFromStackTrace;
169
+ exports.setErrorTracking = setErrorTracking;
166
170
  exports.trackError = trackError;
167
- exports.trackGlobalErrorHandler = trackGlobalErrorHandler;
@@ -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;