@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,16 @@ var transport = require('../core/transport.js');
11
11
  var validate = require('../core/validate.js');
12
12
  var hooks = require('../core/hooks.js');
13
13
 
14
+ /**
15
+ * Whether the active user's customer group is not tracked, as user/register last answered for them
16
+ * (user_info's customergrouptracking). A user registered before it was kept has none, and counts as
17
+ * tracked. Only a user getsdkconfig is asked about can be one: the status decides whether it
18
+ * carries their userid.
19
+ */
20
+ function activeUserGroupUntracked() {
21
+ var user = state._ZAP._user_info;
22
+ return !!user && !utils.isEmpty(user.userid) && user.customergrouptracking === false;
23
+ }
14
24
  function getUser() {
15
25
  return state._ZAP._user_info || {}; // no i18n
16
26
  }
@@ -95,7 +105,7 @@ function registerUserWithApptics(user_info) {
95
105
  if (utils.isEmptyObj(user_info)) {
96
106
  return Promise.reject(label + ': nothing to register'); // no i18n
97
107
  }
98
- var missing = transport.rejectIfNoDeviceIds(label);
108
+ var missing = transport.rejectIfNoDeviceIds(label, 'reguser');
99
109
  if (missing) {
100
110
  return missing;
101
111
  }
@@ -104,11 +114,21 @@ function registerUserWithApptics(user_info) {
104
114
  var data = result.data || {};
105
115
  user_info.userid = data.userid;
106
116
  user_info.groupid = data.customergroupid;
107
- consent.setTrackingStatus(constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII);
117
+ // whether a change of tracking status asks getsdkconfig again depends on it (see setTrackingStatus)
118
+ user_info.customergrouptracking = data.customergrouptracking !== false;
119
+ // the tracking status is left as it is: registering a user is not consent to attach them to
120
+ // the data. Only AppticsSettings.setTrackingStatus changes it
108
121
  addOrUpdateUser(user_info);
109
122
  getUserInfo();
110
123
  // the user and their customer group are known now: remote config conditions on them re-apply
111
124
  hooks.hooks.remoteConfigUserChanged();
125
+ // a user whose customer group is not tracked (customergrouptracking: false) gets every
126
+ // module off from getsdkconfig, so it is asked again for them now; for any other user the
127
+ // current answer stands. Only with PII does getsdkconfig carry the userid: anonymous, or
128
+ // without PII, it answers for the device alone, and the customer group does not apply
129
+ if (data.customergrouptracking === false && consent.opt_in_status() === constants.AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII) {
130
+ hooks.hooks.askServerSettings();
131
+ }
112
132
  return data;
113
133
  });
114
134
  }
@@ -174,8 +194,10 @@ class UserBuilder {
174
194
  return validate.userValidateJSON(user);
175
195
  }
176
196
  }
197
+ hooks.hooks.activeUserGroupUntracked = activeUserGroupUntracked;
177
198
 
178
199
  exports.UserBuilder = UserBuilder;
200
+ exports.activeUserGroupUntracked = activeUserGroupUntracked;
179
201
  exports.addOrUpdateUser = addOrUpdateUser;
180
202
  exports.getUser = getUser;
181
203
  exports.getUserInfo = getUserInfo;
@@ -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 { RETRY_CAPABLE_PATHS } from './constants.js';
3
3
  import { user_defaults } from './storage.js';
4
4
  import { nowMs } from './utils.js';
@@ -1,19 +1,19 @@
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, isExpired } from './state.js';
3
3
  import { Console, warnAlways } from './logger.js';
4
4
  import { isEmptyObj, sizeof } from './utils.js';
5
- import './constants.js';
6
5
  import './db.js';
7
6
  import { shouldTrackOrSendData } from './consent.js';
8
7
  import { attemptsExhausted, MAX_ATTEMPTS, resetAttempts } from './attempts.js';
9
8
  import { rejectIfDisabled, rejectIfNoDeviceIds, getMetaObj, postKeepalive, apiHeaders, postToApptics } from './transport.js';
9
+ import { shield } from './shield.js';
10
10
 
11
11
  /** Retries `send` in 500 ms, replacing any retry already scheduled. */
