@zoho_apptics/apptics-js-sdk 2.0.0-beta.2 → 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 +47 -0
- package/README.md +229 -174
- 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 -3
- package/dist/cjs/core/consent.d.ts +9 -6
- package/dist/cjs/core/consent.js +63 -10
- 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 +44 -0
- package/dist/cjs/core/constants.js +55 -1
- 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.js +1 -1
- 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 +25 -1
- package/dist/cjs/core/hooks.js +11 -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 +5 -1
- package/dist/cjs/core/state.js +3 -1
- package/dist/cjs/core/storage.d.ts +7 -0
- package/dist/cjs/core/storage.js +28 -6
- package/dist/cjs/core/stylesheet.js +1 -1
- package/dist/cjs/core/transport.d.ts +15 -4
- package/dist/cjs/core/transport.js +63 -13
- package/dist/cjs/core/utils.js +1 -1
- package/dist/cjs/core/validate.js +6 -5
- package/dist/cjs/device/appversion.js +1 -1
- package/dist/cjs/device/index.js +63 -15
- 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 +1 -1
- package/dist/cjs/engagement/session.js +77 -37
- package/dist/cjs/engagement/track.js +9 -6
- package/dist/cjs/errors/send.js +1 -1
- package/dist/cjs/errors/track.js +3 -2
- package/dist/cjs/feedback/controls.d.ts +30 -4
- package/dist/cjs/feedback/controls.js +237 -51
- 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.js +5 -4
- package/dist/cjs/feedback/quartz.js +5 -2
- package/dist/cjs/feedback/send.d.ts +4 -1
- package/dist/cjs/feedback/send.js +56 -15
- package/dist/cjs/feedback/styles.js +2 -2
- package/dist/cjs/feedback/template.d.ts +4 -2
- package/dist/cjs/feedback/template.js +67 -46
- package/dist/cjs/feedback/ui.d.ts +40 -4
- package/dist/cjs/feedback/ui.js +208 -89
- package/dist/cjs/heatmap/send.js +1 -1
- package/dist/cjs/heatmap/track.js +13 -9
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/lifecycle.js +119 -72
- 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.js +27 -8
- package/dist/cjs/remoteconfig/index.d.ts +1 -6
- package/dist/cjs/remoteconfig/index.js +4 -28
- package/dist/cjs/remoteconfig/store.js +1 -1
- package/dist/cjs/remoteconfig/tz-countries.js +1 -1
- package/dist/cjs/remotelog/callsite.js +1 -1
- package/dist/cjs/remotelog/gate.js +1 -1
- package/dist/cjs/remotelog/logger.js +1 -1
- package/dist/cjs/remotelog/send.js +5 -4
- package/dist/cjs/remotelogger/index.js +1 -1
- package/dist/cjs/scheduler.js +11 -5
- 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 +31 -15
- package/dist/cjs/user/index.d.ts +7 -0
- package/dist/cjs/user/index.js +25 -7
- package/dist/esm/core/attempts.js +1 -1
- package/dist/esm/core/batch.js +4 -3
- package/dist/esm/core/consent.d.ts +9 -6
- package/dist/esm/core/consent.js +67 -16
- 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 +44 -0
- package/dist/esm/core/constants.js +52 -2
- 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.js +1 -1
- 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 +25 -1
- package/dist/esm/core/hooks.js +11 -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 +5 -1
- package/dist/esm/core/state.js +3 -1
- package/dist/esm/core/storage.d.ts +7 -0
- package/dist/esm/core/storage.js +28 -8
- package/dist/esm/core/stylesheet.js +1 -1
- package/dist/esm/core/transport.d.ts +15 -4
- package/dist/esm/core/transport.js +64 -16
- package/dist/esm/core/utils.js +1 -1
- package/dist/esm/core/validate.js +6 -5
- package/dist/esm/device/appversion.js +1 -1
- package/dist/esm/device/index.js +67 -19
- 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 +1 -1
- package/dist/esm/engagement/session.js +77 -37
- package/dist/esm/engagement/track.js +9 -6
- package/dist/esm/errors/send.js +1 -1
- package/dist/esm/errors/track.js +3 -2
- package/dist/esm/feedback/controls.d.ts +30 -4
- package/dist/esm/feedback/controls.js +234 -52
- 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.js +5 -4
- package/dist/esm/feedback/quartz.js +5 -2
- package/dist/esm/feedback/send.d.ts +4 -1
- package/dist/esm/feedback/send.js +56 -16
- package/dist/esm/feedback/styles.js +2 -2
- package/dist/esm/feedback/template.d.ts +4 -2
- package/dist/esm/feedback/template.js +67 -46
- package/dist/esm/feedback/ui.d.ts +40 -4
- package/dist/esm/feedback/ui.js +210 -91
- package/dist/esm/heatmap/send.js +1 -1
- package/dist/esm/heatmap/track.js +13 -9
- package/dist/esm/index.js +2 -2
- package/dist/esm/lifecycle.js +120 -73
- 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.js +27 -8
- package/dist/esm/remoteconfig/index.d.ts +1 -6
- package/dist/esm/remoteconfig/index.js +4 -28
- package/dist/esm/remoteconfig/store.js +1 -1
- package/dist/esm/remoteconfig/tz-countries.js +1 -1
- package/dist/esm/remotelog/callsite.js +1 -1
- package/dist/esm/remotelog/gate.js +1 -1
- package/dist/esm/remotelog/logger.js +1 -1
- package/dist/esm/remotelog/send.js +5 -4
- package/dist/esm/remotelogger/index.js +1 -1
- package/dist/esm/scheduler.js +11 -5
- 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 +31 -15
- package/dist/esm/user/index.d.ts +7 -0
- package/dist/esm/user/index.js +26 -9
- 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 +2 -2
- package/dist/remoteconfig.esm.min.js.map +1 -1
- package/dist/remotelogger.esm.min.js +2 -2
- package/dist/remotelogger.esm.min.js.map +1 -1
- package/package.json +15 -2
- package/dist/chunks/lifecycle-C6m1W7jo.min.js +0 -3
- package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +0 -1
- package/dist/chunks/send-CgUO82ne.min.js +0 -3
- package/dist/chunks/send-CgUO82ne.min.js.map +0 -1
package/dist/esm/heatmap/send.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
|
import { _ZAP } from '../core/state.js';
|
|
3
3
|
import { Console, warnAlways } from '../core/logger.js';
|
|
4
4
|
import { cloneObject } from '../core/utils.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { AP_LOG_MODULE, AP_CONFIG, AP_TRACKING_STATUS } from '../core/constants.js';
|
|
3
3
|
import { getConfig, _ZAP } from '../core/state.js';
|
|
4
4
|
import { Console, logFailure } from '../core/logger.js';
|
|
@@ -10,6 +10,7 @@ import { canTrackHeatmap, getTrackingStatus } from '../core/consent.js';
|
|
|
10
10
|
import { screenForRecord } from '../engagement/track.js';
|
|
11
11
|
import { hooks } from '../core/hooks.js';
|
|
12
12
|
import { noteDebugActivity } from '../core/debug.js';
|
|
13
|
+
import { shield, quietly } from '../core/shield.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Where people click and how far they scroll.
|
|
@@ -219,7 +220,7 @@ function store(record) {
|
|
|
219
220
|
recorded++;
|
|
220
221
|
noteDebugActivity();
|
|
221
222
|
// a heatmap record is worth a session in the same way an event is
|
|
222
|
-
commitPendingSession();
|
|
223
|
+
quietly('session', commitPendingSession()); // no i18n
|
|
223
224
|
heatmap_transactions.add(record);
|
|
224
225
|
Console.dir(record);
|
|
225
226
|
}
|
|
@@ -280,13 +281,13 @@ function watchForDeadClick(record, target) {
|
|
|
280
281
|
catch (err) {
|
|
281
282
|
return;
|
|
282
283
|
}
|
|
283
|
-
setTimeout(function () {
|
|
284
|
+
setTimeout(shield('heatmap dead click', function () {
|
|
284
285
|
observer.disconnect();
|
|
285
286
|
if (!changed && window.location.href === url) {
|
|
286
287
|
record.is_dead_click = 1;
|
|
287
288
|
heatmap_transactions.update(record);
|
|
288
289
|
}
|
|
289
|
-
}, DEAD_CLICK_MS);
|
|
290
|
+
}), DEAD_CLICK_MS);
|
|
290
291
|
}
|
|
291
292
|
/**
|
|
292
293
|
* What a scroll event moved, as a gesture counts it: null for the window (the event's target is
|
|
@@ -343,7 +344,7 @@ function onScroll(event) {
|
|
|
343
344
|
else {
|
|
344
345
|
clearTimeout(scrollTimer);
|
|
345
346
|
}
|
|
346
|
-
scrollTimer = setTimeout(endScrollGesture, SCROLL_IDLE_MS);
|
|
347
|
+
scrollTimer = setTimeout(shield('heatmap scroll', endScrollGesture), SCROLL_IDLE_MS); // no i18n
|
|
347
348
|
}
|
|
348
349
|
/** One record for the whole burst, once the page has been still for SCROLL_IDLE_MS. */
|
|
349
350
|
function endScrollGesture() {
|
|
@@ -402,6 +403,9 @@ function endScrollGesture() {
|
|
|
402
403
|
logFailure(AP_LOG_MODULE.HEATMAP, 'apptics.heatmap: scroll capture failed: ' + String(err)); // no i18n
|
|
403
404
|
}
|
|
404
405
|
}
|
|
406
|
+
// the listeners as added, so the same functions come off again
|
|
407
|
+
const pointerListener = shield('heatmap click', onPointerDown); // no i18n
|
|
408
|
+
const scrollListener = shield('heatmap scroll', onScroll); // no i18n
|
|
405
409
|
/** Turns capture on or off. Listeners are passive, so they never delay a click or a scroll. */
|
|
406
410
|
function trackHeatmap(status) {
|
|
407
411
|
var wanted = typeof status === 'boolean' ? status : true; // no i18n
|
|
@@ -412,14 +416,14 @@ function trackHeatmap(status) {
|
|
|
412
416
|
// where the page already is, so the first gesture is measured from here and not from 0
|
|
413
417
|
lastX = Math.round(window.scrollX || 0);
|
|
414
418
|
lastY = Math.round(window.scrollY || 0);
|
|
415
|
-
window.addEventListener('pointerdown',
|
|
416
|
-
window.addEventListener('scroll',
|
|
419
|
+
window.addEventListener('pointerdown', pointerListener, { capture: true, passive: true }); // no i18n
|
|
420
|
+
window.addEventListener('scroll', scrollListener, { capture: true, passive: true }); // no i18n
|
|
417
421
|
installed = true;
|
|
418
422
|
Console.log('apptics.heatmap: capturing clicks and scrolls'); // no i18n
|
|
419
423
|
return;
|
|
420
424
|
}
|
|
421
|
-
window.removeEventListener('pointerdown',
|
|
422
|
-
window.removeEventListener('scroll',
|
|
425
|
+
window.removeEventListener('pointerdown', pointerListener, true); // no i18n
|
|
426
|
+
window.removeEventListener('scroll', scrollListener, true); // no i18n
|
|
423
427
|
// a gesture still settling when capture stops (a single-page app leaving a heatmap page) is
|
|
424
428
|
// recorded as it stands, not dropped: it was the visitor's last scroll on that page
|
|
425
429
|
if (scrollTimer !== null) {
|
package/dist/esm/index.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
|
import { AP_TRACKING_STATUS } from './core/constants.js';
|
|
3
3
|
import { forward, guard } from './core/guard.js';
|
|
4
4
|
import { warnAlways } from './core/logger.js';
|
|
@@ -168,7 +168,7 @@ const setTrackingStatusGuarded = guard('AppticsSettings.setTrackingStatus', setT
|
|
|
168
168
|
const getTrackingStatusGuarded = guard('AppticsSettings.getTrackingStatus', getTrackingStatus); // no i18n
|
|
169
169
|
/** Android's AppticsSettings: what the SDK may track for this visitor. */
|
|
170
170
|
const AppticsSettings = {
|
|
171
|
-
/** The states setTrackingStatus takes: USAGE_TRACKING_WITH_PII, USAGE_TRACKING_WITHOUT_PII, NO_TRACKING. */
|
|
171
|
+
/** The states setTrackingStatus takes: USAGE_TRACKING_WITH_PII, USAGE_TRACKING_WITHOUT_PII, ANONYMOUS, NO_TRACKING. */
|
|
172
172
|
AP_TRACKING_STATUS: AP_TRACKING_STATUS,
|
|
173
173
|
setTrackingStatus: function setTrackingStatus(status) { return forward(setTrackingStatusGuarded, arguments); },
|
|
174
174
|
getTrackingStatus: function getTrackingStatus() { return forward(getTrackingStatusGuarded, arguments); },
|
package/dist/esm/lifecycle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
@@ -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. */
|
|
@@ -151,7 +152,7 @@ const TUNABLE = Object.freeze([
|
|
|
151
152
|
{ key: 'getupdates_interval', min: 10000, max: 86400000 }, // no i18n
|
|
152
153
|
{ key: 'batch_size', min: 1, max: 500 }, // no i18n
|
|
153
154
|
{ key: 'batch_request_timeout', min: 1, max: 30 }, // no i18n
|
|
154
|
-
{ key: 'min_session_duration', min:
|
|
155
|
+
{ key: 'min_session_duration', min: SESSION_TIMING_MIN_MS, max: SESSION_TIMING_MAX_MS }, // no i18n
|
|
155
156
|
{ key: 'heatmap_max_per_session', min: 0, max: 10000 }, // no i18n
|
|
156
157
|
]);
|
|
157
158
|
/** Reads the tunable timings out of the config. Anything missing goes back to its default. */
|
|
@@ -171,18 +172,30 @@ function applyIntervals(config) {
|
|
|
171
172
|
_ZAP._config[rule.key] = num;
|
|
172
173
|
Console.log('Apptics.init: ' + rule.key + ' set to ' + num); // no i18n
|
|
173
174
|
});
|
|
174
|
-
//
|
|
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
|
|
175
179
|
_ZAP.inactiveduration = DEFAULT_INACTIVE_MINUTES;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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;
|
|
185
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;
|
|
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
|
|
186
199
|
}
|
|
187
200
|
/** Everything the SDK stores: settings, ids and every queue. Resolves once it is all gone. */
|
|
188
201
|
function clearStorage() {
|
|
@@ -243,15 +256,21 @@ function init(config) {
|
|
|
243
256
|
if (typeof config.ignore_do_not_track === 'boolean') { // no i18n
|
|
244
257
|
_ZAP._config.ignore_do_not_track = config.ignore_do_not_track;
|
|
245
258
|
}
|
|
246
|
-
// debug
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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();
|
|
253
268
|
// what to call this device in the debug stream; see devicename in core/transport.ts
|
|
254
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
|
+
}
|
|
255
274
|
// the SDK no longer reports its own failures to the Remote Logger page: only the lines an app
|
|
256
275
|
// logs with AppticsLogger go there
|
|
257
276
|
if (config.remote_log !== undefined) {
|
|
@@ -330,6 +349,8 @@ function init(config) {
|
|
|
330
349
|
Console.error('Apptics.init: start-up failed', err); // no i18n
|
|
331
350
|
return false;
|
|
332
351
|
});
|
|
352
|
+
// push calls made before init() wait on this start-up, success or not
|
|
353
|
+
hooks.pushInitCalled();
|
|
333
354
|
return true;
|
|
334
355
|
}
|
|
335
356
|
/** Start-up from app/addversion on, once the store holds only this app's data. */
|
|
@@ -385,7 +406,7 @@ function registerWhenOnline(myGeneration) {
|
|
|
385
406
|
clearInterval(timer);
|
|
386
407
|
resolve(ok);
|
|
387
408
|
}
|
|
388
|
-
function
|
|
409
|
+
function tryRegister() {
|
|
389
410
|
if (myGeneration !== generation) {
|
|
390
411
|
done(false);
|
|
391
412
|
return;
|
|
@@ -394,7 +415,7 @@ function registerWhenOnline(myGeneration) {
|
|
|
394
415
|
return;
|
|
395
416
|
}
|
|
396
417
|
trying = true;
|
|
397
|
-
registerAppVersion().then(function (registered) {
|
|
418
|
+
quietly('app/addversion retry', registerAppVersion().then(function (registered) {
|
|
398
419
|
trying = false;
|
|
399
420
|
if (registered) {
|
|
400
421
|
done(true);
|
|
@@ -403,8 +424,12 @@ function registerWhenOnline(myGeneration) {
|
|
|
403
424
|
warnAlways('Apptics.init: app/addversion did not return the app ids, not starting'); // no i18n
|
|
404
425
|
done(false);
|
|
405
426
|
}
|
|
406
|
-
})
|
|
427
|
+
}, function (err) {
|
|
428
|
+
trying = false;
|
|
429
|
+
throw err;
|
|
430
|
+
}));
|
|
407
431
|
}
|
|
432
|
+
var attempt = shield('app/addversion retry', tryRegister); // no i18n
|
|
408
433
|
window.addEventListener('online', attempt); // no i18n
|
|
409
434
|
timer = setInterval(attempt, OFFLINE_RETRY_MS);
|
|
410
435
|
});
|
|
@@ -500,7 +525,9 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
500
525
|
// answers, the settings saved by the last visit apply (restoreServerSettings, in start())
|
|
501
526
|
startServerSettingChecks();
|
|
502
527
|
if (appVersionChanged) {
|
|
503
|
-
|
|
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
|
|
504
531
|
updateDeviceWithApptics(_ZAP._device_info).then(function (result) {
|
|
505
532
|
if (isSuccess(result)) {
|
|
506
533
|
Console.log('init: appversion updated to ' + _ZAP._defaultoptions.appversion); // no i18n
|
|
@@ -518,7 +545,7 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
518
545
|
return false;
|
|
519
546
|
}
|
|
520
547
|
startTimers();
|
|
521
|
-
sendStoredLogs();
|
|
548
|
+
quietly('sending stored logs', sendStoredLogs()); // no i18n
|
|
522
549
|
_ZAP._ready = true;
|
|
523
550
|
// replay calls made while storage was loading, in order
|
|
524
551
|
var pending = _ZAP._pending;
|
|
@@ -536,8 +563,11 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
536
563
|
enableScreenTracking(_ZAP._config.track_screen);
|
|
537
564
|
// a no-op unless the remote-config entry was imported, which sets the hook
|
|
538
565
|
hooks.remoteConfigStarted();
|
|
566
|
+
// the same for push notification: a no-op unless its entry was imported
|
|
567
|
+
hooks.pushStarted();
|
|
539
568
|
window.appticsReadyStatus = true;
|
|
540
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
|
|
541
571
|
window.appticsReady();
|
|
542
572
|
}
|
|
543
573
|
return true;
|
|
@@ -556,7 +586,10 @@ function reset() {
|
|
|
556
586
|
hooks.trackHeatmap(false);
|
|
557
587
|
hooks.resetHeatmap();
|
|
558
588
|
hooks.resetRemoteConfig();
|
|
559
|
-
|
|
589
|
+
hooks.resetPush();
|
|
590
|
+
_ZAP._pushEnabled = false;
|
|
591
|
+
_ZAP._wmsConfig = null;
|
|
592
|
+
quietly('clearing storage', clearStorage()); // no i18n
|
|
560
593
|
_ZAP._initialised = false;
|
|
561
594
|
_ZAP._ready = false;
|
|
562
595
|
_ZAP._pending = [];
|
|
@@ -654,33 +687,33 @@ function onDocumentClick(event) {
|
|
|
654
687
|
function onPageHidden() {
|
|
655
688
|
if (!isActive())
|
|
656
689
|
return;
|
|
657
|
-
// the moment the user left: the session ends at it if they are not back within
|
|
658
|
-
markTabInactive(sendEndedSession);
|
|
659
|
-
updateScreenWithEndtime();
|
|
660
|
-
flush(true);
|
|
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
|
|
661
694
|
Console.log('page hidden: closing the open screen and flushing'); // no i18n
|
|
662
695
|
}
|
|
663
696
|
/** A session that inactivity ended while the tab was away: sent now, not when the user returns. */
|
|
664
|
-
|
|
697
|
+
const sendEndedSession = shield('sending the ended session', function () {
|
|
665
698
|
if (!isActive())
|
|
666
699
|
return;
|
|
667
|
-
flush();
|
|
668
|
-
}
|
|
700
|
+
quietly('sending the ended session', flush()); // no i18n
|
|
701
|
+
});
|
|
669
702
|
/**
|
|
670
703
|
* The tab is closing, or the page is being replaced or frozen into the back/forward cache.
|
|
671
704
|
* The session ends here, and everything queued goes out by keepalive, since a normal
|
|
672
705
|
* request would be cancelled with the page.
|
|
673
706
|
*/
|
|
674
|
-
|
|
707
|
+
const onPageClosing = shield('page closing', function () {
|
|
675
708
|
if (!isActive())
|
|
676
709
|
return;
|
|
677
710
|
Console.log('page closing: ending the session and sending what is queued'); // no i18n
|
|
678
|
-
updateScreenWithEndtime();
|
|
679
|
-
forgetStoredLogs();
|
|
680
|
-
endCurrentSession().then(function () {
|
|
711
|
+
quietly('page closing', updateScreenWithEndtime()); // no i18n
|
|
712
|
+
quietly('page closing', forgetStoredLogs()); // no i18n
|
|
713
|
+
quietly('page closing', endCurrentSession().then(function () {
|
|
681
714
|
return flush(true);
|
|
682
|
-
});
|
|
683
|
-
}
|
|
715
|
+
}));
|
|
716
|
+
});
|
|
684
717
|
function attachListeners() {
|
|
685
718
|
if (listenersAttached) {
|
|
686
719
|
return;
|
|
@@ -689,42 +722,42 @@ function attachListeners() {
|
|
|
689
722
|
// listen for connection change events (only available in w3c implementation)
|
|
690
723
|
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
691
724
|
if (connection && connection.addEventListener) {
|
|
692
|
-
connection.addEventListener('change', function () {
|
|
725
|
+
connection.addEventListener('change', shield('connection change', function () {
|
|
693
726
|
_ZAP._device_info.connectionType = getConnectionType();
|
|
694
|
-
});
|
|
727
|
+
}));
|
|
695
728
|
}
|
|
696
729
|
// Track when the window loses focus (user switches to another window or application)
|
|
697
|
-
window.addEventListener('blur', function () {
|
|
730
|
+
window.addEventListener('blur', shield('window blur', function () {
|
|
698
731
|
if (!isActive())
|
|
699
732
|
return;
|
|
700
733
|
// focus moving into an iframe on the page blurs the window too, and the user is still here
|
|
701
734
|
if (document.activeElement && document.activeElement.tagName === 'IFRAME')
|
|
702
735
|
return; // no i18n
|
|
703
736
|
Console.log('Window lost focus, user switched to another window or application'); // no i18n
|
|
704
|
-
markTabInactive(sendEndedSession);
|
|
705
|
-
});
|
|
737
|
+
quietly('window blur', markTabInactive(sendEndedSession)); // no i18n
|
|
738
|
+
}));
|
|
706
739
|
// Track when the window gains focus (user switches back to the window)
|
|
707
|
-
window.addEventListener('focus', function () {
|
|
740
|
+
window.addEventListener('focus', shield('window focus', function () {
|
|
708
741
|
if (!isActive())
|
|
709
742
|
return;
|
|
710
743
|
Console.log('Window regained focus, user switched back to the window'); // no i18n
|
|
711
744
|
markTabActive();
|
|
712
|
-
checkAndUpdateSession();
|
|
745
|
+
quietly('window focus', checkAndUpdateSession()); // no i18n
|
|
713
746
|
startTimers();
|
|
714
|
-
});
|
|
747
|
+
}));
|
|
715
748
|
// IndexedDB writes are async, so unload work starts on pagehide rather than beforeunload
|
|
716
749
|
window.addEventListener('pagehide', onPageClosing); // no i18n
|
|
717
750
|
// back/forward cache: pagehide ended the session, so coming back starts a new one
|
|
718
|
-
window.addEventListener('pageshow', function (event) {
|
|
751
|
+
window.addEventListener('pageshow', shield('page show', function (event) {
|
|
719
752
|
if (!isActive() || !event.persisted)
|
|
720
753
|
return;
|
|
721
754
|
Console.log('restored from the back/forward cache: starting a new session'); // no i18n
|
|
722
755
|
markTabActive();
|
|
723
756
|
// the screen the page was left on starts a new view, in the new session
|
|
724
|
-
checkAndUpdateSession().then(resumeScreen);
|
|
757
|
+
quietly('page show', checkAndUpdateSession().then(resumeScreen)); // no i18n
|
|
725
758
|
startTimers();
|
|
726
|
-
});
|
|
727
|
-
document.addEventListener('visibilitychange', function () {
|
|
759
|
+
}));
|
|
760
|
+
document.addEventListener('visibilitychange', shield('visibility change', function () {
|
|
728
761
|
if (!isActive())
|
|
729
762
|
return;
|
|
730
763
|
if (document.visibilityState === 'hidden') { // no i18n
|
|
@@ -736,15 +769,15 @@ function attachListeners() {
|
|
|
736
769
|
markTabActive();
|
|
737
770
|
// hiding ended the screen view; the screen the user is back on starts a new one, after the
|
|
738
771
|
// session is settled so the view belongs to the right one
|
|
739
|
-
checkAndUpdateSession().then(resumeScreen);
|
|
740
|
-
});
|
|
772
|
+
quietly('visibility change', checkAndUpdateSession().then(resumeScreen)); // no i18n
|
|
773
|
+
}));
|
|
741
774
|
// if we are running in cordova use ondeviceready otherwise onload
|
|
742
|
-
window.addEventListener(window.cordova ? 'deviceready' : 'load', function () {
|
|
775
|
+
window.addEventListener(window.cordova ? 'deviceready' : 'load', shield('page load', function () {
|
|
743
776
|
if (isActive())
|
|
744
|
-
checkAndUpdateSession();
|
|
745
|
-
}, { passive: true });
|
|
777
|
+
quietly('page load', checkAndUpdateSession()); // no i18n
|
|
778
|
+
}), { passive: true });
|
|
746
779
|
// Always send pending requests when the connection comes back online
|
|
747
|
-
window.addEventListener('online', function () {
|
|
780
|
+
window.addEventListener('online', shield('back online', function () {
|
|
748
781
|
if (!isActive())
|
|
749
782
|
return;
|
|
750
783
|
// a first visit that started offline has no device ids yet, and nothing can be sent
|
|
@@ -752,44 +785,58 @@ function attachListeners() {
|
|
|
752
785
|
if (needsDevice()) {
|
|
753
786
|
Console.log('back online: registering this device before sending'); // no i18n
|
|
754
787
|
// the same locked path as start-up, so two tabs coming back online register it once
|
|
755
|
-
prepareDevice().then(deviceReady).then(function () {
|
|
788
|
+
quietly('back online', prepareDevice().then(deviceReady).then(function () {
|
|
756
789
|
if (!isActive())
|
|
757
790
|
return;
|
|
758
|
-
flush();
|
|
791
|
+
quietly('back online', flush()); // no i18n
|
|
759
792
|
// the lines logged while offline are waiting too, and log/add needs the same ids
|
|
760
|
-
sendStoredLogs();
|
|
761
|
-
});
|
|
793
|
+
quietly('back online', sendStoredLogs()); // no i18n
|
|
794
|
+
}));
|
|
762
795
|
return;
|
|
763
796
|
}
|
|
764
|
-
flush();
|
|
765
|
-
sendStoredLogs();
|
|
766
|
-
}, { passive: true });
|
|
797
|
+
quietly('back online', flush()); // no i18n
|
|
798
|
+
quietly('back online', sendStoredLogs()); // no i18n
|
|
799
|
+
}), { passive: true });
|
|
767
800
|
if (window.screen && window.screen.orientation && typeof window.screen.orientation.addEventListener === 'function') { // no i18n
|
|
768
|
-
window.screen.orientation.addEventListener('change', function () {
|
|
801
|
+
window.screen.orientation.addEventListener('change', shield('orientation change', function () {
|
|
769
802
|
_ZAP._properties.orientation = getOrientation();
|
|
770
|
-
});
|
|
803
|
+
}));
|
|
771
804
|
}
|
|
772
|
-
window.addEventListener('unhandledrejection', function (event) {
|
|
773
|
-
if (isActive()
|
|
774
|
-
|
|
805
|
+
window.addEventListener('unhandledrejection', shield('error tracking', function (event) {
|
|
806
|
+
if (!isActive() || !_ZAP._config.track_error) {
|
|
807
|
+
return;
|
|
775
808
|
}
|
|
776
|
-
|
|
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
|
+
}));
|
|
777
815
|
// in the capture phase: a <script>, <img> or <link> that fails to load fires `error` on the
|
|
778
816
|
// element, and it does not bubble, so a bubbling listener never hears of it. One listener
|
|
779
817
|
// hears both kinds, the window's own errors included, so none is counted twice
|
|
780
|
-
window.addEventListener('error', function (event) {
|
|
818
|
+
window.addEventListener('error', shield('error tracking', function (event) {
|
|
781
819
|
if (!isActive() || !_ZAP._config.track_error) {
|
|
782
820
|
return;
|
|
783
821
|
}
|
|
784
822
|
var target = event.target;
|
|
785
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
|
+
}
|
|
786
829
|
// named by describeTarget: Event "error" on <script src="...">
|
|
787
830
|
trackError({ type: 'error', reason: event }); // no i18n
|
|
788
831
|
return;
|
|
789
832
|
}
|
|
833
|
+
// thrown by the SDK's <script> file or the Quartz recorder it loaded
|
|
834
|
+
if (isSdkScript(event.filename)) {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
790
837
|
trackError(event);
|
|
791
|
-
}, true);
|
|
792
|
-
window.addEventListener('click', onDocumentClick, true); // no i18n
|
|
838
|
+
}), true);
|
|
839
|
+
window.addEventListener('click', shield('click tracking', onDocumentClick), true); // no i18n
|
|
793
840
|
}
|
|
794
841
|
|
|
795
842
|
export { init, ready, reset, screenRouteRules, setClickTracking, setScreenTracking };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { WebNotification } from './payload.js';
|
|
2
|
+
/**
|
|
3
|
+
* How a push notification is shown, for the page and the service worker alike: the title, the
|
|
4
|
+
* options for showNotification(), and what the notification carries in its data so the worker
|
|
5
|
+
* can step a carousel and open a button's URL after the tab has closed.
|
|
6
|
+
*/
|
|
7
|
+
/** What a shown notification carries in its data. `apptics: 1` marks it as the SDK's. */
|
|
8
|
+
export interface ShownNotification {
|
|
9
|
+
apptics: 1;
|
|
10
|
+
view: WebNotification;
|
|
11
|
+
/** The carousel slide on show. */
|
|
12
|
+
index: number;
|
|
13
|
+
tag: string;
|
|
14
|
+
/** The message's data as it arrived, for the app's click callback. */
|
|
15
|
+
message: Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Which run of the message this is: the envelope's timestamp, the server's send time. A
|
|
18
|
+
* recurring push sends the same appticsPnID every run, and without a notificationNumber this is
|
|
19
|
+
* what tells the runs' stats apart. Never sent.
|
|
20
|
+
*/
|
|
21
|
+
run?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Notification options with the parts some DOM typings leave out. */
|
|
24
|
+
export type ShowOptions = NotificationOptions & {
|
|
25
|
+
actions?: Array<{
|
|
26
|
+
action: string;
|
|
27
|
+
title: string;
|
|
28
|
+
icon?: string;
|
|
29
|
+
}>;
|
|
30
|
+
image?: string;
|
|
31
|
+
renotify?: boolean;
|
|
32
|
+
data?: ShownNotification;
|
|
33
|
+
};
|
|
34
|
+
/** What the service worker posts to the site's tabs. */
|
|
35
|
+
export declare const CLICK_MESSAGE = "apptics-notification-click";
|
|
36
|
+
export declare const CLOSE_MESSAGE = "apptics-notification-close";
|
|
37
|
+
/** Prev / Next pressed: the page stops that notification's auto-scroll, as the visitor took over. */
|
|
38
|
+
export declare const STEP_MESSAGE = "apptics-notification-step";
|
|
39
|
+
/** The worker gives back the timers it could not finish in its time: an open tab runs the rest. */
|
|
40
|
+
export declare const HANDOFF_MESSAGE = "apptics-notification-handoff";
|
|
41
|
+
/** What a tab posts to the service worker: run this notification's timers; stop them (one tag, or all). */
|
|
42
|
+
export declare const TIMERS_MESSAGE = "apptics-notification-timers";
|
|
43
|
+
export declare const STOP_TIMERS_MESSAGE = "apptics-notification-stop";
|
|
44
|
+
/** The worker's answer to TIMERS_MESSAGE, on the port it came with: it runs them. */
|
|
45
|
+
export declare const TIMERS_TAKEN = "apptics-notification-timers-taken";
|
|
46
|
+
export declare const ACTION_PREV = "apptics-prev";
|
|
47
|
+
export declare const ACTION_NEXT = "apptics-next";
|
|
48
|
+
export declare const ACTION_BUTTON = "apptics-btn-";
|
|
49
|
+
export declare function isCarousel(view: WebNotification): boolean;
|
|
50
|
+
/** The title shown for slide `index`: the slide number is added for a carousel. */
|
|
51
|
+
export declare function titleFor(view: WebNotification, index: number): string;
|
|
52
|
+
/**
|
|
53
|
+
* The options for showing `shown` at its slide. `update` is a re-show of one already on screen
|
|
54
|
+
* (a carousel step, a countdown tick): it makes no sound.
|
|
55
|
+
*/
|
|
56
|
+
export declare function optionsFor(shown: ShownNotification, update: boolean, nowMs: number): ShowOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Whether this browser shows a notification's large image. Notification.prototype has `image`
|
|
59
|
+
* where it does; Chrome on macOS has none. Asked the same way in the page and the worker.
|
|
60
|
+
*/
|
|
61
|
+
export declare function supportsImage(): boolean;
|
|
62
|
+
/** Whether a notification's data is one the SDK showed. */
|
|
63
|
+
export declare function isOurs(data: unknown): data is ShownNotification;
|
|
64
|
+
/** The slide after `index` by `step` (+1 / -1), wrapping. */
|
|
65
|
+
export declare function stepIndex(view: WebNotification, index: number, step: number): number;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
|
+
import { formatCountdown } from './payload.js';
|
|
3
|
+
|
|
4
|
+
/** What the service worker posts to the site's tabs. */
|
|
5
|
+
const CLICK_MESSAGE = 'apptics-notification-click'; // no i18n
|
|
6
|
+
const CLOSE_MESSAGE = 'apptics-notification-close'; // no i18n
|
|
7
|
+
/** Prev / Next pressed: the page stops that notification's auto-scroll, as the visitor took over. */
|
|
8
|
+
const STEP_MESSAGE = 'apptics-notification-step'; // no i18n
|
|
9
|
+
/** The worker gives back the timers it could not finish in its time: an open tab runs the rest. */
|
|
10
|
+
const HANDOFF_MESSAGE = 'apptics-notification-handoff'; // no i18n
|
|
11
|
+
/** What a tab posts to the service worker: run this notification's timers; stop them (one tag, or all). */
|
|
12
|
+
const TIMERS_MESSAGE = 'apptics-notification-timers'; // no i18n
|
|
13
|
+
const STOP_TIMERS_MESSAGE = 'apptics-notification-stop'; // no i18n
|
|
14
|
+
/** The worker's answer to TIMERS_MESSAGE, on the port it came with: it runs them. */
|
|
15
|
+
const TIMERS_TAKEN = 'apptics-notification-timers-taken'; // no i18n
|
|
16
|
+
const ACTION_PREV = 'apptics-prev'; // no i18n
|
|
17
|
+
const ACTION_NEXT = 'apptics-next'; // no i18n
|
|
18
|
+
const ACTION_BUTTON = 'apptics-btn-'; // no i18n
|
|
19
|
+
/** The browser's labels for the carousel's two buttons, as the console's preview shows them. */
|
|
20
|
+
const PREV_LABEL = 'Prev'; // no i18n
|
|
21
|
+
const NEXT_LABEL = 'Next'; // no i18n
|
|
22
|
+
function isCarousel(view) {
|
|
23
|
+
return view.images.length > 1;
|
|
24
|
+
}
|
|
25
|
+
/** The title shown for slide `index`: the slide number is added for a carousel. */
|
|
26
|
+
function titleFor(view, index) {
|
|
27
|
+
return isCarousel(view) ? view.title + ' (' + (index + 1) + ' / ' + view.images.length + ')' : view.title; // no i18n
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The options for showing `shown` at its slide. `update` is a re-show of one already on screen
|
|
31
|
+
* (a carousel step, a countdown tick): it makes no sound.
|
|
32
|
+
*/
|
|
33
|
+
function optionsFor(shown, update, nowMs) {
|
|
34
|
+
var view = shown.view;
|
|
35
|
+
var body = view.text;
|
|
36
|
+
if (view.countdownTo > 0) {
|
|
37
|
+
body += (body ? '\n' : '') + formatCountdown(view.countdownTo, nowMs); // no i18n
|
|
38
|
+
}
|
|
39
|
+
var options = {
|
|
40
|
+
body: body,
|
|
41
|
+
tag: shown.tag,
|
|
42
|
+
requireInteraction: view.requireInteraction,
|
|
43
|
+
silent: view.silent || update,
|
|
44
|
+
// a new message alerts even when it replaces one still on screen under the same tag (the
|
|
45
|
+
// same appticsPnID); the SDK's own updates (a slide, a countdown tick) replace it quietly
|
|
46
|
+
renotify: !update,
|
|
47
|
+
data: shown,
|
|
48
|
+
};
|
|
49
|
+
var image = view.images[shown.index] || view.images[0];
|
|
50
|
+
if (image && !supportsImage()) {
|
|
51
|
+
// no large image here (Chrome on macOS goes through the system's notifications, which have
|
|
52
|
+
// no slot for one): the slide shows as the icon, so a carousel still visibly changes
|
|
53
|
+
options.icon = image;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (view.icon) {
|
|
57
|
+
options.icon = view.icon;
|
|
58
|
+
}
|
|
59
|
+
if (image) {
|
|
60
|
+
options.image = image;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (isCarousel(view)) {
|
|
64
|
+
options.actions = [{ action: ACTION_PREV, title: PREV_LABEL }, { action: ACTION_NEXT, title: NEXT_LABEL }];
|
|
65
|
+
}
|
|
66
|
+
else if (view.buttons.length > 0) {
|
|
67
|
+
options.actions = view.buttons.map(function (b, i) {
|
|
68
|
+
var action = { action: ACTION_BUTTON + i, title: b.label };
|
|
69
|
+
if (b.icon) {
|
|
70
|
+
action.icon = b.icon;
|
|
71
|
+
}
|
|
72
|
+
return action;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return options;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether this browser shows a notification's large image. Notification.prototype has `image`
|
|
79
|
+
* where it does; Chrome on macOS has none. Asked the same way in the page and the worker.
|
|
80
|
+
*/
|
|
81
|
+
function supportsImage() {
|
|
82
|
+
var N = typeof Notification !== 'undefined' ? Notification : undefined; // no i18n
|
|
83
|
+
return !N || !N.prototype || 'image' in N.prototype; // no i18n
|
|
84
|
+
}
|
|
85
|
+
/** Whether a notification's data is one the SDK showed. */
|
|
86
|
+
function isOurs(data) {
|
|
87
|
+
return !!data && typeof data === 'object' && data.apptics === 1; // no i18n
|
|
88
|
+
}
|
|
89
|
+
/** The slide after `index` by `step` (+1 / -1), wrapping. */
|
|
90
|
+
function stepIndex(view, index, step) {
|
|
91
|
+
var n = view.images.length;
|
|
92
|
+
return n > 0 ? ((index + step) % n + n) % n : 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { ACTION_BUTTON, ACTION_NEXT, ACTION_PREV, CLICK_MESSAGE, CLOSE_MESSAGE, HANDOFF_MESSAGE, STEP_MESSAGE, STOP_TIMERS_MESSAGE, TIMERS_MESSAGE, TIMERS_TAKEN, isCarousel, isOurs, optionsFor, stepIndex, supportsImage, titleFor };
|