@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/lifecycle.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
2
|
-
import { REQUIRED_CONFIG, CONFIG_KEYS, AP_CONFIG, RETIRED_CONFIG_NAMES, DEFAULT_INACTIVE_MINUTES } from './core/constants.js';
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { REQUIRED_CONFIG, CONFIG_KEYS, AP_CONFIG, RETIRED_CONFIG_NAMES, DEFAULT_INACTIVE_MINUTES, SESSION_TIMING_MIN_MS, SESSION_TIMING_MAX_MS } from './core/constants.js';
|
|
3
3
|
import { _ZAP } from './core/state.js';
|
|
4
4
|
import { Console, warnAlways } from './core/logger.js';
|
|
5
5
|
import { isEmpty, isSuccess } from './core/utils.js';
|
|
6
|
-
import { storageReady, user_defaults, engagement_transactions, error_transactions, tracking_preference } from './core/storage.js';
|
|
6
|
+
import { storageReady, user_defaults, engagement_transactions, error_transactions, heatmap_transactions, remotelog_transactions, feedbacklog_transactions, tracking_preference } from './core/storage.js';
|
|
7
7
|
import { hooks } from './core/hooks.js';
|
|
8
8
|
import { applyDebugConfig } from './core/debug.js';
|
|
9
9
|
import { getConnectionType, getOrientation } from './core/env.js';
|
|
10
|
-
import { restoreServerSettings, prepareDevice,
|
|
11
|
-
import { clearAppVersion, registerAppVersion, appVersionFailedForNetwork } from './device/appversion.js';
|
|
12
|
-
import { holdTabLock, checkAndUpdateSession,
|
|
10
|
+
import { restoreServerSettings, prepareDevice, startServerSettingChecks, updateDeviceWithApptics, needsDevice, deviceReady } from './device/index.js';
|
|
11
|
+
import { clearAppVersion, keyFingerprint, registerAppVersion, appVersionFailedForNetwork } from './device/appversion.js';
|
|
12
|
+
import { holdTabLock, checkAndUpdateSession, markTabInactive, markTabActive, updateScreenWithEndtime, endCurrentSession, resetInactivity } from './engagement/session.js';
|
|
13
13
|
import { enableApiTracking } from './engagement/auto-api.js';
|
|
14
|
-
import {
|
|
14
|
+
import { enableScreenTracking, routePath } from './engagement/auto-screen.js';
|
|
15
15
|
import { resumeScreen, trackEvent } from './engagement/track.js';
|
|
16
16
|
import { trackError } from './errors/track.js';
|
|
17
17
|
import { startTimers, flush, stopTimers } from './scheduler.js';
|
|
@@ -19,6 +19,7 @@ import { sendStoredLogs, forgetStoredLogs } from './remotelog/send.js';
|
|
|
19
19
|
import { getUserInfo } from './user/index.js';
|
|
20
20
|
import { clearAttempts } from './core/attempts.js';
|
|
21
21
|
import { FRAMEWORK_ID } from './core/framework-id.js';
|
|
22
|
+
import { quietly, shield, isSdkRejection, isSdkElement, isSdkScript } from './core/shield.js';
|
|
22
23
|
|
|
23
24
|
let listenersAttached = false;
|
|
24
25
|
/** The config init() was last called with; reset() starts again from it. */
|
|
@@ -114,10 +115,15 @@ var previousAppVersion = ''; // no i18n
|
|
|
114
115
|
/**
|
|
115
116
|
* Data stored for another app on this origin is discarded before anything else reads it,
|
|
116
117
|
* including the stored app/addversion answer that would otherwise hand out that app's ids.
|
|
118
|
+
*
|
|
119
|
+
* Another app is a different base_url, app_domain or auth_key from the ones the stored data was
|
|
120
|
+
* registered with. Everything goes, the queues included, and start-up runs as on a first visit:
|
|
121
|
+
* app/addversion, device/add and the rest. Resolves once the store is empty.
|
|
117
122
|
*/
|
|
118
123
|
function discardOtherAppData(settings) {
|
|
119
|
-
// which app it is, and which version, are in app_version_info (serviceUrl, identifier
|
|
120
|
-
// appversion): no keys of their own. 2.0.0-beta's appkey and
|
|
124
|
+
// which app it is, and which version, are in app_version_info (serviceUrl, identifier, a
|
|
125
|
+
// fingerprint of zak, and appversion): no keys of their own. 2.0.0-beta's appkey and
|
|
126
|
+
// appversion are read this once
|
|
121
127
|
var info = user_defaults.item('app_version_info') || {}; // no i18n
|
|
122
128
|
var stored = !isEmpty(info.serviceUrl) && !isEmpty(info.identifier)
|
|
123
129
|
? appKey(info)
|
|
@@ -125,11 +131,17 @@ function discardOtherAppData(settings) {
|
|
|
125
131
|
previousAppVersion = String((!isEmpty(info.appversion) ? info.appversion : user_defaults.item('appversion')) || ''); // no i18n
|
|
126
132
|
user_defaults.add('appkey', undefined); // no i18n
|
|
127
133
|
user_defaults.add('appversion', undefined); // no i18n
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
var otherApp = !isEmpty(stored) && stored !== appKey(settings);
|
|
135
|
+
// a build that kept no fingerprint cannot tell: hasAppVersion() registers again, and records one
|
|
136
|
+
var otherKey = !isEmpty(info.zakhash) && info.zakhash !== keyFingerprint(settings.zak);
|
|
137
|
+
if (!otherApp && !otherKey) {
|
|
138
|
+
return Promise.resolve();
|
|
139
|
+
}
|
|
140
|
+
Console.log('init: stored data was registered with another ' + (otherApp ? 'base_url or app_domain' : 'auth_key') + ', clearing it and starting as a first visit'); // no i18n
|
|
141
|
+
previousAppVersion = ''; // no i18n
|
|
142
|
+
// the remote config values read from the store, which is about to go
|
|
143
|
+
hooks.resetRemoteConfig();
|
|
144
|
+
return clearStorage();
|
|
133
145
|
}
|
|
134
146
|
/**
|
|
135
147
|
* Timing an app may tune in init(). Each has a range: a value outside it is ignored with a
|
|
@@ -140,7 +152,7 @@ const TUNABLE = Object.freeze([
|
|
|
140
152
|
{ key: 'getupdates_interval', min: 10000, max: 86400000 }, // no i18n
|
|
141
153
|
{ key: 'batch_size', min: 1, max: 500 }, // no i18n
|
|
142
154
|
{ key: 'batch_request_timeout', min: 1, max: 30 }, // no i18n
|
|
143
|
-
{ key: 'min_session_duration', min:
|
|
155
|
+
{ key: 'min_session_duration', min: SESSION_TIMING_MIN_MS, max: SESSION_TIMING_MAX_MS }, // no i18n
|
|
144
156
|
{ key: 'heatmap_max_per_session', min: 0, max: 10000 }, // no i18n
|
|
145
157
|
]);
|
|
146
158
|
/** Reads the tunable timings out of the config. Anything missing goes back to its default. */
|
|
@@ -160,28 +172,45 @@ function applyIntervals(config) {
|
|
|
160
172
|
_ZAP._config[rule.key] = num;
|
|
161
173
|
Console.log('Apptics.init: ' + rule.key + ' set to ' + num); // no i18n
|
|
162
174
|
});
|
|
163
|
-
//
|
|
175
|
+
// max_session_duration: how long a tab may be inactive before its session ends, in
|
|
176
|
+
// milliseconds like min_session_duration. Kept on state in minutes (_ZAP.inactiveduration),
|
|
177
|
+
// which is how the session code counts it. The retired inactiveduration, in minutes, is still
|
|
178
|
+
// read when max_session_duration is not given
|
|
164
179
|
_ZAP.inactiveduration = DEFAULT_INACTIVE_MINUTES;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
180
|
+
var keyName = 'max_session_duration'; // no i18n
|
|
181
|
+
var ms = NaN;
|
|
182
|
+
if (!isEmpty(config.max_session_duration)) {
|
|
183
|
+
ms = Number(config.max_session_duration);
|
|
184
|
+
}
|
|
185
|
+
else if (!isEmpty(config.inactiveduration)) {
|
|
186
|
+
warnAlways('Apptics.init: inactiveduration is now max_session_duration, in milliseconds; rename it in your config'); // no i18n
|
|
187
|
+
keyName = 'inactiveduration'; // no i18n
|
|
188
|
+
ms = Math.round(Number(config.inactiveduration) * 60 * 1000);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!isFinite(ms) || ms < SESSION_TIMING_MIN_MS || ms > SESSION_TIMING_MAX_MS) {
|
|
194
|
+
warnAlways('Apptics.init: ' + keyName + ' must be between 5 seconds and 30 minutes (' + SESSION_TIMING_MIN_MS + ' to ' + SESSION_TIMING_MAX_MS + ' ms), keeping ' + (DEFAULT_INACTIVE_MINUTES * 60 * 1000) + ' ms'); // no i18n
|
|
195
|
+
return;
|
|
174
196
|
}
|
|
197
|
+
_ZAP.inactiveduration = keyName === 'inactiveduration' ? Number(config.inactiveduration) : ms / (60 * 1000); // no i18n
|
|
198
|
+
Console.log('Apptics.init: max_session_duration set to ' + ms + ' ms'); // no i18n
|
|
175
199
|
}
|
|
200
|
+
/** Everything the SDK stores: settings, ids and every queue. Resolves once it is all gone. */
|
|
176
201
|
function clearStorage() {
|
|
177
202
|
clearAttempts();
|
|
178
203
|
user_defaults.clear();
|
|
179
|
-
|
|
180
|
-
|
|
204
|
+
return Promise.all([
|
|
205
|
+
engagement_transactions, error_transactions, heatmap_transactions, remotelog_transactions, feedbacklog_transactions,
|
|
206
|
+
].map(function (queue) {
|
|
207
|
+
return queue.clear();
|
|
208
|
+
})).then(function () {
|
|
209
|
+
return undefined;
|
|
210
|
+
});
|
|
181
211
|
}
|
|
182
212
|
/**
|
|
183
|
-
* Starts the SDK. The config object is required:
|
|
184
|
-
* supply it (auto-init reads window.appticssettings._defaultoptions and calls init with it).
|
|
213
|
+
* Starts the SDK. The config object is required: the SDK starts only when the app calls this.
|
|
185
214
|
* Returns true when the config has base_url, auth_key, app_domain and appversion and start-up has
|
|
186
215
|
* begun (see ready()), false when it was already running, the config is missing or incomplete, or
|
|
187
216
|
* there is no browser. Start-up calls app/addversion with those four, which answers with aaid, the
|
|
@@ -227,15 +256,21 @@ function init(config) {
|
|
|
227
256
|
if (typeof config.ignore_do_not_track === 'boolean') { // no i18n
|
|
228
257
|
_ZAP._config.ignore_do_not_track = config.ignore_do_not_track;
|
|
229
258
|
}
|
|
230
|
-
// debug
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
259
|
+
// debug mode is switched from the browser console only (Apptics.enableDebug()), never from
|
|
260
|
+
// config, so an app cannot ship with it on
|
|
261
|
+
['debug', 'debug_api'].forEach(function (key) {
|
|
262
|
+
if (config[key] !== undefined) {
|
|
263
|
+
warnAlways('Apptics.init: ' + key + ' is no longer an init option and is ignored; type Apptics.enableDebug() in the browser console to turn debug mode on'); // no i18n
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
// off, unless enableDebug() was already called; starts (or clears) the idle hour
|
|
267
|
+
applyDebugConfig();
|
|
237
268
|
// what to call this device in the debug stream; see devicename in core/transport.ts
|
|
238
269
|
_ZAP._config.device_name = typeof config.device_name === 'string' ? config.device_name : AP_CONFIG.device_name; // no i18n
|
|
270
|
+
// push notifications always use the site's /apptics-pn-sw.js
|
|
271
|
+
if (config.push_service_worker !== undefined) {
|
|
272
|
+
warnAlways('Apptics.init: push_service_worker is no longer an init option and is ignored; push notifications use your site\'s /apptics-pn-sw.js'); // no i18n
|
|
273
|
+
}
|
|
239
274
|
// the SDK no longer reports its own failures to the Remote Logger page: only the lines an app
|
|
240
275
|
// logs with AppticsLogger go there
|
|
241
276
|
if (config.remote_log !== undefined) {
|
|
@@ -279,6 +314,10 @@ function init(config) {
|
|
|
279
314
|
// screen view can be stored
|
|
280
315
|
_ZAP._config.track_screen = typeof config.track_screen === 'boolean' ? config.track_screen : AP_CONFIG.track_screen; // no i18n
|
|
281
316
|
_ZAP._config.screen_routes = screenRouteRules(config.screen_routes);
|
|
317
|
+
// uncaught errors and tagged clicks, on unless the config says false: the listeners check
|
|
318
|
+
// these as each error or click happens
|
|
319
|
+
_ZAP._config.track_error = typeof config.track_error === 'boolean' ? config.track_error : AP_CONFIG.track_error; // no i18n
|
|
320
|
+
_ZAP._config.track_click = typeof config.track_click === 'boolean' ? config.track_click : AP_CONFIG.track_click; // no i18n
|
|
282
321
|
// a theme in the config wins; without one, what AppticsFeedback.setFeedbackTheme set stays
|
|
283
322
|
if (config.feedback_theme === 'light' || config.feedback_theme === 'dark' || config.feedback_theme === 'auto') { // no i18n
|
|
284
323
|
_ZAP._config.feedback_theme = config.feedback_theme;
|
|
@@ -300,46 +339,56 @@ function init(config) {
|
|
|
300
339
|
_ZAP._pending = [];
|
|
301
340
|
return false;
|
|
302
341
|
}
|
|
303
|
-
discardOtherAppData(_ZAP._defaultoptions)
|
|
304
|
-
// app/addversion is the first call and everything waits on it: it is what turns the four
|
|
305
|
-
// values init() was given into aaid, the portal and project ids every url carries, and
|
|
306
|
-
// appreleaseversionid, which metaWebSDKV2 refuses a payload without
|
|
307
|
-
return registerAppVersion().then(function (registered) {
|
|
342
|
+
return discardOtherAppData(_ZAP._defaultoptions).then(function () {
|
|
308
343
|
if (myGeneration !== generation) {
|
|
309
344
|
return false;
|
|
310
345
|
}
|
|
311
|
-
|
|
312
|
-
// a first visit with no network: start once it is back, keeping what the app
|
|
313
|
-
// tracks until then queued, rather than giving up for the rest of the page
|
|
314
|
-
warnAlways('Apptics.init: offline, so app/addversion is tried again when the browser is back online; calls made until then are kept'); // no i18n
|
|
315
|
-
return registerWhenOnline(myGeneration).then(function (ok) {
|
|
316
|
-
if (myGeneration !== generation) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
if (!ok) {
|
|
320
|
-
_ZAP._initialised = false;
|
|
321
|
-
_ZAP._token = ''; // no i18n
|
|
322
|
-
_ZAP._pending = [];
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
return start(config, myGeneration);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
if (!registered) {
|
|
329
|
-
warnAlways('Apptics.init: app/addversion did not return the app ids, not starting'); // no i18n
|
|
330
|
-
_ZAP._initialised = false;
|
|
331
|
-
_ZAP._token = ''; // no i18n
|
|
332
|
-
_ZAP._pending = [];
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
return start(config, myGeneration);
|
|
346
|
+
return startUp(config, myGeneration);
|
|
336
347
|
});
|
|
337
348
|
}).catch(function (err) {
|
|
338
349
|
Console.error('Apptics.init: start-up failed', err); // no i18n
|
|
339
350
|
return false;
|
|
340
351
|
});
|
|
352
|
+
// push calls made before init() wait on this start-up, success or not
|
|
353
|
+
hooks.pushInitCalled();
|
|
341
354
|
return true;
|
|
342
355
|
}
|
|
356
|
+
/** Start-up from app/addversion on, once the store holds only this app's data. */
|
|
357
|
+
function startUp(config, myGeneration) {
|
|
358
|
+
// app/addversion is the first call and everything waits on it: it is what turns the four
|
|
359
|
+
// values init() was given into aaid, the portal and project ids every url carries, and
|
|
360
|
+
// appreleaseversionid, which metaWebSDKV2 refuses a payload without
|
|
361
|
+
return registerAppVersion().then(function (registered) {
|
|
362
|
+
if (myGeneration !== generation) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if (!registered && appVersionFailedForNetwork()) {
|
|
366
|
+
// a first visit with no network: start once it is back, keeping what the app
|
|
367
|
+
// tracks until then queued, rather than giving up for the rest of the page
|
|
368
|
+
warnAlways('Apptics.init: offline, so app/addversion is tried again when the browser is back online; calls made until then are kept'); // no i18n
|
|
369
|
+
return registerWhenOnline(myGeneration).then(function (ok) {
|
|
370
|
+
if (myGeneration !== generation) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
if (!ok) {
|
|
374
|
+
_ZAP._initialised = false;
|
|
375
|
+
_ZAP._token = ''; // no i18n
|
|
376
|
+
_ZAP._pending = [];
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
return start(config, myGeneration);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
if (!registered) {
|
|
383
|
+
warnAlways('Apptics.init: app/addversion did not return the app ids, not starting'); // no i18n
|
|
384
|
+
_ZAP._initialised = false;
|
|
385
|
+
_ZAP._token = ''; // no i18n
|
|
386
|
+
_ZAP._pending = [];
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
return start(config, myGeneration);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
343
392
|
/** How often a start-up waiting on the network tries app/addversion again, besides on `online`. */
|
|
344
393
|
const OFFLINE_RETRY_MS = 60 * 1000;
|
|
345
394
|
/**
|
|
@@ -357,7 +406,7 @@ function registerWhenOnline(myGeneration) {
|
|
|
357
406
|
clearInterval(timer);
|
|
358
407
|
resolve(ok);
|
|
359
408
|
}
|
|
360
|
-
function
|
|
409
|
+
function tryRegister() {
|
|
361
410
|
if (myGeneration !== generation) {
|
|
362
411
|
done(false);
|
|
363
412
|
return;
|
|
@@ -366,7 +415,7 @@ function registerWhenOnline(myGeneration) {
|
|
|
366
415
|
return;
|
|
367
416
|
}
|
|
368
417
|
trying = true;
|
|
369
|
-
registerAppVersion().then(function (registered) {
|
|
418
|
+
quietly('app/addversion retry', registerAppVersion().then(function (registered) {
|
|
370
419
|
trying = false;
|
|
371
420
|
if (registered) {
|
|
372
421
|
done(true);
|
|
@@ -375,8 +424,12 @@ function registerWhenOnline(myGeneration) {
|
|
|
375
424
|
warnAlways('Apptics.init: app/addversion did not return the app ids, not starting'); // no i18n
|
|
376
425
|
done(false);
|
|
377
426
|
}
|
|
378
|
-
})
|
|
427
|
+
}, function (err) {
|
|
428
|
+
trying = false;
|
|
429
|
+
throw err;
|
|
430
|
+
}));
|
|
379
431
|
}
|
|
432
|
+
var attempt = shield('app/addversion retry', tryRegister); // no i18n
|
|
380
433
|
window.addEventListener('online', attempt); // no i18n
|
|
381
434
|
timer = setInterval(attempt, OFFLINE_RETRY_MS);
|
|
382
435
|
});
|
|
@@ -446,6 +499,8 @@ function start(config, myGeneration) {
|
|
|
446
499
|
_ZAP._token = String(_ZAP._defaultoptions.aaid);
|
|
447
500
|
// last known server settings (getupdates) apply before anything is tracked
|
|
448
501
|
restoreServerSettings();
|
|
502
|
+
// the user this browser was tracking as, before getsdkconfig is asked: it carries their ids
|
|
503
|
+
getUserInfo();
|
|
449
504
|
// a new release of the app, against the version the stored data was for (see
|
|
450
505
|
// discardOtherAppData): a first visit has none, and is no change
|
|
451
506
|
var appVersionChanged = previousAppVersion !== '' && previousAppVersion != _ZAP._defaultoptions.appversion; // no i18n
|
|
@@ -464,11 +519,15 @@ function start(config, myGeneration) {
|
|
|
464
519
|
}
|
|
465
520
|
/** The rest of start-up, once the device is set up. */
|
|
466
521
|
function startTracking(appVersionChanged, myGeneration) {
|
|
467
|
-
//
|
|
468
|
-
// succeeded (registerDeviceWithApptics)
|
|
469
|
-
//
|
|
522
|
+
// getsdkconfig, once per page load and then at each answer's next_check_after. A first visit
|
|
523
|
+
// asked as soon as device/add succeeded (registerDeviceWithApptics) and this does nothing; a
|
|
524
|
+
// returning visit, whose device is registered, asks now, after app/addversion. Until it
|
|
525
|
+
// answers, the settings saved by the last visit apply (restoreServerSettings, in start())
|
|
526
|
+
startServerSettingChecks();
|
|
470
527
|
if (appVersionChanged) {
|
|
471
|
-
|
|
528
|
+
// the device is told its new appversionid, which app/addversion has just answered for this
|
|
529
|
+
// release and device/add declares mandatory: sent empty, the update was refused, and every
|
|
530
|
+
// call after it went without the id
|
|
472
531
|
updateDeviceWithApptics(_ZAP._device_info).then(function (result) {
|
|
473
532
|
if (isSuccess(result)) {
|
|
474
533
|
Console.log('init: appversion updated to ' + _ZAP._defaultoptions.appversion); // no i18n
|
|
@@ -481,13 +540,12 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
481
540
|
_ZAP._device_info.connectionType = getConnectionType();
|
|
482
541
|
attachListeners();
|
|
483
542
|
_ZAP._properties.orientation = getOrientation();
|
|
484
|
-
getUserInfo();
|
|
485
543
|
return checkAndUpdateSession().then(function () {
|
|
486
544
|
if (myGeneration !== generation) {
|
|
487
545
|
return false;
|
|
488
546
|
}
|
|
489
547
|
startTimers();
|
|
490
|
-
sendStoredLogs();
|
|
548
|
+
quietly('sending stored logs', sendStoredLogs()); // no i18n
|
|
491
549
|
_ZAP._ready = true;
|
|
492
550
|
// replay calls made while storage was loading, in order
|
|
493
551
|
var pending = _ZAP._pending;
|
|
@@ -505,8 +563,11 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
505
563
|
enableScreenTracking(_ZAP._config.track_screen);
|
|
506
564
|
// a no-op unless the remote-config entry was imported, which sets the hook
|
|
507
565
|
hooks.remoteConfigStarted();
|
|
566
|
+
// the same for push notification: a no-op unless its entry was imported
|
|
567
|
+
hooks.pushStarted();
|
|
508
568
|
window.appticsReadyStatus = true;
|
|
509
569
|
if (typeof window.appticsReady == 'function') { // no i18n
|
|
570
|
+
// the app's own callback: what it throws is the app's, so it is not caught here
|
|
510
571
|
window.appticsReady();
|
|
511
572
|
}
|
|
512
573
|
return true;
|
|
@@ -516,6 +577,7 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
516
577
|
function reset() {
|
|
517
578
|
generation++;
|
|
518
579
|
stopTimers();
|
|
580
|
+
resetInactivity();
|
|
519
581
|
// the wrappers come off with everything else; the init() below puts them back if the config
|
|
520
582
|
// asked for them, so a reset that has no config to restore leaves XHR and fetch untouched
|
|
521
583
|
enableApiTracking(false);
|
|
@@ -524,7 +586,10 @@ function reset() {
|
|
|
524
586
|
hooks.trackHeatmap(false);
|
|
525
587
|
hooks.resetHeatmap();
|
|
526
588
|
hooks.resetRemoteConfig();
|
|
527
|
-
|
|
589
|
+
hooks.resetPush();
|
|
590
|
+
_ZAP._pushEnabled = false;
|
|
591
|
+
_ZAP._wmsConfig = null;
|
|
592
|
+
quietly('clearing storage', clearStorage()); // no i18n
|
|
528
593
|
_ZAP._initialised = false;
|
|
529
594
|
_ZAP._ready = false;
|
|
530
595
|
_ZAP._pending = [];
|
|
@@ -546,6 +611,26 @@ function reset() {
|
|
|
546
611
|
function isActive() {
|
|
547
612
|
return _ZAP._ready;
|
|
548
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* AppticsEvent.setClickTracking: click tracking from markup on or off, as the `track_click`
|
|
616
|
+
* config sets it. The listener stays; it checks the switch on every click.
|
|
617
|
+
*/
|
|
618
|
+
function setClickTracking(enabled) {
|
|
619
|
+
_ZAP._config.track_click = typeof enabled === 'boolean' ? enabled : true; // no i18n
|
|
620
|
+
Console.log('click tracking: ' + (_ZAP._config.track_click ? 'on' : 'off')); // no i18n
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* AppticsScreen.setScreenTracking: automatic screen tracking on or off, as the `track_screen`
|
|
624
|
+
* config sets it. Applied now once the SDK is running; before that it is only noted, and start()
|
|
625
|
+
* switches tracking to it. Like the other switches, the next init() (a reset() too) goes back to
|
|
626
|
+
* what its config says.
|
|
627
|
+
*/
|
|
628
|
+
function setScreenTracking(enabled) {
|
|
629
|
+
_ZAP._config.track_screen = typeof enabled === 'boolean' ? enabled : true; // no i18n
|
|
630
|
+
if (isActive()) {
|
|
631
|
+
enableScreenTracking(_ZAP._config.track_screen);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
549
634
|
/**
|
|
550
635
|
* A click-tracking attribute, in either spelling: `apeventaction`, or `data-apeventaction`, which
|
|
551
636
|
* is valid HTML and what React and TypeScript accept without declaring the attribute.
|
|
@@ -561,7 +646,7 @@ function trackingSelector(name) {
|
|
|
561
646
|
// Declarative click tracking: <el apeventaction="name" apeventprops='{"k":"v"}'> inside <el apgroupaction="group">,
|
|
562
647
|
// or the same attributes with a data- prefix
|
|
563
648
|
function onDocumentClick(event) {
|
|
564
|
-
if (!window.appticsReadyStatus || !isActive()) {
|
|
649
|
+
if (!window.appticsReadyStatus || !isActive() || !_ZAP._config.track_click) {
|
|
565
650
|
return;
|
|
566
651
|
}
|
|
567
652
|
var start = event.target;
|
|
@@ -577,7 +662,8 @@ function onDocumentClick(event) {
|
|
|
577
662
|
}
|
|
578
663
|
var eventName = trackingAttribute(targetElem, 'apeventaction') || ''; // no i18n
|
|
579
664
|
var groupElem = targetElem.closest(trackingSelector('apgroupaction')); // no i18n
|
|
580
|
-
|
|
665
|
+
// no apgroupaction around it: trackEvent refuses it and says the group is missing
|
|
666
|
+
var groupName = (groupElem && trackingAttribute(groupElem, 'apgroupaction')) || undefined; // no i18n
|
|
581
667
|
var eventProps = {};
|
|
582
668
|
var rawProps = trackingAttribute(targetElem, 'apeventprops'); // no i18n
|
|
583
669
|
if (!isEmpty(rawProps)) {
|
|
@@ -601,25 +687,33 @@ function onDocumentClick(event) {
|
|
|
601
687
|
function onPageHidden() {
|
|
602
688
|
if (!isActive())
|
|
603
689
|
return;
|
|
604
|
-
|
|
605
|
-
|
|
690
|
+
// the moment the user left: the session ends at it if they are not back within max_session_duration
|
|
691
|
+
quietly('closing the screen', markTabInactive(sendEndedSession)); // no i18n
|
|
692
|
+
quietly('closing the screen', updateScreenWithEndtime()); // no i18n
|
|
693
|
+
quietly('sending on page hide', flush(true)); // no i18n
|
|
606
694
|
Console.log('page hidden: closing the open screen and flushing'); // no i18n
|
|
607
695
|
}
|
|
696
|
+
/** A session that inactivity ended while the tab was away: sent now, not when the user returns. */
|
|
697
|
+
const sendEndedSession = shield('sending the ended session', function () {
|
|
698
|
+
if (!isActive())
|
|
699
|
+
return;
|
|
700
|
+
quietly('sending the ended session', flush()); // no i18n
|
|
701
|
+
});
|
|
608
702
|
/**
|
|
609
703
|
* The tab is closing, or the page is being replaced or frozen into the back/forward cache.
|
|
610
704
|
* The session ends here, and everything queued goes out by keepalive, since a normal
|
|
611
705
|
* request would be cancelled with the page.
|
|
612
706
|
*/
|
|
613
|
-
|
|
707
|
+
const onPageClosing = shield('page closing', function () {
|
|
614
708
|
if (!isActive())
|
|
615
709
|
return;
|
|
616
710
|
Console.log('page closing: ending the session and sending what is queued'); // no i18n
|
|
617
|
-
updateScreenWithEndtime();
|
|
618
|
-
forgetStoredLogs();
|
|
619
|
-
endCurrentSession().then(function () {
|
|
711
|
+
quietly('page closing', updateScreenWithEndtime()); // no i18n
|
|
712
|
+
quietly('page closing', forgetStoredLogs()); // no i18n
|
|
713
|
+
quietly('page closing', endCurrentSession().then(function () {
|
|
620
714
|
return flush(true);
|
|
621
|
-
});
|
|
622
|
-
}
|
|
715
|
+
}));
|
|
716
|
+
});
|
|
623
717
|
function attachListeners() {
|
|
624
718
|
if (listenersAttached) {
|
|
625
719
|
return;
|
|
@@ -628,57 +722,62 @@ function attachListeners() {
|
|
|
628
722
|
// listen for connection change events (only available in w3c implementation)
|
|
629
723
|
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
630
724
|
if (connection && connection.addEventListener) {
|
|
631
|
-
connection.addEventListener('change', function () {
|
|
725
|
+
connection.addEventListener('change', shield('connection change', function () {
|
|
632
726
|
_ZAP._device_info.connectionType = getConnectionType();
|
|
633
|
-
});
|
|
727
|
+
}));
|
|
634
728
|
}
|
|
635
729
|
// Track when the window loses focus (user switches to another window or application)
|
|
636
|
-
window.addEventListener('blur', function () {
|
|
730
|
+
window.addEventListener('blur', shield('window blur', function () {
|
|
637
731
|
if (!isActive())
|
|
638
732
|
return;
|
|
733
|
+
// focus moving into an iframe on the page blurs the window too, and the user is still here
|
|
734
|
+
if (document.activeElement && document.activeElement.tagName === 'IFRAME')
|
|
735
|
+
return; // no i18n
|
|
639
736
|
Console.log('Window lost focus, user switched to another window or application'); // no i18n
|
|
640
|
-
|
|
641
|
-
});
|
|
737
|
+
quietly('window blur', markTabInactive(sendEndedSession)); // no i18n
|
|
738
|
+
}));
|
|
642
739
|
// Track when the window gains focus (user switches back to the window)
|
|
643
|
-
window.addEventListener('focus', function () {
|
|
740
|
+
window.addEventListener('focus', shield('window focus', function () {
|
|
644
741
|
if (!isActive())
|
|
645
742
|
return;
|
|
646
743
|
Console.log('Window regained focus, user switched back to the window'); // no i18n
|
|
647
|
-
|
|
744
|
+
markTabActive();
|
|
745
|
+
quietly('window focus', checkAndUpdateSession()); // no i18n
|
|
648
746
|
startTimers();
|
|
649
|
-
});
|
|
747
|
+
}));
|
|
650
748
|
// IndexedDB writes are async, so unload work starts on pagehide rather than beforeunload
|
|
651
749
|
window.addEventListener('pagehide', onPageClosing); // no i18n
|
|
652
750
|
// back/forward cache: pagehide ended the session, so coming back starts a new one
|
|
653
|
-
window.addEventListener('pageshow', function (event) {
|
|
751
|
+
window.addEventListener('pageshow', shield('page show', function (event) {
|
|
654
752
|
if (!isActive() || !event.persisted)
|
|
655
753
|
return;
|
|
656
754
|
Console.log('restored from the back/forward cache: starting a new session'); // no i18n
|
|
755
|
+
markTabActive();
|
|
657
756
|
// the screen the page was left on starts a new view, in the new session
|
|
658
|
-
checkAndUpdateSession().then(resumeScreen);
|
|
757
|
+
quietly('page show', checkAndUpdateSession().then(resumeScreen)); // no i18n
|
|
659
758
|
startTimers();
|
|
660
|
-
});
|
|
661
|
-
document.addEventListener('visibilitychange', function () {
|
|
759
|
+
}));
|
|
760
|
+
document.addEventListener('visibilitychange', shield('visibility change', function () {
|
|
662
761
|
if (!isActive())
|
|
663
762
|
return;
|
|
664
763
|
if (document.visibilityState === 'hidden') { // no i18n
|
|
665
764
|
onPageHidden();
|
|
666
765
|
return;
|
|
667
766
|
}
|
|
668
|
-
// back in view
|
|
669
|
-
|
|
767
|
+
// back in view. getsdkconfig is not asked here: only at its next_check_after, on a tab's
|
|
768
|
+
// first page load, and when a user is registered or getupdates reports a change
|
|
769
|
+
markTabActive();
|
|
670
770
|
// hiding ended the screen view; the screen the user is back on starts a new one, after the
|
|
671
771
|
// session is settled so the view belongs to the right one
|
|
672
|
-
checkAndUpdateSession().then(resumeScreen);
|
|
673
|
-
|
|
674
|
-
});
|
|
772
|
+
quietly('visibility change', checkAndUpdateSession().then(resumeScreen)); // no i18n
|
|
773
|
+
}));
|
|
675
774
|
// if we are running in cordova use ondeviceready otherwise onload
|
|
676
|
-
window.addEventListener(window.cordova ? 'deviceready' : 'load', function () {
|
|
775
|
+
window.addEventListener(window.cordova ? 'deviceready' : 'load', shield('page load', function () {
|
|
677
776
|
if (isActive())
|
|
678
|
-
checkAndUpdateSession();
|
|
679
|
-
}, { passive: true });
|
|
777
|
+
quietly('page load', checkAndUpdateSession()); // no i18n
|
|
778
|
+
}), { passive: true });
|
|
680
779
|
// Always send pending requests when the connection comes back online
|
|
681
|
-
window.addEventListener('online', function () {
|
|
780
|
+
window.addEventListener('online', shield('back online', function () {
|
|
682
781
|
if (!isActive())
|
|
683
782
|
return;
|
|
684
783
|
// a first visit that started offline has no device ids yet, and nothing can be sent
|
|
@@ -686,44 +785,58 @@ function attachListeners() {
|
|
|
686
785
|
if (needsDevice()) {
|
|
687
786
|
Console.log('back online: registering this device before sending'); // no i18n
|
|
688
787
|
// the same locked path as start-up, so two tabs coming back online register it once
|
|
689
|
-
prepareDevice().then(deviceReady).then(function () {
|
|
788
|
+
quietly('back online', prepareDevice().then(deviceReady).then(function () {
|
|
690
789
|
if (!isActive())
|
|
691
790
|
return;
|
|
692
|
-
flush();
|
|
791
|
+
quietly('back online', flush()); // no i18n
|
|
693
792
|
// the lines logged while offline are waiting too, and log/add needs the same ids
|
|
694
|
-
sendStoredLogs();
|
|
695
|
-
});
|
|
793
|
+
quietly('back online', sendStoredLogs()); // no i18n
|
|
794
|
+
}));
|
|
696
795
|
return;
|
|
697
796
|
}
|
|
698
|
-
flush();
|
|
699
|
-
sendStoredLogs();
|
|
700
|
-
}, { passive: true });
|
|
797
|
+
quietly('back online', flush()); // no i18n
|
|
798
|
+
quietly('back online', sendStoredLogs()); // no i18n
|
|
799
|
+
}), { passive: true });
|
|
701
800
|
if (window.screen && window.screen.orientation && typeof window.screen.orientation.addEventListener === 'function') { // no i18n
|
|
702
|
-
window.screen.orientation.addEventListener('change', function () {
|
|
801
|
+
window.screen.orientation.addEventListener('change', shield('orientation change', function () {
|
|
703
802
|
_ZAP._properties.orientation = getOrientation();
|
|
704
|
-
});
|
|
803
|
+
}));
|
|
705
804
|
}
|
|
706
|
-
window.addEventListener('unhandledrejection', function (event) {
|
|
707
|
-
if (isActive()
|
|
708
|
-
|
|
805
|
+
window.addEventListener('unhandledrejection', shield('error tracking', function (event) {
|
|
806
|
+
if (!isActive() || !_ZAP._config.track_error) {
|
|
807
|
+
return;
|
|
709
808
|
}
|
|
710
|
-
|
|
809
|
+
// a promise the SDK handed the app, rejected and left unhandled: the SDK's failure
|
|
810
|
+
if (isSdkRejection(event.reason)) {
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
trackError(event);
|
|
814
|
+
}));
|
|
711
815
|
// in the capture phase: a <script>, <img> or <link> that fails to load fires `error` on the
|
|
712
816
|
// element, and it does not bubble, so a bubbling listener never hears of it. One listener
|
|
713
817
|
// hears both kinds, the window's own errors included, so none is counted twice
|
|
714
|
-
window.addEventListener('error', function (event) {
|
|
715
|
-
if (!isActive() || !_ZAP.
|
|
818
|
+
window.addEventListener('error', shield('error tracking', function (event) {
|
|
819
|
+
if (!isActive() || !_ZAP._config.track_error) {
|
|
716
820
|
return;
|
|
717
821
|
}
|
|
718
822
|
var target = event.target;
|
|
719
823
|
if (target && target !== window && typeof target.tagName === 'string') { // no i18n
|
|
824
|
+
// the SDK's own elements (its style, the Quartz script, the feedback form and its
|
|
825
|
+
// preview video, the recording timer) are not the app's
|
|
826
|
+
if (isSdkElement(target)) {
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
720
829
|
// named by describeTarget: Event "error" on <script src="...">
|
|
721
830
|
trackError({ type: 'error', reason: event }); // no i18n
|
|
722
831
|
return;
|
|
723
832
|
}
|
|
833
|
+
// thrown by the SDK's <script> file or the Quartz recorder it loaded
|
|
834
|
+
if (isSdkScript(event.filename)) {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
724
837
|
trackError(event);
|
|
725
|
-
}, true);
|
|
726
|
-
window.addEventListener('click', onDocumentClick, true); // no i18n
|
|
838
|
+
}), true);
|
|
839
|
+
window.addEventListener('click', shield('click tracking', onDocumentClick), true); // no i18n
|
|
727
840
|
}
|
|
728
841
|
|
|
729
|
-
export { init, ready, reset, screenRouteRules };
|
|
842
|
+
export { init, ready, reset, screenRouteRules, setClickTracking, setScreenTracking };
|