12
12
  function defer(send) {
13
13
  if (_ZAP._deferSendTimer) {
14
14
  clearTimeout(_ZAP._deferSendTimer);
15
15
  }
16
- _ZAP._deferSendTimer = setTimeout(send, 500);
16
+ _ZAP._deferSendTimer = setTimeout(shield('deferred send', send), 500); // no i18n
17
17
  }
18
18
  function clearDefer() {
19
19
  if (_ZAP._deferSendTimer) {
@@ -71,7 +71,7 @@ function sendBatch(path, label, _payload, forget) {
71
71
  if (isEmptyObj(_payload)) {
72
72
  return Promise.reject(label + ': nothing to send'); // no i18n
73
73
  }
74
- var missing = rejectIfNoDeviceIds(label);
74
+ var missing = rejectIfNoDeviceIds(label, path);
75
75
  if (missing) {
76
76
  return missing;
77
77
  }
@@ -1,3 +1,4 @@
1
+ import { type EngagementType } from './constants.js';
1
2
  import type { TrackingStatus } from '../types.js';
2
3
  /**
3
4
  * DNT counts only when not ignored; while it counts, tracking is NO_TRACKING (opt_in_status).
@@ -12,8 +13,11 @@ export declare function shouldTrackOrSendData(): boolean;
12
13
  * and consent / server flags allow tracking.
13
14
  */
14
15
  export declare function canTrack(caller: string): boolean;
15
- /** canTrack plus the server's `engagementtracking` flag from getupdates (events, screens, sessions, api calls). */
16
- export declare function canTrackEngagement(caller: string): boolean;
16
+ /**
17
+ * canTrack plus the server's flag for this kind of item: getsdkconfig's event (5), api (6),
18
+ * screen (10) and session (11) modules, each switched on its own.
19
+ */
20
+ export declare function canTrackEngagement(caller: string, type: EngagementType): boolean;
17
21
  /**
18
22
  * canTrack plus the server's heatmap flag (getsdkconfig module 18).
19
23
  *
@@ -21,7 +25,16 @@ export declare function canTrackEngagement(caller: string): boolean;
21
25
  * well want events while declining to have every click's coordinates recorded.
22
26
  */
23
27
  export declare function canTrackHeatmap(caller: string): boolean;
24
- /** canTrack plus the server's `errortracking` flag from getupdates. */
28
+ /** canTrack plus the server's js_error module (15) from getsdkconfig. */
25
29
  export declare function canTrackErrors(caller: string): boolean;
26
- export declare function setTrackingStatus(trackingState: TrackingStatus): void;
30
+ /** Stores the visitor's tracking status without telling the server. True when it changed. */
31
+ export declare function recordTrackingStatus(trackingState: TrackingStatus): boolean;
32
+ export declare function setTrackingStatus(value: TrackingStatus | number): void;
27
33
  export declare function getTrackingStatus(): TrackingStatus;
34
+ /**
35
+ * Whether the visitor chose anonymous tracking: the stored choice, not opt_in_status(), which
36
+ * answers NO_TRACKING while Do Not Track counts, and then nothing is sent to be named anyway.
37
+ */
38
+ export declare function isAnonymous(): boolean;
39
+ /** The server's device preference for a tracking status: devicestatus on device/add. */
40
+ export declare function deviceStatusFor(status: TrackingStatus): number;
@@ -1,10 +1,10 @@
1
- /*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.1 | (c) Zoho Corporation Private Limited | see LICENSE */
2
- import { AP_TRACKING_STATUS } from './constants.js';
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ import { AP_TRACKING_STATUS, AP_DEVICE_STATUS } from './constants.js';
3
3
  import { _ZAP } from './state.js';
4
- import { Console } from './logger.js';
5
- import { isEmpty, isSuccess } from './utils.js';
6
- import { tracking_preference } from './storage.js';
7
- import { is_apptics_disabled, isDntOn } from './env.js';
4
+ import { Console, warnAlways } from './logger.js';
5
+ import { isSuccess, isEmpty } from './utils.js';
6
+ import { tracking_preference, trackingStatusFrom } from './storage.js';
7
+ import { isDntOn, is_apptics_disabled } from './env.js';
8
8
  import { hooks } from './hooks.js';
9
9
 
10
10
  /**
@@ -28,14 +28,14 @@ function opt_in_status() {
28
28
  return AP_TRACKING_STATUS.NO_TRACKING;
29
29
  }
30
30
  var status = tracking_preference.opt_in_status();
31
- if (status == -1) {
31
+ if (status === AP_TRACKING_STATUS.NO_TRACKING) {
32
32
  Console.warn('opt_in_status: You are opted out of Apptics tracking. This will prevent the our SDK from sending no data to our server.'); // no i18n
33
33
  }
34
34
  return status;
35
35
  }
36
36
  function shouldTrackOrSendData() {
37
37
  var optInStatus = opt_in_status();
38
- return optInStatus > -1 && _ZAP._shouldTrack;
38
+ return optInStatus !== AP_TRACKING_STATUS.NO_TRACKING && _ZAP._shouldTrack;
39
39
  }
40
40
  /**
41
41
  * The guard every tracking call starts with: init() has run, the client isn't a crawler,
@@ -51,13 +51,16 @@ function canTrack(caller) {
51
51
  }
52
52
  return shouldTrackOrSendData();
53
53
  }
54
- /** canTrack plus the server's `engagementtracking` flag from getupdates (events, screens, sessions, api calls). */
55
- function canTrackEngagement(caller) {
54
+ /**
55
+ * canTrack plus the server's flag for this kind of item: getsdkconfig's event (5), api (6),
56
+ * screen (10) and session (11) modules, each switched on its own.
57
+ */
58
+ function canTrackEngagement(caller, type) {
56
59
  if (!canTrack(caller)) {
57
60
  return false;
58
61
  }
59
- if (!_ZAP._engagementTracking) {
60
- Console.log('apptics.' + caller + ': engagement tracking is turned off by the server'); // no i18n
62
+ if (!_ZAP._engagementTracking[type]) {
63
+ Console.log('apptics.' + caller + ': ' + type + ' tracking is turned off by the server'); // no i18n
61
64
  return false;
62
65
  }
63
66
  return true;
@@ -78,7 +81,7 @@ function canTrackHeatmap(caller) {
78
81
  }
79
82
  return true;
80
83
  }
81
- /** canTrack plus the server's `errortracking` flag from getupdates. */
84
+ /** canTrack plus the server's js_error module (15) from getsdkconfig. */
82
85
  function canTrackErrors(caller) {
83
86
  if (!canTrack(caller)) {
84
87
  return false;
@@ -89,17 +92,45 @@ function canTrackErrors(caller) {
89
92
  }
90
93
  return true;
91
94
  }
92
- function setTrackingStatus(trackingState) {
93
- if (isEmpty(trackingState)) {
95
+ /** Stores the visitor's tracking status without telling the server. True when it changed. */
96
+ function recordTrackingStatus(trackingState) {
97
+ if (tracking_preference.opt_in_status() == trackingState) {
98
+ return false;
99
+ }
100
+ tracking_preference.update_status(trackingState);
101
+ _ZAP._devicestatus = tracking_preference.opt_in_status();
102
+ return true;
103
+ }
104
+ /**
105
+ * The status setTrackingStatus was given: one of AP_TRACKING_STATUS, or the number an app passed
106
+ * before the status had names, which still works and says so.
107
+ */
108
+ function requestedStatus(value) {
109
+ if (isEmpty(value)) {
94
110
  Console.warn('setTrackingStatus: trackingStatus is Empty'); // no i18n
111
+ return undefined;
112
+ }
113
+ var status = trackingStatusFrom(value);
114
+ if (status === undefined) {
115
+ warnAlways('AppticsSettings.setTrackingStatus: ' + String(value) + ' is not a tracking status; pass one of AppticsSettings.AP_TRACKING_STATUS'); // no i18n
116
+ }
117
+ else if (typeof value === 'number') { // no i18n
118
+ warnAlways('AppticsSettings.setTrackingStatus: the number ' + value + ' is deprecated; pass AppticsSettings.AP_TRACKING_STATUS.' + status); // no i18n
119
+ }
120
+ return status;
121
+ }
122
+ function setTrackingStatus(value) {
123
+ var trackingState = requestedStatus(value);
124
+ if (trackingState === undefined) {
95
125
  return;
96
126
  }
97
- if (tracking_preference.opt_in_status() == trackingState) {
127
+ var previous = tracking_preference.opt_in_status();
128
+ if (!recordTrackingStatus(trackingState)) {
98
129
  return;
99
130
  }
100
- tracking_preference.update_status(trackingState);
101
- _ZAP._devicestatus = tracking_preference.opt_in_status();
102
- _ZAP._isanonrequired = tracking_preference.opt_in_status() == AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII ? false : _ZAP._isanonrequired;
131
+ askServerSettingsForUser(previous, tracking_preference.opt_in_status());
132
+ // push registers by the id the new status goes by, or stops with no tracking
133
+ hooks.pushTrackingChanged();
103
134
  if (tracking_preference.opt_in_status() != AP_TRACKING_STATUS.NO_TRACKING) {
104
135
  Console.log('setTrackingStatus: Updating device info with new tracking status'); // no i18n
105
136
  hooks.updateDevice(_ZAP._device_info).then(function (result) {
@@ -115,8 +146,41 @@ function setTrackingStatus(trackingState) {
115
146
  });
116
147
  }
117
148
  }
149
+ /**
150
+ * getsdkconfig carries the user's ids only with PII. For a user whose customer group is not
151
+ * tracked, it answers every module off with them and for the device alone without them, so a
152
+ * change into or out of PII is asked about now rather than at the next check. Any other user,
153
+ * or a change to no tracking, asks nothing.
154
+ */
155
+ function askServerSettingsForUser(previous, current) {
156
+ if (current === AP_TRACKING_STATUS.NO_TRACKING || !hooks.activeUserGroupUntracked()) {
157
+ return;
158
+ }
159
+ var withPii = AP_TRACKING_STATUS.USAGE_TRACKING_WITH_PII;
160
+ if (current === withPii || previous === withPii) {
161
+ Console.log('setTrackingStatus: the user\'s customer group is not tracked, asking getsdkconfig'); // no i18n
162
+ hooks.askServerSettings();
163
+ }
164
+ }
118
165
  function getTrackingStatus() {
119
166
  return opt_in_status();
120
167
  }
168
+ /**
169
+ * Whether the visitor chose anonymous tracking: the stored choice, not opt_in_status(), which
170
+ * answers NO_TRACKING while Do Not Track counts, and then nothing is sent to be named anyway.
171
+ */
172
+ function isAnonymous() {
173
+ return tracking_preference.opt_in_status() === AP_TRACKING_STATUS.ANONYMOUS;
174
+ }
175
+ /** The server's device preference for a tracking status: devicestatus on device/add. */
176
+ function deviceStatusFor(status) {
177
+ if (status === AP_TRACKING_STATUS.ANONYMOUS) {
178
+ return AP_DEVICE_STATUS.ALL_ANONYMOUS;
179
+ }
180
+ if (status === AP_TRACKING_STATUS.NO_TRACKING) {
181
+ return AP_DEVICE_STATUS.TRACKING_OFF;
182
+ }
183
+ return AP_DEVICE_STATUS.ALL_WITH_PII;
184
+ }
121
185
 
122
- export { canTrack, canTrackEngagement, canTrackErrors, canTrackHeatmap, getTrackingStatus, hasDoNotTrackEnabled, opt_in_status, setTrackingStatus, shouldTrackOrSendData };
186
+ export { canTrack, canTrackEngagement, canTrackErrors, canTrackHeatmap, deviceStatusFor, getTrackingStatus, hasDoNotTrackEnabled, isAnonymous, opt_in_status, recordTrackingStatus, setTrackingStatus, shouldTrackOrSendData };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Whether a call was typed into the browser's developer console rather than made by the page's
3
+ * own code. Debug mode is switched this way only (see debug.ts), so an app cannot ship with it on.
4
+ *
5
+ * The browser does not say who called, so this reads the call's stack. Its outermost frame is
6
+ * where the call started: for code that is a script file, an inline handler or an eval made by
7
+ * one, and each of those names a URL. A console call starts in the console's own input, which has
8
+ * none:
9
+ *
10
+ * Chrome, Edge `at <anonymous>:1:9`
11
+ * Firefox `@debugger eval code:1:1`
12
+ * Safari `global code`, then frames from `[native code]`
13
+ *
14
+ * It is a best guess, not a lock: a script can make a stack with no URL in it too (a Function()
15
+ * body some engines leave unnamed), so this keeps a switch out of shipped code, nothing more.
16
+ */
17
+ /** Whether a stack, as Error().stack gives it, started in the console. */
18
+ export declare function isConsoleStack(stack: string): boolean;
19
+ /**
20
+ * Whether the public call running now was typed into the console. A browser that gives no stack
21
+ * cannot be asked, and is let through rather than having the call stop working there.
22
+ */
23
+ export declare function calledFromConsole(): boolean;
@@ -0,0 +1,60 @@
1
+ /*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
2
+ /**
3
+ * Whether a call was typed into the browser's developer console rather than made by the page's
4
+ * own code. Debug mode is switched this way only (see debug.ts), so an app cannot ship with it on.
5
+ *
6
+ * The browser does not say who called, so this reads the call's stack. Its outermost frame is
7
+ * where the call started: for code that is a script file, an inline handler or an eval made by
8
+ * one, and each of those names a URL. A console call starts in the console's own input, which has
9
+ * none:
10
+ *
11
+ * Chrome, Edge `at <anonymous>:1:9`
12
+ * Firefox `@debugger eval code:1:1`
13
+ * Safari `global code`, then frames from `[native code]`
14
+ *
15
+ * It is a best guess, not a lock: a script can make a stack with no URL in it too (a Function()
16
+ * body some engines leave unnamed), so this keeps a switch out of shipped code, nothing more.
17
+ */
18
+ /** A location with a scheme: https://, file://, blob:, webpack-internal:// and the like. */
19
+ const URL_RE = /[a-z][a-z0-9+.-]*:\/\//i;
20
+ /** Frames that are the engine's own, which say nothing about who called. */
21
+ function engineFrame(line) {
22
+ return line === '@' || line.indexOf('[native code]') !== -1; // no i18n
23
+ }
24
+ /** Whether a stack, as Error().stack gives it, started in the console. */
25
+ function isConsoleStack(stack) {
26
+ var frames = stack.split('\n').map(function (line) {
27
+ return line.trim();
28
+ }).filter(function (line) {
29
+ return line !== '' && !engineFrame(line);
30
+ });
31
+ // V8 heads its stack with the error's own name and message, which is no frame
32
+ if (frames.length && !/^at\s/.test(frames[0]) && frames[0].indexOf('@') === -1 && /^\w*Error\b/.test(frames[0])) {
33
+ frames.shift();
34
+ }
35
+ if (!frames.length) {
36
+ return false;
37
+ }
38
+ return !URL_RE.test(frames[frames.length - 1]);
39
+ }
40
+ /**
41
+ * Whether the public call running now was typed into the console. A browser that gives no stack
42
+ * cannot be asked, and is let through rather than having the call stop working there.
43
+ */
44
+ function calledFromConsole() {
45
+ // V8 keeps 10 frames unless told otherwise, which a deep enough call cuts off before the frame
46
+ // where it started; the whole stack is read, and the page's own limit put back
47
+ var E = Error;
48
+ var limit = E.stackTraceLimit;
49
+ var stack;
50
+ try {
51
+ E.stackTraceLimit = Infinity;
52
+ stack = new Error().stack;
53
+ }
54
+ finally {
55
+ E.stackTraceLimit = limit;
56
+ }
57
+ return typeof stack !== 'string' || stack === '' || isConsoleStack(stack); // no i18n
58
+ }
59
+
60
+ export { calledFromConsole, isConsoleStack };
@@ -14,11 +14,40 @@ export type ScreenRouteRule = {
14
14
  regex: RegExp;
15
15
  name: string;
16
16
  };
17
+ /**
18
+ * The visitor's tracking status: what setTrackingStatus takes and getTrackingStatus returns. Each
19
+ * value is its own name, so an app never deals in the numbers it is stored as (TRACKING_STATUS_CODE).
20
+ */
17
21
  export declare const AP_TRACKING_STATUS: Readonly<{
22
+ readonly USAGE_TRACKING_WITH_PII: "USAGE_TRACKING_WITH_PII";
23
+ readonly USAGE_TRACKING_WITHOUT_PII: "USAGE_TRACKING_WITHOUT_PII";
24
+ readonly ANONYMOUS: "ANONYMOUS";
25
+ readonly NO_TRACKING: "NO_TRACKING";
26
+ }>;
27
+ /**
28
+ * The number each tracking status is stored as, in trackinfo's tracking_status, and the number an
29
+ * app passed to setTrackingStatus before the status had names. These are the SDK's own values, not
30
+ * the server's device preference: deviceStatusFor() turns one into the devicestatus device/add
31
+ * sends. ANONYMOUS is 7, past the server's 1–6, because 4 is already stored by browsers that chose
32
+ * without PII and must keep meaning that.
33
+ */
34
+ export declare const TRACKING_STATUS_CODE: Readonly<{
18
35
  readonly USAGE_TRACKING_WITH_PII: 1;
19
36
  readonly USAGE_TRACKING_WITHOUT_PII: 4;
37
+ readonly ANONYMOUS: 7;
20
38
  readonly NO_TRACKING: -1;
21
39
  }>;
40
+ /**
41
+ * The server's device preferences, devicestatus on device/add. With and without PII are both
42
+ * "all tracking with PII" (1): without PII only means no user is attached to the data. ANONYMOUS
43
+ * is "all tracking, anonymous" (4). The usage-only and crash-only preferences (2, 3, 5, 6) have no
44
+ * SDK status yet.
45
+ */
46
+ export declare const AP_DEVICE_STATUS: Readonly<{
47
+ readonly ALL_WITH_PII: 1;
48
+ readonly ALL_ANONYMOUS: 4;
49
+ readonly TRACKING_OFF: -1;
50
+ }>;
22
51
  export declare const AP_FEEDBACK_TYPE: Readonly<{
23
52
  readonly BUG: 0;
24
53
  readonly FEEDBACK: 1;
@@ -34,6 +63,8 @@ export declare const AP_CONSTANTS: Readonly<{
34
63
  readonly SUCCESS: "success";
35
64
  readonly BROWSER: "Browser";
36
65
  }>;
66
+ /** The kinds of engagement item, each with its own getsdkconfig module: AP_CONSTANTS' type values. */
67
+ export type EngagementType = 'event' | 'screen' | 'session' | 'api';
37
68
  export declare const DEFAULT_API_PATHS: Readonly<{
38
69
  readonly addversion: "app/addversion";
39
70
  readonly regdevice: "device/add";
@@ -45,6 +76,8 @@ export declare const DEFAULT_API_PATHS: Readonly<{
45
76
  readonly getupdates: "getupdates";
46
77
  readonly consolelog: "log/add";
47
78
  readonly heatmap: "heatmap/add";
79
+ readonly pushnotification: "pushnotification/device";
80
+ readonly pnstats: "channel/add";
48
81
  }>;
49
82
  /**
50
83
  * Which API version each path lives under.
@@ -79,9 +112,18 @@ export declare const SDK_MODULE: Readonly<{
79
112
  * authority. Where they disagree, getsdkconfig wins.
80
113
  */
81
114
  readonly REMOTE_CONFIG: "2";
115
+ readonly EVENT: "5";
116
+ readonly API: "6";
117
+ readonly SCREEN: "10";
82
118
  readonly SESSION: "11";
83
119
  readonly FEEDBACK: "12";
84
- readonly CRASH: "13";
120
+ /**
121
+ * Push notification over WMS. getsdkconfig answers with the `wms` block only when it is asked
122
+ * for this id in `moduleids` and push is on for the app.
123
+ */
124
+ readonly PUSH_NOTIFICATION: "16";
125
+ /** Uncaught and reported JavaScript errors: js_error. 13 (crash) and 14 (nonfatal) are the native SDKs'. */
126
+ readonly JS_ERROR: "15";
85
127
  readonly REMOTE_LOGGER: "17";
86
128
  readonly HEATMAP: "18";
87
129
  }>;
@@ -97,9 +139,10 @@ export declare const LOG_FILENAME_MAX = 100;
97
139
  */
98
140
  export declare const DEVICE_NAME_MAX = 100;
99
141
  /**
100
- * The `level` every line goes out with. Everything the remote logger carries is a failure inside
101
- * the SDK — logFailure is its only caller — so the level never varies. 3 is what the v2 reference
102
- * shows in its only example; the scale itself is not documented anywhere we can see.
142
+ * The `level` a remote log line goes out with when it has none of its own: 3, Info. Every line an
143
+ * app writes with AppticsLogger carries its level (1 verbose to 5 error, see LOG_LEVEL in
144
+ * remotelog/logger.ts). Only a line an older SDK stored, when the SDK logged its own failures
145
+ * there, has none; it is sent as Info rather than having the batch refused for a missing level.
103
146
  */
104
147
  export declare const REMOTE_LOG_LEVEL = 3;
105
148
  /**
@@ -109,29 +152,24 @@ export declare const REMOTE_LOG_LEVEL = 3;
109
152
  * enough that a tab left open overnight is not still sending every call to its debug twin.
110
153
  */
111
154
  export declare const DEBUG_IDLE_MS: number;
112
- /** Idle minutes that end a session. Lives on state, not in _config, but defaults here. */
155
+ /** Minutes a tab can be inactive before its session ends. Lives on state, not in _config, but defaults here. */
113
156
  export declare const DEFAULT_INACTIVE_MINUTES = 30;
157
+ /**
158
+ * The range both session timings may be set in: min_session_duration (how long a visit must last
159
+ * before its session is recorded) and max_session_duration (how long a tab may be inactive before its
160
+ * session ends). 5 seconds to 30 minutes; a value outside it is ignored and the default kept.
161
+ */
162
+ export declare const SESSION_TIMING_MIN_MS: number;
163
+ export declare const SESSION_TIMING_MAX_MS: number;
114
164
  /** Global defaults. `state._config` holds a mutable copy per init. */
115
165
  export declare const AP_CONFIG: Readonly<{
116
166
  endpoint: "/sdk/web/";
117
167
  method: "POST";
118
- transport: "XHR";
119
- track_link_timeout: 300;
120
- cookie_expiration_days: 365;
121
- storage_type: "localStorage";
122
- enable_batch_requests: true;
123
168
  batch_size: 50;
124
169
  batch_flush_interval: 30000;
125
170
  getupdates_interval: 120000;
126
171
  batch_request_timeout: 7;
127
- auto_starts_batch: true;
128
- mode: 1;
129
- default_group_name: "default";
130
- default_optin_status: number;
131
- enable_pageview_tracking: false;
132
- save_referrer: true;
133
172
  debug: boolean;
134
- track_by_default: true;
135
173
  ignore_do_not_track: boolean;
136
174
  /**
137
175
  * Wrap XHR and fetch to record the app's API calls without it calling startTrackApi(). Off by
@@ -144,6 +182,16 @@ export declare const AP_CONFIG: Readonly<{
144
182
  * default; the app's own inScreen() during a navigation replaces that navigation's view.
145
183
  */
146
184
  track_screen: boolean;
185
+ /**
186
+ * Record uncaught errors and unhandled promise rejections, from the window's `error` and
187
+ * `unhandledrejection` events. On by default; AppticsError.setErrorTracking() switches it later.
188
+ */
189
+ track_error: boolean;
190
+ /**
191
+ * Record clicks on elements tagged `apeventaction` (or `data-apeventaction`) as events. On by
192
+ * default; AppticsEvent.setClickTracking() switches it later.
193
+ */
194
+ track_click: boolean;
147
195
  /**
148
196
  * How automatic screen tracking names a path, as init() keeps the config's screen_routes: route
149
197
  * patterns (`/users/{id}/orders`, each id recorded as a star), exact paths and regular
@@ -182,6 +230,7 @@ export declare const AP_CONFIG: Readonly<{
182
230
  * debug stream is no use to whoever is reading it.
183
231
  */
184
232
  device_name: string;
233
+ /** Path of the site's service worker for push notifications (it imports apptics-pn-sw.js); '' for none. */
185
234
  /**
186
235
  * Most heatmap records one visit may produce. Clicks are cheap, but a page that scrolls a lot
187
236
  * can produce them faster than they are sent, and an unbounded queue is a memory leak on a tab