@zoho_apptics/apptics-js-sdk 2.0.0-beta.1 → 2.0.0-beta.2
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 +80 -16
- package/README.md +187 -100
- 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/lifecycle-C6m1W7jo.min.js +3 -0
- package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +1 -0
- package/dist/chunks/send-CgUO82ne.min.js +3 -0
- package/dist/chunks/send-CgUO82ne.min.js.map +1 -0
- package/dist/cjs/core/attempts.js +1 -1
- package/dist/cjs/core/batch.js +1 -2
- package/dist/cjs/core/consent.d.ts +13 -3
- package/dist/cjs/core/consent.js +24 -10
- package/dist/cjs/core/constants.d.ts +22 -17
- package/dist/cjs/core/constants.js +22 -19
- package/dist/cjs/core/db.js +1 -1
- package/dist/cjs/core/debug.js +1 -1
- 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 +1 -1
- package/dist/cjs/core/hooks.d.ts +5 -0
- package/dist/cjs/core/hooks.js +2 -1
- package/dist/cjs/core/locks.js +1 -1
- package/dist/cjs/core/logger.js +1 -1
- package/dist/cjs/core/state.d.ts +6 -4
- package/dist/cjs/core/state.js +2 -4
- package/dist/cjs/core/storage.js +1 -4
- package/dist/cjs/core/stylesheet.js +1 -1
- package/dist/cjs/core/transport.js +13 -16
- package/dist/cjs/core/utils.js +1 -1
- package/dist/cjs/core/validate.js +1 -1
- 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 +195 -27
- package/dist/cjs/engagement/api-rules.js +1 -1
- package/dist/cjs/engagement/auto-api.js +1 -1
- package/dist/cjs/engagement/auto-screen.js +1 -1
- package/dist/cjs/engagement/defined-events.js +1 -1
- package/dist/cjs/engagement/send.js +7 -3
- package/dist/cjs/engagement/session.d.ts +17 -0
- package/dist/cjs/engagement/session.js +95 -4
- package/dist/cjs/engagement/track.d.ts +4 -4
- package/dist/cjs/engagement/track.js +15 -12
- package/dist/cjs/errors/send.js +2 -2
- package/dist/cjs/errors/track.d.ts +2 -1
- package/dist/cjs/errors/track.js +6 -4
- package/dist/cjs/feedback/controls.d.ts +6 -0
- package/dist/cjs/feedback/controls.js +74 -25
- package/dist/cjs/feedback/index.js +1 -1
- package/dist/cjs/feedback/logs.d.ts +3 -6
- package/dist/cjs/feedback/logs.js +8 -18
- package/dist/cjs/feedback/quartz.js +1 -1
- package/dist/cjs/feedback/send.d.ts +2 -2
- package/dist/cjs/feedback/send.js +4 -27
- package/dist/cjs/feedback/styles.js +2 -2
- package/dist/cjs/feedback/template.d.ts +1 -1
- package/dist/cjs/feedback/template.js +9 -1
- package/dist/cjs/feedback/ui.d.ts +7 -0
- package/dist/cjs/feedback/ui.js +160 -25
- package/dist/cjs/heatmap/send.d.ts +2 -0
- package/dist/cjs/heatmap/send.js +3 -5
- package/dist/cjs/heatmap/track.js +1 -1
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +54 -17
- package/dist/cjs/lifecycle.d.ts +13 -2
- package/dist/cjs/lifecycle.js +122 -54
- package/dist/cjs/remoteconfig/country.js +1 -1
- package/dist/cjs/remoteconfig/custom.js +1 -1
- package/dist/cjs/remoteconfig/evaluate.js +1 -1
- package/dist/cjs/remoteconfig/fetch.d.ts +17 -10
- package/dist/cjs/remoteconfig/fetch.js +126 -31
- package/dist/cjs/remoteconfig/index.d.ts +13 -4
- package/dist/cjs/remoteconfig/index.js +36 -20
- 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 +2 -2
- package/dist/cjs/remotelogger/index.js +1 -1
- package/dist/cjs/scheduler.d.ts +3 -1
- package/dist/cjs/scheduler.js +24 -21
- package/dist/cjs/types.d.ts +61 -16
- package/dist/cjs/user/index.js +6 -2
- package/dist/esm/core/attempts.js +1 -1
- package/dist/esm/core/batch.js +1 -2
- package/dist/esm/core/consent.d.ts +13 -3
- package/dist/esm/core/consent.js +24 -11
- package/dist/esm/core/constants.d.ts +22 -17
- package/dist/esm/core/constants.js +22 -19
- package/dist/esm/core/db.js +1 -1
- package/dist/esm/core/debug.js +1 -1
- 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 +1 -1
- package/dist/esm/core/hooks.d.ts +5 -0
- package/dist/esm/core/hooks.js +2 -1
- package/dist/esm/core/locks.js +1 -1
- package/dist/esm/core/logger.js +1 -1
- package/dist/esm/core/state.d.ts +6 -4
- package/dist/esm/core/state.js +2 -4
- package/dist/esm/core/storage.js +1 -4
- package/dist/esm/core/stylesheet.js +1 -1
- package/dist/esm/core/transport.js +13 -16
- package/dist/esm/core/utils.js +1 -1
- package/dist/esm/core/validate.js +1 -1
- 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 +195 -30
- package/dist/esm/engagement/api-rules.js +1 -1
- package/dist/esm/engagement/auto-api.js +1 -1
- package/dist/esm/engagement/auto-screen.js +1 -1
- package/dist/esm/engagement/defined-events.js +1 -1
- package/dist/esm/engagement/send.js +7 -3
- package/dist/esm/engagement/session.d.ts +17 -0
- package/dist/esm/engagement/session.js +93 -5
- package/dist/esm/engagement/track.d.ts +4 -4
- package/dist/esm/engagement/track.js +16 -13
- package/dist/esm/errors/send.js +2 -2
- package/dist/esm/errors/track.d.ts +2 -1
- package/dist/esm/errors/track.js +6 -4
- package/dist/esm/feedback/controls.d.ts +6 -0
- package/dist/esm/feedback/controls.js +74 -26
- package/dist/esm/feedback/index.js +1 -1
- package/dist/esm/feedback/logs.d.ts +3 -6
- package/dist/esm/feedback/logs.js +8 -18
- package/dist/esm/feedback/quartz.js +1 -1
- package/dist/esm/feedback/send.d.ts +2 -2
- package/dist/esm/feedback/send.js +6 -29
- package/dist/esm/feedback/styles.js +2 -2
- package/dist/esm/feedback/template.d.ts +1 -1
- package/dist/esm/feedback/template.js +9 -1
- package/dist/esm/feedback/ui.d.ts +7 -0
- package/dist/esm/feedback/ui.js +161 -26
- package/dist/esm/heatmap/send.d.ts +2 -0
- package/dist/esm/heatmap/send.js +3 -5
- package/dist/esm/heatmap/track.js +1 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +57 -20
- package/dist/esm/lifecycle.d.ts +13 -2
- package/dist/esm/lifecycle.js +126 -60
- package/dist/esm/remoteconfig/country.js +1 -1
- package/dist/esm/remoteconfig/custom.js +1 -1
- package/dist/esm/remoteconfig/evaluate.js +1 -1
- package/dist/esm/remoteconfig/fetch.d.ts +17 -10
- package/dist/esm/remoteconfig/fetch.js +127 -32
- package/dist/esm/remoteconfig/index.d.ts +13 -4
- package/dist/esm/remoteconfig/index.js +36 -20
- 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 +2 -2
- package/dist/esm/remotelogger/index.js +1 -1
- package/dist/esm/scheduler.d.ts +3 -1
- package/dist/esm/scheduler.js +25 -23
- package/dist/esm/types.d.ts +61 -16
- package/dist/esm/user/index.js +7 -3
- package/dist/feedback.esm.min.js +2 -2
- package/dist/feedback.esm.min.js.map +1 -1
- 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 +3 -2
- 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
|
@@ -8,6 +8,8 @@ import type { Dict, ServerResult } from '../types.js';
|
|
|
8
8
|
*
|
|
9
9
|
* Gated on the server's own heatmap flag (getsdkconfig module 18), not on engagement: an app may
|
|
10
10
|
* want events while declining to have every click's coordinates recorded.
|
|
11
|
+
*
|
|
12
|
+
* The scheduler reaches it through hooks.sendHeatmaps, which src/index.ts sets.
|
|
11
13
|
*/
|
|
12
14
|
export declare function sendHeatmapData(forget?: boolean): Promise<void>;
|
|
13
15
|
export declare function requestToSendHeatmaps(_payload: Dict, forget?: boolean): Promise<ServerResult>;
|
package/dist/esm/heatmap/send.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (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';
|
|
@@ -7,7 +7,6 @@ import { is_apptics_disabled } from '../core/env.js';
|
|
|
7
7
|
import { shouldTrackOrSendData } from '../core/consent.js';
|
|
8
8
|
import { defer, clearDefer, withSendLock, freshItems, awaitUnlessClosing, sendBatch } from '../core/batch.js';
|
|
9
9
|
import { isPermanentRefusal } from '../core/transport.js';
|
|
10
|
-
import { hooks } from '../core/hooks.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Sends queued heatmap records to heatmap/add.
|
|
@@ -18,6 +17,8 @@ import { hooks } from '../core/hooks.js';
|
|
|
18
17
|
*
|
|
19
18
|
* Gated on the server's own heatmap flag (getsdkconfig module 18), not on engagement: an app may
|
|
20
19
|
* want events while declining to have every click's coordinates recorded.
|
|
20
|
+
*
|
|
21
|
+
* The scheduler reaches it through hooks.sendHeatmaps, which src/index.ts sets.
|
|
21
22
|
*/
|
|
22
23
|
function sendHeatmapData(forget) {
|
|
23
24
|
if (is_apptics_disabled() || !shouldTrackOrSendData() || !_ZAP._heatmapTracking) {
|
|
@@ -72,8 +73,5 @@ function requestToSendHeatmaps(_payload, forget) {
|
|
|
72
73
|
var label = 'requestToSendHeatmaps'; // no i18n
|
|
73
74
|
return sendBatch('heatmap', label, _payload, forget); // no i18n
|
|
74
75
|
}
|
|
75
|
-
// the scheduler flushes through this, so importing the heatmap entry is what puts heatmap
|
|
76
|
-
// records on the flush timer at all
|
|
77
|
-
hooks.sendHeatmaps = sendHeatmapData;
|
|
78
76
|
|
|
79
77
|
export { requestToSendHeatmaps, sendHeatmapData };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (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';
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import './heatmap/send.js';
|
|
2
1
|
import type { AppticsSdk } from './types.js';
|
|
3
2
|
export type { AppticsSdk, AppticsConfig, ErrorLike, FeedbackType, Properties, TrackingStatus, UserInfo, UserValidationResult, } from './types.js';
|
|
4
3
|
/** Android's Apptics: starting the SDK, and what applies to all of it. */
|
|
@@ -14,7 +13,7 @@ export type { ApiTrackingConfig } from './engagement/api-rules.js';
|
|
|
14
13
|
export declare const AppticsError: AppticsSdk['AppticsError'];
|
|
15
14
|
/** Android's AppticsUser: the signed-in user, and the builder for their properties. */
|
|
16
15
|
export declare const AppticsUser: AppticsSdk['AppticsUser'];
|
|
17
|
-
/** Heatmap capture: AppticsHeatmap.
|
|
16
|
+
/** Heatmap capture: AppticsHeatmap.setHeatmapTracking() starts or stops recording clicks and scrolls. */
|
|
18
17
|
export declare const AppticsHeatmap: AppticsSdk['AppticsHeatmap'];
|
|
19
18
|
/** Android's AppticsSettings: what the SDK may track for this visitor. */
|
|
20
19
|
export declare const AppticsSettings: AppticsSdk['AppticsSettings'];
|
package/dist/esm/index.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (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
|
-
import {
|
|
4
|
+
import { warnAlways } from './core/logger.js';
|
|
5
|
+
import { reset, ready, init, setClickTracking, setScreenTracking } from './lifecycle.js';
|
|
5
6
|
import { enableApiTracking } from './engagement/auto-api.js';
|
|
6
7
|
import { endTrackApiAt, outScreenAt, inScreenAt, startTrackApi, trackEvent } from './engagement/track.js';
|
|
7
8
|
import { DefinedEvents } from './engagement/defined-events.js';
|
|
8
9
|
import { nowMs, getNewUUID } from './core/utils.js';
|
|
9
10
|
import { validateScreenName } from './core/validate.js';
|
|
10
11
|
import { ApiTrackingBuilder, configureApiTracking } from './engagement/api-rules.js';
|
|
11
|
-
import {
|
|
12
|
+
import { setErrorTracking, trackError } from './errors/track.js';
|
|
12
13
|
import { UserBuilder, getUser, setUser } from './user/index.js';
|
|
13
14
|
import { getTrackingStatus, setTrackingStatus } from './core/consent.js';
|
|
14
|
-
import {
|
|
15
|
+
import { calledFlush } from './scheduler.js';
|
|
15
16
|
import { trackHeatmap } from './heatmap/track.js';
|
|
16
|
-
import './heatmap/send.js';
|
|
17
|
-
import {
|
|
17
|
+
import { sendHeatmapData } from './heatmap/send.js';
|
|
18
|
+
import { hooks } from './core/hooks.js';
|
|
18
19
|
import { disableDebug, enableDebug } from './core/debug.js';
|
|
19
20
|
|
|
21
|
+
// flush() and the flush timer send heatmap records through this hook. Set here, from a named
|
|
22
|
+
// import, rather than by heatmap/send.ts on being imported: the package's sideEffects list names
|
|
23
|
+
// only the CDN bundle, so a bundler drops a bare `import './heatmap/send.js'`, and with it every
|
|
24
|
+
// heatmap send, while capture carries on filling the queue
|
|
25
|
+
hooks.sendHeatmaps = sendHeatmapData;
|
|
20
26
|
/*
|
|
21
27
|
* Every public call below is a function of its own, with the parameter names the console shows
|
|
22
28
|
* on hover, forwarding to its guard()ed implementation (see forward).
|
|
23
29
|
*/
|
|
24
30
|
const initGuarded = guard('Apptics.init', init); // no i18n
|
|
25
31
|
const readyGuarded = guard('Apptics.ready', ready); // no i18n
|
|
26
|
-
const flushGuarded = guard('Apptics.flush',
|
|
32
|
+
const flushGuarded = guard('Apptics.flush', calledFlush); // no i18n
|
|
27
33
|
const resetGuarded = guard('Apptics.reset', reset); // no i18n
|
|
28
34
|
/**
|
|
29
35
|
* Debug mode, on or off; works before init(), and wins over `debug` in init(). On, engagement,
|
|
@@ -33,13 +39,23 @@ const resetGuarded = guard('Apptics.reset', reset); // no i18n
|
|
|
33
39
|
*/
|
|
34
40
|
const enableDebugGuarded = guard('Apptics.enableDebug', enableDebug); // no i18n
|
|
35
41
|
const disableDebugGuarded = guard('Apptics.disableDebug', disableDebug); // no i18n
|
|
42
|
+
/** The renamed calls already warned about: once per page each, not once per call. */
|
|
43
|
+
var warnedRenamed = {};
|
|
44
|
+
/** An earlier name of a call still works, with a console warning naming the call to use. */
|
|
45
|
+
function renamed(old, current) {
|
|
46
|
+
if (warnedRenamed[old]) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
warnedRenamed[old] = true;
|
|
50
|
+
warnAlways(old + ' is now ' + current + '; rename it in your code'); // no i18n
|
|
51
|
+
}
|
|
36
52
|
/** Android's Apptics: starting the SDK, and what applies to all of it. */
|
|
37
53
|
const Apptics = {
|
|
38
|
-
/** Starts the SDK
|
|
54
|
+
/** Starts the SDK with the app's config object, which is required. */
|
|
39
55
|
init: function init(config) { return forward(initGuarded, arguments); },
|
|
40
56
|
/** Resolves true once the SDK is running, false if it can't start. */
|
|
41
57
|
ready: function ready() { return forward(readyGuarded, arguments); },
|
|
42
|
-
/** Sends stored engagements, errors and heatmap records now. */
|
|
58
|
+
/** Sends stored engagements, errors and heatmap records now; at most once every 15 seconds. */
|
|
43
59
|
flush: function flush() { return forward(flushGuarded, arguments); },
|
|
44
60
|
/** Clears stored identity, queued data and remote config values, then starts again. */
|
|
45
61
|
reset: function reset() { return forward(resetGuarded, arguments); },
|
|
@@ -47,19 +63,23 @@ const Apptics = {
|
|
|
47
63
|
disableDebug: function disableDebug() { return forward(disableDebugGuarded, arguments); },
|
|
48
64
|
};
|
|
49
65
|
/**
|
|
50
|
-
* Android's AppticsEvents: `addEvent(name, group
|
|
66
|
+
* Android's AppticsEvents: `addEvent(name, group, properties?)`, or
|
|
51
67
|
* `addEvent(AppticsEvent.DefinedEvents.X, properties?)`.
|
|
52
68
|
*/
|
|
53
69
|
const addEventGuarded = guard('AppticsEvent.addEvent', trackEvent); // no i18n
|
|
70
|
+
const setClickTrackingGuarded = guard('AppticsEvent.setClickTracking', setClickTracking); // no i18n
|
|
54
71
|
const AppticsEvent = {
|
|
55
72
|
/** Apptics' defined events, as Android's DefinedEvents, to log with addEvent. */
|
|
56
73
|
DefinedEvents: DefinedEvents,
|
|
57
74
|
addEvent: function addEvent(eventName, groupName, properties) {
|
|
58
75
|
return forward(addEventGuarded, arguments);
|
|
59
76
|
},
|
|
77
|
+
/** Turns click tracking from markup (apeventaction) on or off; the `track_click` config flag sets it at start-up. */
|
|
78
|
+
setClickTracking: function setClickTracking(enabled) { return forward(setClickTrackingGuarded, arguments); },
|
|
60
79
|
};
|
|
61
80
|
const inScreenGuarded = guard('AppticsScreen.inScreen', inScreenAt); // no i18n
|
|
62
81
|
const outScreenGuarded = guard('AppticsScreen.outScreen', outScreenAt); // no i18n
|
|
82
|
+
const setScreenTrackingGuarded = guard('AppticsScreen.setScreenTracking', setScreenTracking); // no i18n
|
|
63
83
|
/** Android's AppticsScreenTracker: inScreen(name) returns the view's id, outScreen(id) ends it. */
|
|
64
84
|
const AppticsScreen = {
|
|
65
85
|
/**
|
|
@@ -81,11 +101,13 @@ const AppticsScreen = {
|
|
|
81
101
|
outScreen: function outScreen(id) {
|
|
82
102
|
outScreenGuarded(id, nowMs());
|
|
83
103
|
},
|
|
104
|
+
/** Turns automatic screen tracking on or off; the `track_screen` config flag sets it at start-up. */
|
|
105
|
+
setScreenTracking: function setScreenTracking(enabled) { return forward(setScreenTrackingGuarded, arguments); },
|
|
84
106
|
};
|
|
85
107
|
const endTrackApiGuarded = guard('AppticsApi.endTrackApi', endTrackApiAt); // no i18n
|
|
86
108
|
const startTrackApiGuarded = guard('AppticsApi.startTrackApi', startTrackApi); // no i18n
|
|
87
109
|
const configureGuarded = guard('AppticsApi.configure', configureApiTracking); // no i18n
|
|
88
|
-
const
|
|
110
|
+
const setApiTrackingGuarded = guard('AppticsApi.setApiTracking', enableApiTracking); // no i18n
|
|
89
111
|
/** Android's AppticsApiTracker: startTrackApi / endTrackApi, and configure for the rules. */
|
|
90
112
|
const AppticsApi = {
|
|
91
113
|
/** Begins timing one call: returns the id endTrackApi takes. */
|
|
@@ -99,17 +121,27 @@ const AppticsApi = {
|
|
|
99
121
|
ApiTrackingBuilder: ApiTrackingBuilder,
|
|
100
122
|
/** The rules API tracking records by, from ApiTrackingBuilder. Works before Apptics.init(). */
|
|
101
123
|
configure: function configure(config) { return forward(configureGuarded, arguments); },
|
|
102
|
-
/** Turns automatic API tracking on or off; the `track_api` config flag
|
|
103
|
-
|
|
124
|
+
/** Turns automatic API tracking on or off; the `track_api` config flag sets it at start-up. */
|
|
125
|
+
setApiTracking: function setApiTracking(enabled) { return forward(setApiTrackingGuarded, arguments); },
|
|
126
|
+
/** @deprecated the earlier name of setApiTracking, which it calls, with a warning */
|
|
127
|
+
enableApiTracking: function enableApiTracking(enabled) {
|
|
128
|
+
renamed('AppticsApi.enableApiTracking', 'AppticsApi.setApiTracking'); // no i18n
|
|
129
|
+
return forward(setApiTrackingGuarded, arguments);
|
|
130
|
+
},
|
|
104
131
|
};
|
|
105
132
|
const trackErrorGuarded = guard('AppticsError.trackError', trackError); // no i18n
|
|
106
|
-
const
|
|
133
|
+
const setErrorTrackingGuarded = guard('AppticsError.setErrorTracking', setErrorTracking); // no i18n
|
|
107
134
|
/** Errors: the ones the app caught, and the switch for the uncaught ones tracked on their own. */
|
|
108
135
|
const AppticsError = {
|
|
109
136
|
/** Reports an error the app caught, or an `error` / `unhandledrejection` event. */
|
|
110
137
|
trackError: function trackError(error, properties) { return forward(trackErrorGuarded, arguments); },
|
|
111
|
-
/** Turns the automatic tracking of uncaught errors and unhandled rejections on or off. */
|
|
112
|
-
|
|
138
|
+
/** Turns the automatic tracking of uncaught errors and unhandled rejections on or off; the `track_error` config flag sets it at start-up. */
|
|
139
|
+
setErrorTracking: function setErrorTracking(enabled) { return forward(setErrorTrackingGuarded, arguments); },
|
|
140
|
+
/** @deprecated the earlier name of setErrorTracking, which it calls, with a warning */
|
|
141
|
+
trackGlobalErrorHandler: function trackGlobalErrorHandler(enabled) {
|
|
142
|
+
renamed('AppticsError.trackGlobalErrorHandler', 'AppticsError.setErrorTracking'); // no i18n
|
|
143
|
+
return forward(setErrorTrackingGuarded, arguments);
|
|
144
|
+
},
|
|
113
145
|
};
|
|
114
146
|
const setUserGuarded = guard('AppticsUser.setUser', setUser); // no i18n
|
|
115
147
|
const getUserGuarded = guard('AppticsUser.getUser', getUser); // no i18n
|
|
@@ -121,10 +153,16 @@ const AppticsUser = {
|
|
|
121
153
|
getUser: function getUser() { return forward(getUserGuarded, arguments); },
|
|
122
154
|
UserBuilder: UserBuilder,
|
|
123
155
|
};
|
|
124
|
-
const
|
|
125
|
-
/** Heatmap capture: AppticsHeatmap.
|
|
156
|
+
const setHeatmapTrackingGuarded = guard('AppticsHeatmap.setHeatmapTracking', trackHeatmap); // no i18n
|
|
157
|
+
/** Heatmap capture: AppticsHeatmap.setHeatmapTracking() starts or stops recording clicks and scrolls. */
|
|
126
158
|
const AppticsHeatmap = {
|
|
127
|
-
|
|
159
|
+
/** Starts or stops recording clicks and scrolls; the `track_heatmap` config flag sets it at start-up. */
|
|
160
|
+
setHeatmapTracking: function setHeatmapTracking(enabled) { return forward(setHeatmapTrackingGuarded, arguments); },
|
|
161
|
+
/** @deprecated the earlier name of setHeatmapTracking, which it calls, with a warning */
|
|
162
|
+
trackHeatmap: function trackHeatmap(on) {
|
|
163
|
+
renamed('AppticsHeatmap.trackHeatmap', 'AppticsHeatmap.setHeatmapTracking'); // no i18n
|
|
164
|
+
return forward(setHeatmapTrackingGuarded, arguments);
|
|
165
|
+
},
|
|
128
166
|
};
|
|
129
167
|
const setTrackingStatusGuarded = guard('AppticsSettings.setTrackingStatus', setTrackingStatus); // no i18n
|
|
130
168
|
const getTrackingStatusGuarded = guard('AppticsSettings.getTrackingStatus', getTrackingStatus); // no i18n
|
|
@@ -145,6 +183,5 @@ const apptics = {
|
|
|
145
183
|
AppticsSettings,
|
|
146
184
|
AppticsHeatmap,
|
|
147
185
|
};
|
|
148
|
-
scheduleAutoInit(Apptics);
|
|
149
186
|
|
|
150
187
|
export { Apptics, AppticsApi, AppticsError, AppticsEvent, AppticsHeatmap, AppticsScreen, AppticsSettings, AppticsUser, apptics as default };
|
package/dist/esm/lifecycle.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type ScreenRouteRule } from './core/constants.js';
|
|
2
2
|
import type { AppticsConfig } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Starts the SDK. The config object is required:
|
|
5
|
-
* supply it (auto-init reads window.appticssettings._defaultoptions and calls init with it).
|
|
4
|
+
* Starts the SDK. The config object is required: the SDK starts only when the app calls this.
|
|
6
5
|
* Returns true when the config has base_url, auth_key, app_domain and appversion and start-up has
|
|
7
6
|
* begun (see ready()), false when it was already running, the config is missing or incomplete, or
|
|
8
7
|
* there is no browser. Start-up calls app/addversion with those four, which answers with aaid, the
|
|
@@ -19,3 +18,15 @@ export declare function screenRouteRules(routes: unknown): ScreenRouteRule[];
|
|
|
19
18
|
export declare function ready(): Promise<boolean>;
|
|
20
19
|
/** Clears stored identity and queues, then starts again from the snippet. */
|
|
21
20
|
export declare function reset(): void;
|
|
21
|
+
/**
|
|
22
|
+
* AppticsEvent.setClickTracking: click tracking from markup on or off, as the `track_click`
|
|
23
|
+
* config sets it. The listener stays; it checks the switch on every click.
|
|
24
|
+
*/
|
|
25
|
+
export declare function setClickTracking(enabled?: boolean): void;
|
|
26
|
+
/**
|
|
27
|
+
* AppticsScreen.setScreenTracking: automatic screen tracking on or off, as the `track_screen`
|
|
28
|
+
* config sets it. Applied now once the SDK is running; before that it is only noted, and start()
|
|
29
|
+
* switches tracking to it. Like the other switches, the next init() (a reset() too) goes back to
|
|
30
|
+
* what its config says.
|
|
31
|
+
*/
|
|
32
|
+
export declare function setScreenTracking(enabled?: boolean): void;
|
package/dist/esm/lifecycle.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { REQUIRED_CONFIG, CONFIG_KEYS, AP_CONFIG, RETIRED_CONFIG_NAMES, DEFAULT_INACTIVE_MINUTES } from './core/constants.js';
|
|
3
3
|
import { _ZAP } from './core/state.js';
|
|
4
4
|
import { Console, warnAlways } from './core/logger.js';
|
|
5
5
|
import { isEmpty, isSuccess } from './core/utils.js';
|
|
6
|
-
import { storageReady, user_defaults, engagement_transactions, error_transactions, tracking_preference } from './core/storage.js';
|
|
6
|
+
import { storageReady, user_defaults, engagement_transactions, error_transactions, heatmap_transactions, remotelog_transactions, feedbacklog_transactions, tracking_preference } from './core/storage.js';
|
|
7
7
|
import { hooks } from './core/hooks.js';
|
|
8
8
|
import { applyDebugConfig } from './core/debug.js';
|
|
9
9
|
import { getConnectionType, getOrientation } from './core/env.js';
|
|
10
|
-
import { restoreServerSettings, prepareDevice,
|
|
11
|
-
import { clearAppVersion, registerAppVersion, appVersionFailedForNetwork } from './device/appversion.js';
|
|
12
|
-
import { holdTabLock, checkAndUpdateSession,
|
|
10
|
+
import { restoreServerSettings, prepareDevice, startServerSettingChecks, updateDeviceWithApptics, needsDevice, deviceReady } from './device/index.js';
|
|
11
|
+
import { clearAppVersion, keyFingerprint, registerAppVersion, appVersionFailedForNetwork } from './device/appversion.js';
|
|
12
|
+
import { holdTabLock, checkAndUpdateSession, markTabInactive, markTabActive, updateScreenWithEndtime, endCurrentSession, resetInactivity } from './engagement/session.js';
|
|
13
13
|
import { enableApiTracking } from './engagement/auto-api.js';
|
|
14
|
-
import {
|
|
14
|
+
import { enableScreenTracking, routePath } from './engagement/auto-screen.js';
|
|
15
15
|
import { resumeScreen, trackEvent } from './engagement/track.js';
|
|
16
16
|
import { trackError } from './errors/track.js';
|
|
17
17
|
import { startTimers, flush, stopTimers } from './scheduler.js';
|
|
@@ -114,10 +114,15 @@ var previousAppVersion = ''; // no i18n
|
|
|
114
114
|
/**
|
|
115
115
|
* Data stored for another app on this origin is discarded before anything else reads it,
|
|
116
116
|
* including the stored app/addversion answer that would otherwise hand out that app's ids.
|
|
117
|
+
*
|
|
118
|
+
* Another app is a different base_url, app_domain or auth_key from the ones the stored data was
|
|
119
|
+
* registered with. Everything goes, the queues included, and start-up runs as on a first visit:
|
|
120
|
+
* app/addversion, device/add and the rest. Resolves once the store is empty.
|
|
117
121
|
*/
|
|
118
122
|
function discardOtherAppData(settings) {
|
|
119
|
-
// which app it is, and which version, are in app_version_info (serviceUrl, identifier
|
|
120
|
-
// appversion): no keys of their own. 2.0.0-beta's appkey and
|
|
123
|
+
// which app it is, and which version, are in app_version_info (serviceUrl, identifier, a
|
|
124
|
+
// fingerprint of zak, and appversion): no keys of their own. 2.0.0-beta's appkey and
|
|
125
|
+
// appversion are read this once
|
|
121
126
|
var info = user_defaults.item('app_version_info') || {}; // no i18n
|
|
122
127
|
var stored = !isEmpty(info.serviceUrl) && !isEmpty(info.identifier)
|
|
123
128
|
? appKey(info)
|
|
@@ -125,11 +130,17 @@ function discardOtherAppData(settings) {
|
|
|
125
130
|
previousAppVersion = String((!isEmpty(info.appversion) ? info.appversion : user_defaults.item('appversion')) || ''); // no i18n
|
|
126
131
|
user_defaults.add('appkey', undefined); // no i18n
|
|
127
132
|
user_defaults.add('appversion', undefined); // no i18n
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
var otherApp = !isEmpty(stored) && stored !== appKey(settings);
|
|
134
|
+
// a build that kept no fingerprint cannot tell: hasAppVersion() registers again, and records one
|
|
135
|
+
var otherKey = !isEmpty(info.zakhash) && info.zakhash !== keyFingerprint(settings.zak);
|
|
136
|
+
if (!otherApp && !otherKey) {
|
|
137
|
+
return Promise.resolve();
|
|
138
|
+
}
|
|
139
|
+
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
|
|
140
|
+
previousAppVersion = ''; // no i18n
|
|
141
|
+
// the remote config values read from the store, which is about to go
|
|
142
|
+
hooks.resetRemoteConfig();
|
|
143
|
+
return clearStorage();
|
|
133
144
|
}
|
|
134
145
|
/**
|
|
135
146
|
* Timing an app may tune in init(). Each has a range: a value outside it is ignored with a
|
|
@@ -173,15 +184,20 @@ function applyIntervals(config) {
|
|
|
173
184
|
}
|
|
174
185
|
}
|
|
175
186
|
}
|
|
187
|
+
/** Everything the SDK stores: settings, ids and every queue. Resolves once it is all gone. */
|
|
176
188
|
function clearStorage() {
|
|
177
189
|
clearAttempts();
|
|
178
190
|
user_defaults.clear();
|
|
179
|
-
|
|
180
|
-
|
|
191
|
+
return Promise.all([
|
|
192
|
+
engagement_transactions, error_transactions, heatmap_transactions, remotelog_transactions, feedbacklog_transactions,
|
|
193
|
+
].map(function (queue) {
|
|
194
|
+
return queue.clear();
|
|
195
|
+
})).then(function () {
|
|
196
|
+
return undefined;
|
|
197
|
+
});
|
|
181
198
|
}
|
|
182
199
|
/**
|
|
183
|
-
* Starts the SDK. The config object is required:
|
|
184
|
-
* supply it (auto-init reads window.appticssettings._defaultoptions and calls init with it).
|
|
200
|
+
* Starts the SDK. The config object is required: the SDK starts only when the app calls this.
|
|
185
201
|
* Returns true when the config has base_url, auth_key, app_domain and appversion and start-up has
|
|
186
202
|
* begun (see ready()), false when it was already running, the config is missing or incomplete, or
|
|
187
203
|
* there is no browser. Start-up calls app/addversion with those four, which answers with aaid, the
|
|
@@ -279,6 +295,10 @@ function init(config) {
|
|
|
279
295
|
// screen view can be stored
|
|
280
296
|
_ZAP._config.track_screen = typeof config.track_screen === 'boolean' ? config.track_screen : AP_CONFIG.track_screen; // no i18n
|
|
281
297
|
_ZAP._config.screen_routes = screenRouteRules(config.screen_routes);
|
|
298
|
+
// uncaught errors and tagged clicks, on unless the config says false: the listeners check
|
|
299
|
+
// these as each error or click happens
|
|
300
|
+
_ZAP._config.track_error = typeof config.track_error === 'boolean' ? config.track_error : AP_CONFIG.track_error; // no i18n
|
|
301
|
+
_ZAP._config.track_click = typeof config.track_click === 'boolean' ? config.track_click : AP_CONFIG.track_click; // no i18n
|
|
282
302
|
// a theme in the config wins; without one, what AppticsFeedback.setFeedbackTheme set stays
|
|
283
303
|
if (config.feedback_theme === 'light' || config.feedback_theme === 'dark' || config.feedback_theme === 'auto') { // no i18n
|
|
284
304
|
_ZAP._config.feedback_theme = config.feedback_theme;
|
|
@@ -300,39 +320,11 @@ function init(config) {
|
|
|
300
320
|
_ZAP._pending = [];
|
|
301
321
|
return false;
|
|
302
322
|
}
|
|
303
|
-
discardOtherAppData(_ZAP._defaultoptions)
|
|
304
|
-
// app/addversion is the first call and everything waits on it: it is what turns the four
|
|
305
|
-
// values init() was given into aaid, the portal and project ids every url carries, and
|
|
306
|
-
// appreleaseversionid, which metaWebSDKV2 refuses a payload without
|
|
307
|
-
return registerAppVersion().then(function (registered) {
|
|
323
|
+
return discardOtherAppData(_ZAP._defaultoptions).then(function () {
|
|
308
324
|
if (myGeneration !== generation) {
|
|
309
325
|
return false;
|
|
310
326
|
}
|
|
311
|
-
|
|
312
|
-
// a first visit with no network: start once it is back, keeping what the app
|
|
313
|
-
// tracks until then queued, rather than giving up for the rest of the page
|
|
314
|
-
warnAlways('Apptics.init: offline, so app/addversion is tried again when the browser is back online; calls made until then are kept'); // no i18n
|
|
315
|
-
return registerWhenOnline(myGeneration).then(function (ok) {
|
|
316
|
-
if (myGeneration !== generation) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
if (!ok) {
|
|
320
|
-
_ZAP._initialised = false;
|
|
321
|
-
_ZAP._token = ''; // no i18n
|
|
322
|
-
_ZAP._pending = [];
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
return start(config, myGeneration);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
if (!registered) {
|
|
329
|
-
warnAlways('Apptics.init: app/addversion did not return the app ids, not starting'); // no i18n
|
|
330
|
-
_ZAP._initialised = false;
|
|
331
|
-
_ZAP._token = ''; // no i18n
|
|
332
|
-
_ZAP._pending = [];
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
return start(config, myGeneration);
|
|
327
|
+
return startUp(config, myGeneration);
|
|
336
328
|
});
|
|
337
329
|
}).catch(function (err) {
|
|
338
330
|
Console.error('Apptics.init: start-up failed', err); // no i18n
|
|
@@ -340,6 +332,42 @@ function init(config) {
|
|
|
340
332
|
});
|
|
341
333
|
return true;
|
|
342
334
|
}
|
|
335
|
+
/** Start-up from app/addversion on, once the store holds only this app's data. */
|
|
336
|
+
function startUp(config, myGeneration) {
|
|
337
|
+
// app/addversion is the first call and everything waits on it: it is what turns the four
|
|
338
|
+
// values init() was given into aaid, the portal and project ids every url carries, and
|
|
339
|
+
// appreleaseversionid, which metaWebSDKV2 refuses a payload without
|
|
340
|
+
return registerAppVersion().then(function (registered) {
|
|
341
|
+
if (myGeneration !== generation) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
if (!registered && appVersionFailedForNetwork()) {
|
|
345
|
+
// a first visit with no network: start once it is back, keeping what the app
|
|
346
|
+
// tracks until then queued, rather than giving up for the rest of the page
|
|
347
|
+
warnAlways('Apptics.init: offline, so app/addversion is tried again when the browser is back online; calls made until then are kept'); // no i18n
|
|
348
|
+
return registerWhenOnline(myGeneration).then(function (ok) {
|
|
349
|
+
if (myGeneration !== generation) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
if (!ok) {
|
|
353
|
+
_ZAP._initialised = false;
|
|
354
|
+
_ZAP._token = ''; // no i18n
|
|
355
|
+
_ZAP._pending = [];
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
return start(config, myGeneration);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
if (!registered) {
|
|
362
|
+
warnAlways('Apptics.init: app/addversion did not return the app ids, not starting'); // no i18n
|
|
363
|
+
_ZAP._initialised = false;
|
|
364
|
+
_ZAP._token = ''; // no i18n
|
|
365
|
+
_ZAP._pending = [];
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return start(config, myGeneration);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
343
371
|
/** How often a start-up waiting on the network tries app/addversion again, besides on `online`. */
|
|
344
372
|
const OFFLINE_RETRY_MS = 60 * 1000;
|
|
345
373
|
/**
|
|
@@ -446,6 +474,8 @@ function start(config, myGeneration) {
|
|
|
446
474
|
_ZAP._token = String(_ZAP._defaultoptions.aaid);
|
|
447
475
|
// last known server settings (getupdates) apply before anything is tracked
|
|
448
476
|
restoreServerSettings();
|
|
477
|
+
// the user this browser was tracking as, before getsdkconfig is asked: it carries their ids
|
|
478
|
+
getUserInfo();
|
|
449
479
|
// a new release of the app, against the version the stored data was for (see
|
|
450
480
|
// discardOtherAppData): a first visit has none, and is no change
|
|
451
481
|
var appVersionChanged = previousAppVersion !== '' && previousAppVersion != _ZAP._defaultoptions.appversion; // no i18n
|
|
@@ -464,9 +494,11 @@ function start(config, myGeneration) {
|
|
|
464
494
|
}
|
|
465
495
|
/** The rest of start-up, once the device is set up. */
|
|
466
496
|
function startTracking(appVersionChanged, myGeneration) {
|
|
467
|
-
//
|
|
468
|
-
// succeeded (registerDeviceWithApptics)
|
|
469
|
-
//
|
|
497
|
+
// getsdkconfig, once per page load and then at each answer's next_check_after. A first visit
|
|
498
|
+
// asked as soon as device/add succeeded (registerDeviceWithApptics) and this does nothing; a
|
|
499
|
+
// returning visit, whose device is registered, asks now, after app/addversion. Until it
|
|
500
|
+
// answers, the settings saved by the last visit apply (restoreServerSettings, in start())
|
|
501
|
+
startServerSettingChecks();
|
|
470
502
|
if (appVersionChanged) {
|
|
471
503
|
_ZAP._device_info.appversionid = ''; // no i18n
|
|
472
504
|
updateDeviceWithApptics(_ZAP._device_info).then(function (result) {
|
|
@@ -481,7 +513,6 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
481
513
|
_ZAP._device_info.connectionType = getConnectionType();
|
|
482
514
|
attachListeners();
|
|
483
515
|
_ZAP._properties.orientation = getOrientation();
|
|
484
|
-
getUserInfo();
|
|
485
516
|
return checkAndUpdateSession().then(function () {
|
|
486
517
|
if (myGeneration !== generation) {
|
|
487
518
|
return false;
|
|
@@ -516,6 +547,7 @@ function startTracking(appVersionChanged, myGeneration) {
|
|
|
516
547
|
function reset() {
|
|
517
548
|
generation++;
|
|
518
549
|
stopTimers();
|
|
550
|
+
resetInactivity();
|
|
519
551
|
// the wrappers come off with everything else; the init() below puts them back if the config
|
|
520
552
|
// asked for them, so a reset that has no config to restore leaves XHR and fetch untouched
|
|
521
553
|
enableApiTracking(false);
|
|
@@ -546,6 +578,26 @@ function reset() {
|
|
|
546
578
|
function isActive() {
|
|
547
579
|
return _ZAP._ready;
|
|
548
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* AppticsEvent.setClickTracking: click tracking from markup on or off, as the `track_click`
|
|
583
|
+
* config sets it. The listener stays; it checks the switch on every click.
|
|
584
|
+
*/
|
|
585
|
+
function setClickTracking(enabled) {
|
|
586
|
+
_ZAP._config.track_click = typeof enabled === 'boolean' ? enabled : true; // no i18n
|
|
587
|
+
Console.log('click tracking: ' + (_ZAP._config.track_click ? 'on' : 'off')); // no i18n
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* AppticsScreen.setScreenTracking: automatic screen tracking on or off, as the `track_screen`
|
|
591
|
+
* config sets it. Applied now once the SDK is running; before that it is only noted, and start()
|
|
592
|
+
* switches tracking to it. Like the other switches, the next init() (a reset() too) goes back to
|
|
593
|
+
* what its config says.
|
|
594
|
+
*/
|
|
595
|
+
function setScreenTracking(enabled) {
|
|
596
|
+
_ZAP._config.track_screen = typeof enabled === 'boolean' ? enabled : true; // no i18n
|
|
597
|
+
if (isActive()) {
|
|
598
|
+
enableScreenTracking(_ZAP._config.track_screen);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
549
601
|
/**
|
|
550
602
|
* A click-tracking attribute, in either spelling: `apeventaction`, or `data-apeventaction`, which
|
|
551
603
|
* is valid HTML and what React and TypeScript accept without declaring the attribute.
|
|
@@ -561,7 +613,7 @@ function trackingSelector(name) {
|
|
|
561
613
|
// Declarative click tracking: <el apeventaction="name" apeventprops='{"k":"v"}'> inside <el apgroupaction="group">,
|
|
562
614
|
// or the same attributes with a data- prefix
|
|
563
615
|
function onDocumentClick(event) {
|
|
564
|
-
if (!window.appticsReadyStatus || !isActive()) {
|
|
616
|
+
if (!window.appticsReadyStatus || !isActive() || !_ZAP._config.track_click) {
|
|
565
617
|
return;
|
|
566
618
|
}
|
|
567
619
|
var start = event.target;
|
|
@@ -577,7 +629,8 @@ function onDocumentClick(event) {
|
|
|
577
629
|
}
|
|
578
630
|
var eventName = trackingAttribute(targetElem, 'apeventaction') || ''; // no i18n
|
|
579
631
|
var groupElem = targetElem.closest(trackingSelector('apgroupaction')); // no i18n
|
|
580
|
-
|
|
632
|
+
// no apgroupaction around it: trackEvent refuses it and says the group is missing
|
|
633
|
+
var groupName = (groupElem && trackingAttribute(groupElem, 'apgroupaction')) || undefined; // no i18n
|
|
581
634
|
var eventProps = {};
|
|
582
635
|
var rawProps = trackingAttribute(targetElem, 'apeventprops'); // no i18n
|
|
583
636
|
if (!isEmpty(rawProps)) {
|
|
@@ -601,10 +654,18 @@ function onDocumentClick(event) {
|
|
|
601
654
|
function onPageHidden() {
|
|
602
655
|
if (!isActive())
|
|
603
656
|
return;
|
|
657
|
+
// the moment the user left: the session ends at it if they are not back within inactiveduration
|
|
658
|
+
markTabInactive(sendEndedSession);
|
|
604
659
|
updateScreenWithEndtime();
|
|
605
660
|
flush(true);
|
|
606
661
|
Console.log('page hidden: closing the open screen and flushing'); // no i18n
|
|
607
662
|
}
|
|
663
|
+
/** A session that inactivity ended while the tab was away: sent now, not when the user returns. */
|
|
664
|
+
function sendEndedSession() {
|
|
665
|
+
if (!isActive())
|
|
666
|
+
return;
|
|
667
|
+
flush();
|
|
668
|
+
}
|
|
608
669
|
/**
|
|
609
670
|
* The tab is closing, or the page is being replaced or frozen into the back/forward cache.
|
|
610
671
|
* The session ends here, and everything queued goes out by keepalive, since a normal
|
|
@@ -636,14 +697,18 @@ function attachListeners() {
|
|
|
636
697
|
window.addEventListener('blur', function () {
|
|
637
698
|
if (!isActive())
|
|
638
699
|
return;
|
|
700
|
+
// focus moving into an iframe on the page blurs the window too, and the user is still here
|
|
701
|
+
if (document.activeElement && document.activeElement.tagName === 'IFRAME')
|
|
702
|
+
return; // no i18n
|
|
639
703
|
Console.log('Window lost focus, user switched to another window or application'); // no i18n
|
|
640
|
-
|
|
704
|
+
markTabInactive(sendEndedSession);
|
|
641
705
|
});
|
|
642
706
|
// Track when the window gains focus (user switches back to the window)
|
|
643
707
|
window.addEventListener('focus', function () {
|
|
644
708
|
if (!isActive())
|
|
645
709
|
return;
|
|
646
710
|
Console.log('Window regained focus, user switched back to the window'); // no i18n
|
|
711
|
+
markTabActive();
|
|
647
712
|
checkAndUpdateSession();
|
|
648
713
|
startTimers();
|
|
649
714
|
});
|
|
@@ -654,6 +719,7 @@ function attachListeners() {
|
|
|
654
719
|
if (!isActive() || !event.persisted)
|
|
655
720
|
return;
|
|
656
721
|
Console.log('restored from the back/forward cache: starting a new session'); // no i18n
|
|
722
|
+
markTabActive();
|
|
657
723
|
// the screen the page was left on starts a new view, in the new session
|
|
658
724
|
checkAndUpdateSession().then(resumeScreen);
|
|
659
725
|
startTimers();
|
|
@@ -665,12 +731,12 @@ function attachListeners() {
|
|
|
665
731
|
onPageHidden();
|
|
666
732
|
return;
|
|
667
733
|
}
|
|
668
|
-
// back in view
|
|
669
|
-
|
|
734
|
+
// back in view. getsdkconfig is not asked here: only at its next_check_after, on a tab's
|
|
735
|
+
// first page load, and when a user is registered or getupdates reports a change
|
|
736
|
+
markTabActive();
|
|
670
737
|
// hiding ended the screen view; the screen the user is back on starts a new one, after the
|
|
671
738
|
// session is settled so the view belongs to the right one
|
|
672
739
|
checkAndUpdateSession().then(resumeScreen);
|
|
673
|
-
refreshServerSettings();
|
|
674
740
|
});
|
|
675
741
|
// if we are running in cordova use ondeviceready otherwise onload
|
|
676
742
|
window.addEventListener(window.cordova ? 'deviceready' : 'load', function () {
|
|
@@ -704,7 +770,7 @@ function attachListeners() {
|
|
|
704
770
|
});
|
|
705
771
|
}
|
|
706
772
|
window.addEventListener('unhandledrejection', function (event) {
|
|
707
|
-
if (isActive() && _ZAP.
|
|
773
|
+
if (isActive() && _ZAP._config.track_error) {
|
|
708
774
|
trackError(event);
|
|
709
775
|
}
|
|
710
776
|
});
|
|
@@ -712,7 +778,7 @@ function attachListeners() {
|
|
|
712
778
|
// element, and it does not bubble, so a bubbling listener never hears of it. One listener
|
|
713
779
|
// hears both kinds, the window's own errors included, so none is counted twice
|
|
714
780
|
window.addEventListener('error', function (event) {
|
|
715
|
-
if (!isActive() || !_ZAP.
|
|
781
|
+
if (!isActive() || !_ZAP._config.track_error) {
|
|
716
782
|
return;
|
|
717
783
|
}
|
|
718
784
|
var target = event.target;
|
|
@@ -726,4 +792,4 @@ function attachListeners() {
|
|
|
726
792
|
window.addEventListener('click', onDocumentClick, true); // no i18n
|
|
727
793
|
}
|
|
728
794
|
|
|
729
|
-
export { init, ready, reset, screenRouteRules };
|
|
795
|
+
export { init, ready, reset, screenRouteRules, setClickTracking, setScreenTracking };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { _ZAP } from '../core/state.js';
|
|
3
3
|
import { getTimeZone } from '../core/env.js';
|
|
4
4
|
import { TZ_COUNTRIES } from './tz-countries.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { storageReady } from '../core/storage.js';
|
|
3
3
|
import { Console } from '../core/logger.js';
|
|
4
4
|
import { reresolve } from './store.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0-beta.2 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { Console } from '../core/logger.js';
|
|
3
3
|
import { _ZAP } from '../core/state.js';
|
|
4
4
|
import { isEmpty } from '../core/utils.js';
|