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