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