@croct/sdk 0.17.7 → 0.17.8
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/activeRecord.cjs.map +1 -0
- package/activeRecord.d.ts +8 -4
- package/activeRecord.js +115 -106
- package/activeRecord.js.map +1 -1
- package/apiKey.cjs.map +1 -0
- package/apiKey.d.ts +4 -2
- package/apiKey.js +152 -141
- package/apiKey.js.map +1 -1
- package/base64Url.cjs.map +1 -0
- package/base64Url.d.ts +4 -2
- package/base64Url.js +8 -15
- package/base64Url.js.map +1 -1
- package/cache/cache.cjs.map +1 -0
- package/cache/cache.d.ts +6 -4
- package/cache/cache.js +9 -10
- package/cache/cache.js.map +1 -1
- package/cache/cookieCache.cjs.map +1 -0
- package/cache/cookieCache.d.ts +6 -3
- package/cache/cookieCache.js +52 -54
- package/cache/cookieCache.js.map +1 -1
- package/cache/fallbackCache.cjs.map +1 -0
- package/cache/fallbackCache.d.ts +5 -2
- package/cache/fallbackCache.js +20 -21
- package/cache/fallbackCache.js.map +1 -1
- package/cache/inMemoryCache.cjs.map +1 -0
- package/cache/inMemoryCache.d.ts +5 -2
- package/cache/inMemoryCache.js +15 -17
- package/cache/inMemoryCache.js.map +1 -1
- package/cache/index.cjs.map +1 -0
- package/cache/index.d.ts +4 -4
- package/cache/index.js +9 -11
- package/cache/index.js.map +1 -1
- package/cache/localStorageCache.cjs.map +1 -0
- package/cache/localStorageCache.d.ts +5 -2
- package/cache/localStorageCache.js +55 -63
- package/cache/localStorageCache.js.map +1 -1
- package/channel/channel.cjs.map +1 -0
- package/channel/channel.d.ts +8 -6
- package/channel/channel.js +21 -22
- package/channel/channel.js.map +1 -1
- package/channel/encodedChannel.cjs.map +1 -0
- package/channel/encodedChannel.d.ts +6 -3
- package/channel/encodedChannel.js +13 -14
- package/channel/encodedChannel.js.map +1 -1
- package/channel/guaranteedChannel.cjs.map +1 -0
- package/channel/guaranteedChannel.d.ts +9 -7
- package/channel/guaranteedChannel.js +74 -73
- package/channel/guaranteedChannel.js.map +1 -1
- package/channel/httpBeaconChannel.cjs.map +1 -0
- package/channel/httpBeaconChannel.d.ts +9 -6
- package/channel/httpBeaconChannel.js +82 -83
- package/channel/httpBeaconChannel.js.map +1 -1
- package/channel/index.cjs.map +1 -0
- package/channel/index.d.ts +12 -7
- package/channel/index.js +15 -17
- package/channel/index.js.map +1 -1
- package/channel/queuedChannel.cjs.map +1 -0
- package/channel/queuedChannel.d.ts +7 -4
- package/channel/queuedChannel.js +87 -97
- package/channel/queuedChannel.js.map +1 -1
- package/channel/retryChannel.cjs.map +1 -0
- package/channel/retryChannel.d.ts +7 -5
- package/channel/retryChannel.js +58 -57
- package/channel/retryChannel.js.map +1 -1
- package/channel/sandboxChannel.cjs.map +1 -0
- package/channel/sandboxChannel.d.ts +5 -2
- package/channel/sandboxChannel.js +34 -35
- package/channel/sandboxChannel.js.map +1 -1
- package/cid/assigner.cjs.map +1 -0
- package/cid/assigner.d.ts +3 -1
- package/cid/assigner.js +0 -2
- package/cid/assigner.js.map +1 -1
- package/cid/cachedAssigner.cjs.map +1 -0
- package/cid/cachedAssigner.d.ts +7 -5
- package/cid/cachedAssigner.js +37 -43
- package/cid/cachedAssigner.js.map +1 -1
- package/cid/fixedAssigner.cjs.map +1 -0
- package/cid/fixedAssigner.d.ts +5 -2
- package/cid/fixedAssigner.js +9 -10
- package/cid/fixedAssigner.js.map +1 -1
- package/cid/index.cjs.map +1 -0
- package/cid/index.d.ts +6 -4
- package/cid/index.js +9 -11
- package/cid/index.js.map +1 -1
- package/cid/remoteAssigner.cjs.map +1 -0
- package/cid/remoteAssigner.d.ts +6 -3
- package/cid/remoteAssigner.js +36 -37
- package/cid/remoteAssigner.js.map +1 -1
- package/constants.cjs.map +1 -0
- package/constants.d.ts +6 -4
- package/constants.js +10 -7
- package/constants.js.map +1 -1
- package/container.cjs.map +1 -0
- package/container.d.ts +28 -15
- package/container.js +269 -252
- package/container.js.map +1 -1
- package/contentFetcher.cjs.map +1 -0
- package/contentFetcher.d.ts +17 -14
- package/contentFetcher.js +156 -163
- package/contentFetcher.js.map +1 -1
- package/context.cjs.map +1 -0
- package/context.d.ts +13 -9
- package/context.js +80 -81
- package/context.js.map +1 -1
- package/error.cjs.map +1 -0
- package/error.d.ts +4 -2
- package/error.js +21 -21
- package/error.js.map +1 -1
- package/evaluator.cjs.map +1 -0
- package/evaluator.d.ts +18 -16
- package/evaluator.js +179 -179
- package/evaluator.js.map +1 -1
- package/eventManager.cjs.map +1 -0
- package/eventManager.d.ts +8 -6
- package/eventManager.js +24 -26
- package/eventManager.js.map +1 -1
- package/eventSubjectProcessor.cjs.map +1 -0
- package/eventSubjectProcessor.d.ts +16 -3
- package/eventSubjectProcessor.js +53 -59
- package/eventSubjectProcessor.js.map +1 -1
- package/facade/contentFetcherFacade.cjs.map +1 -0
- package/facade/contentFetcherFacade.d.ts +16 -7
- package/facade/contentFetcherFacade.js +32 -35
- package/facade/contentFetcherFacade.js.map +1 -1
- package/facade/evaluatorFacade.cjs.map +1 -0
- package/facade/evaluatorFacade.d.ts +17 -10
- package/facade/evaluatorFacade.js +56 -60
- package/facade/evaluatorFacade.js.map +1 -1
- package/facade/index.cjs.map +1 -0
- package/facade/index.d.ts +29 -7
- package/facade/index.js +19 -19
- package/facade/index.js.map +1 -1
- package/facade/sdkFacade.cjs.map +1 -0
- package/facade/sdkFacade.d.ts +33 -15
- package/facade/sdkFacade.js +201 -214
- package/facade/sdkFacade.js.map +1 -1
- package/facade/sessionFacade.cjs.map +1 -0
- package/facade/sessionFacade.d.ts +18 -3
- package/facade/sessionFacade.js +10 -11
- package/facade/sessionFacade.js.map +1 -1
- package/facade/sessionPatch.cjs.map +1 -0
- package/facade/sessionPatch.d.ts +17 -4
- package/facade/sessionPatch.js +22 -24
- package/facade/sessionPatch.js.map +1 -1
- package/facade/trackerFacade.cjs.map +1 -0
- package/facade/trackerFacade.d.ts +17 -4
- package/facade/trackerFacade.js +67 -57
- package/facade/trackerFacade.js.map +1 -1
- package/facade/userFacade.cjs.map +1 -0
- package/facade/userFacade.d.ts +21 -4
- package/facade/userFacade.js +17 -18
- package/facade/userFacade.js.map +1 -1
- package/facade/userPatch.cjs.map +1 -0
- package/facade/userPatch.d.ts +17 -4
- package/facade/userPatch.js +22 -24
- package/facade/userPatch.js.map +1 -1
- package/help.cjs.map +1 -0
- package/help.d.ts +3 -1
- package/help.js +19 -23
- package/help.js.map +1 -1
- package/index.cjs.map +1 -0
- package/index.d.ts +25 -3
- package/index.js +7 -7
- package/index.js.map +1 -1
- package/logging/consoleLogger.cjs.map +1 -0
- package/logging/consoleLogger.d.ts +5 -2
- package/logging/consoleLogger.js +23 -24
- package/logging/consoleLogger.js.map +1 -1
- package/logging/filteredLogger.cjs.map +1 -0
- package/logging/filteredLogger.d.ts +8 -5
- package/logging/filteredLogger.js +36 -37
- package/logging/filteredLogger.js.map +1 -1
- package/logging/index.cjs.map +1 -0
- package/logging/index.d.ts +5 -5
- package/logging/index.js +11 -13
- package/logging/index.js.map +1 -1
- package/logging/logger.cjs.map +1 -0
- package/logging/logger.d.ts +4 -2
- package/logging/logger.js +0 -2
- package/logging/logger.js.map +1 -1
- package/logging/namespacedLogger.cjs.map +1 -0
- package/logging/namespacedLogger.d.ts +5 -2
- package/logging/namespacedLogger.js +22 -23
- package/logging/namespacedLogger.js.map +1 -1
- package/logging/nullLogger.cjs.map +1 -0
- package/logging/nullLogger.d.ts +5 -2
- package/logging/nullLogger.js +11 -16
- package/logging/nullLogger.js.map +1 -1
- package/namespacedStorage.cjs.map +1 -0
- package/namespacedStorage.d.ts +3 -1
- package/namespacedStorage.js +51 -52
- package/namespacedStorage.js.map +1 -1
- package/package.json +60 -6
- package/patch.cjs.map +1 -0
- package/patch.d.ts +6 -4
- package/patch.js +0 -2
- package/patch.js.map +1 -1
- package/queue/capacityRestrictedQueue.cjs.map +1 -0
- package/queue/capacityRestrictedQueue.d.ts +5 -2
- package/queue/capacityRestrictedQueue.js +31 -32
- package/queue/capacityRestrictedQueue.js.map +1 -1
- package/queue/inMemoryQueue.cjs.map +1 -0
- package/queue/inMemoryQueue.d.ts +5 -2
- package/queue/inMemoryQueue.js +32 -34
- package/queue/inMemoryQueue.js.map +1 -1
- package/queue/index.cjs.map +1 -0
- package/queue/index.d.ts +6 -5
- package/queue/index.js +11 -13
- package/queue/index.js.map +1 -1
- package/queue/monitoredQueue.cjs.map +1 -0
- package/queue/monitoredQueue.d.ts +8 -5
- package/queue/monitoredQueue.js +104 -110
- package/queue/monitoredQueue.js.map +1 -1
- package/queue/persistentQueue.cjs.map +1 -0
- package/queue/persistentQueue.d.ts +5 -2
- package/queue/persistentQueue.js +52 -54
- package/queue/persistentQueue.js.map +1 -1
- package/queue/queue.cjs.map +1 -0
- package/queue/queue.d.ts +3 -1
- package/queue/queue.js +0 -2
- package/queue/queue.js.map +1 -1
- package/retry/arbitraryPolicy.cjs.map +1 -0
- package/retry/arbitraryPolicy.d.ts +5 -2
- package/retry/arbitraryPolicy.js +14 -15
- package/retry/arbitraryPolicy.js.map +1 -1
- package/retry/backoffPolicy.cjs.map +1 -0
- package/retry/backoffPolicy.d.ts +5 -3
- package/retry/backoffPolicy.js +52 -50
- package/retry/backoffPolicy.js.map +1 -1
- package/retry/index.cjs.map +1 -0
- package/retry/index.d.ts +5 -5
- package/retry/index.js +11 -13
- package/retry/index.js.map +1 -1
- package/retry/maxAttemptsPolicy.cjs.map +1 -0
- package/retry/maxAttemptsPolicy.d.ts +5 -2
- package/retry/maxAttemptsPolicy.js +17 -18
- package/retry/maxAttemptsPolicy.js.map +1 -1
- package/retry/neverPolicy.cjs.map +1 -0
- package/retry/neverPolicy.d.ts +5 -2
- package/retry/neverPolicy.js +9 -10
- package/retry/neverPolicy.js.map +1 -1
- package/retry/policy.cjs.map +1 -0
- package/retry/policy.d.ts +3 -1
- package/retry/policy.js +0 -2
- package/retry/policy.js.map +1 -1
- package/schema/attributeSchema.cjs.map +1 -0
- package/schema/attributeSchema.d.ts +6 -2
- package/schema/attributeSchema.js +7 -7
- package/schema/attributeSchema.js.map +1 -1
- package/schema/contentFetcherSchemas.cjs.map +1 -0
- package/schema/contentFetcherSchemas.d.ts +6 -2
- package/schema/contentFetcherSchemas.js +24 -21
- package/schema/contentFetcherSchemas.js.map +1 -1
- package/schema/contentSchemas.cjs.map +1 -0
- package/schema/contentSchemas.d.ts +6 -2
- package/schema/contentSchemas.js +45 -45
- package/schema/contentSchemas.js.map +1 -1
- package/schema/contextSchemas.cjs.map +1 -0
- package/schema/contextSchemas.d.ts +6 -2
- package/schema/contextSchemas.js +6 -6
- package/schema/contextSchemas.js.map +1 -1
- package/schema/ecommerceSchemas.cjs.map +1 -0
- package/schema/ecommerceSchemas.d.ts +10 -6
- package/schema/ecommerceSchemas.js +176 -172
- package/schema/ecommerceSchemas.js.map +1 -1
- package/schema/evaluatorSchemas.cjs.map +1 -0
- package/schema/evaluatorSchemas.d.ts +6 -2
- package/schema/evaluatorSchemas.js +46 -30
- package/schema/evaluatorSchemas.js.map +1 -1
- package/schema/eventSchemas.cjs.map +1 -0
- package/schema/eventSchemas.d.ts +16 -12
- package/schema/eventSchemas.js +125 -102
- package/schema/eventSchemas.js.map +1 -1
- package/schema/index.cjs.map +1 -0
- package/schema/index.d.ts +14 -11
- package/schema/index.js +11 -14
- package/schema/index.js.map +1 -1
- package/schema/loggerSchema.cjs.map +1 -0
- package/schema/loggerSchema.d.ts +6 -2
- package/schema/loggerSchema.js +13 -13
- package/schema/loggerSchema.js.map +1 -1
- package/schema/operationSchemas.cjs.map +1 -0
- package/schema/operationSchemas.d.ts +14 -10
- package/schema/operationSchemas.js +85 -69
- package/schema/operationSchemas.js.map +1 -1
- package/schema/sdkFacadeSchemas.cjs.map +1 -0
- package/schema/sdkFacadeSchemas.d.ts +6 -2
- package/schema/sdkFacadeSchemas.js +65 -51
- package/schema/sdkFacadeSchemas.js.map +1 -1
- package/schema/sdkSchemas.cjs.map +1 -0
- package/schema/sdkSchemas.d.ts +8 -4
- package/schema/sdkSchemas.js +80 -78
- package/schema/sdkSchemas.js.map +1 -1
- package/schema/tokenSchema.cjs.map +1 -0
- package/schema/tokenSchema.d.ts +6 -2
- package/schema/tokenSchema.js +41 -38
- package/schema/tokenSchema.js.map +1 -1
- package/schema/userSchema.cjs.map +1 -0
- package/schema/userSchema.d.ts +6 -2
- package/schema/userSchema.js +183 -134
- package/schema/userSchema.js.map +1 -1
- package/sdk.cjs.map +1 -0
- package/sdk.d.ts +28 -14
- package/sdk.js +106 -108
- package/sdk.js.map +1 -1
- package/sdkEvents.cjs.map +1 -0
- package/sdkEvents.d.ts +10 -5
- package/sdkEvents.js +0 -2
- package/sdkEvents.js.map +1 -1
- package/sourceLocation.cjs.map +1 -0
- package/sourceLocation.d.ts +7 -5
- package/sourceLocation.js +56 -57
- package/sourceLocation.js.map +1 -1
- package/tab.cjs.map +1 -0
- package/tab.d.ts +9 -7
- package/tab.js +93 -90
- package/tab.js.map +1 -1
- package/token/cachedTokenStore.cjs.map +1 -0
- package/token/cachedTokenStore.d.ts +8 -3
- package/token/cachedTokenStore.js +22 -24
- package/token/cachedTokenStore.js.map +1 -1
- package/token/inMemoryTokenStore.cjs.map +1 -0
- package/token/inMemoryTokenStore.d.ts +7 -2
- package/token/inMemoryTokenStore.js +12 -13
- package/token/inMemoryTokenStore.js.map +1 -1
- package/token/index.cjs.map +1 -0
- package/token/index.d.ts +7 -4
- package/token/index.js +9 -11
- package/token/index.js.map +1 -1
- package/token/replicatedTokenStore.cjs.map +1 -0
- package/token/replicatedTokenStore.d.ts +7 -2
- package/token/replicatedTokenStore.js +14 -15
- package/token/replicatedTokenStore.js.map +1 -1
- package/token/token.cjs.map +1 -0
- package/token/token.d.ts +11 -8
- package/token/token.js +212 -195
- package/token/token.js.map +1 -1
- package/tracker.cjs.map +1 -0
- package/tracker.d.ts +20 -13
- package/tracker.js +307 -307
- package/tracker.js.map +1 -1
- package/trackingEvents.cjs.map +1 -0
- package/trackingEvents.d.ts +65 -62
- package/trackingEvents.js +57 -56
- package/trackingEvents.js.map +1 -1
- package/transformer.cjs.map +1 -0
- package/transformer.d.ts +4 -2
- package/transformer.js +5 -6
- package/transformer.js.map +1 -1
- package/utilityTypes.cjs.map +1 -0
- package/utilityTypes.d.ts +4 -2
- package/utilityTypes.js +0 -2
- package/utilityTypes.js.map +1 -1
- package/uuid.cjs.map +1 -0
- package/uuid.d.ts +3 -1
- package/uuid.js +27 -32
- package/uuid.js.map +1 -1
- package/validation/arrayType.cjs.map +1 -0
- package/validation/arrayType.d.ts +5 -3
- package/validation/arrayType.js +45 -41
- package/validation/arrayType.js.map +1 -1
- package/validation/booleanType.cjs.map +1 -0
- package/validation/booleanType.d.ts +5 -2
- package/validation/booleanType.js +19 -16
- package/validation/booleanType.js.map +1 -1
- package/validation/functionType.cjs.map +1 -0
- package/validation/functionType.d.ts +5 -2
- package/validation/functionType.js +19 -16
- package/validation/functionType.js.map +1 -1
- package/validation/index.cjs.map +1 -0
- package/validation/index.d.ts +12 -12
- package/validation/index.js +27 -29
- package/validation/index.js.map +1 -1
- package/validation/jsonType.cjs.map +1 -0
- package/validation/jsonType.d.ts +8 -6
- package/validation/jsonType.js +89 -82
- package/validation/jsonType.js.map +1 -1
- package/validation/mixedSchema.cjs.map +1 -0
- package/validation/mixedSchema.d.ts +5 -2
- package/validation/mixedSchema.js +5 -7
- package/validation/mixedSchema.js.map +1 -1
- package/validation/nullType.cjs.map +1 -0
- package/validation/nullType.d.ts +5 -2
- package/validation/nullType.js +19 -16
- package/validation/nullType.js.map +1 -1
- package/validation/numberType.cjs.map +1 -0
- package/validation/numberType.d.ts +5 -3
- package/validation/numberType.js +40 -32
- package/validation/numberType.js.map +1 -1
- package/validation/objectType.cjs.map +1 -0
- package/validation/objectType.d.ts +5 -3
- package/validation/objectType.js +84 -85
- package/validation/objectType.js.map +1 -1
- package/validation/schema.cjs.map +1 -0
- package/validation/schema.d.ts +5 -3
- package/validation/schema.js +8 -9
- package/validation/schema.js.map +1 -1
- package/validation/stringType.cjs.map +1 -0
- package/validation/stringType.d.ts +5 -3
- package/validation/stringType.js +74 -70
- package/validation/stringType.js.map +1 -1
- package/validation/unionType.cjs.map +1 -0
- package/validation/unionType.d.ts +5 -2
- package/validation/unionType.js +37 -35
- package/validation/unionType.js.map +1 -1
- package/validation/violation.cjs.map +1 -0
- package/validation/violation.d.ts +4 -2
- package/validation/violation.js +18 -18
- package/validation/violation.js.map +1 -1
package/tracker.js
CHANGED
|
@@ -1,338 +1,338 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { NullLogger } from "./logging";
|
|
2
|
+
import { formatCause } from "./error";
|
|
3
|
+
import {
|
|
4
|
+
isCartPartialEvent,
|
|
5
|
+
isIdentifiedUserEvent
|
|
6
|
+
} from "./trackingEvents";
|
|
7
7
|
const trackedEvents = {};
|
|
8
8
|
class Tracker {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.listeners = [];
|
|
11
|
+
this.pending = [];
|
|
12
|
+
this.state = {
|
|
13
|
+
enabled: false,
|
|
14
|
+
initialized: false,
|
|
15
|
+
suspended: false
|
|
16
|
+
};
|
|
17
|
+
this.inactivityTimer = {
|
|
18
|
+
since: 0
|
|
19
|
+
};
|
|
20
|
+
const { tab, tokenProvider, channel, logger, inactivityRetryPolicy, ...options } = config;
|
|
21
|
+
this.tab = tab;
|
|
22
|
+
this.tokenProvider = tokenProvider;
|
|
23
|
+
this.inactivityRetryPolicy = inactivityRetryPolicy;
|
|
24
|
+
this.channel = channel;
|
|
25
|
+
this.logger = logger ?? new NullLogger();
|
|
26
|
+
this.processor = config.processor;
|
|
27
|
+
this.options = {
|
|
28
|
+
...options,
|
|
29
|
+
eventMetadata: options.eventMetadata ?? {}
|
|
30
|
+
};
|
|
31
|
+
this.enable = this.enable.bind(this);
|
|
32
|
+
this.disable = this.disable.bind(this);
|
|
33
|
+
this.suspend = this.suspend.bind(this);
|
|
34
|
+
this.unsuspend = this.unsuspend.bind(this);
|
|
35
|
+
this.trackPageLoad = this.trackPageLoad.bind(this);
|
|
36
|
+
this.trackTabVisibilityChange = this.trackTabVisibilityChange.bind(this);
|
|
37
|
+
this.trackTabUrlChange = this.trackTabUrlChange.bind(this);
|
|
38
|
+
this.trackInactivity = this.trackInactivity.bind(this);
|
|
39
|
+
}
|
|
40
|
+
addListener(listener) {
|
|
41
|
+
this.listeners.push(listener);
|
|
42
|
+
}
|
|
43
|
+
removeListener(listener) {
|
|
44
|
+
let index = this.listeners.indexOf(listener);
|
|
45
|
+
while (index >= 0) {
|
|
46
|
+
this.listeners.splice(index, 1);
|
|
47
|
+
index = this.listeners.indexOf(listener);
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
}
|
|
50
|
+
get flushed() {
|
|
51
|
+
const suppress = () => {
|
|
52
|
+
};
|
|
53
|
+
return Promise.all(this.pending).then(suppress, suppress);
|
|
54
|
+
}
|
|
55
|
+
isEnabled() {
|
|
56
|
+
return this.state.enabled;
|
|
57
|
+
}
|
|
58
|
+
isSuspended() {
|
|
59
|
+
return this.state.suspended;
|
|
60
|
+
}
|
|
61
|
+
enable() {
|
|
62
|
+
if (this.state.enabled) {
|
|
63
|
+
return;
|
|
43
64
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
index = this.listeners.indexOf(listener);
|
|
49
|
-
}
|
|
65
|
+
this.logger.info("Tracker enabled");
|
|
66
|
+
this.state.enabled = true;
|
|
67
|
+
if (this.state.suspended) {
|
|
68
|
+
return;
|
|
50
69
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return Promise.all(this.pending).then(suppress, suppress);
|
|
70
|
+
this.startInactivityTimer();
|
|
71
|
+
if (!this.state.initialized) {
|
|
72
|
+
this.state.initialized = true;
|
|
73
|
+
this.initialize();
|
|
56
74
|
}
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
this.tab.addListener("load", this.trackPageLoad);
|
|
76
|
+
this.tab.addListener("urlChange", this.trackTabUrlChange);
|
|
77
|
+
this.tab.addListener("visibilityChange", this.trackTabVisibilityChange);
|
|
78
|
+
}
|
|
79
|
+
disable() {
|
|
80
|
+
if (!this.state.enabled) {
|
|
81
|
+
return;
|
|
59
82
|
}
|
|
60
|
-
|
|
61
|
-
|
|
83
|
+
this.logger.info("Tracker disabled");
|
|
84
|
+
this.state.enabled = false;
|
|
85
|
+
if (this.state.suspended) {
|
|
86
|
+
return;
|
|
62
87
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
this.startInactivityTimer();
|
|
73
|
-
if (!this.state.initialized) {
|
|
74
|
-
this.state.initialized = true;
|
|
75
|
-
this.initialize();
|
|
76
|
-
}
|
|
77
|
-
this.tab.addListener('load', this.trackPageLoad);
|
|
78
|
-
this.tab.addListener('urlChange', this.trackTabUrlChange);
|
|
79
|
-
this.tab.addListener('visibilityChange', this.trackTabVisibilityChange);
|
|
80
|
-
}
|
|
81
|
-
disable() {
|
|
82
|
-
if (!this.state.enabled) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
this.logger.info('Tracker disabled');
|
|
86
|
-
this.state.enabled = false;
|
|
87
|
-
if (this.state.suspended) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
this.tab.removeListener('load', this.trackPageLoad);
|
|
91
|
-
this.tab.removeListener('urlChange', this.trackTabUrlChange);
|
|
92
|
-
this.tab.removeListener('visibilityChange', this.trackTabVisibilityChange);
|
|
93
|
-
this.stopInactivityTimer();
|
|
88
|
+
this.tab.removeListener("load", this.trackPageLoad);
|
|
89
|
+
this.tab.removeListener("urlChange", this.trackTabUrlChange);
|
|
90
|
+
this.tab.removeListener("visibilityChange", this.trackTabVisibilityChange);
|
|
91
|
+
this.stopInactivityTimer();
|
|
92
|
+
}
|
|
93
|
+
suspend() {
|
|
94
|
+
if (this.state.suspended) {
|
|
95
|
+
return;
|
|
94
96
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.logger.info('Tracker suspended');
|
|
100
|
-
if (this.state.enabled) {
|
|
101
|
-
this.disable();
|
|
102
|
-
this.state.enabled = true;
|
|
103
|
-
}
|
|
104
|
-
this.state.suspended = true;
|
|
97
|
+
this.logger.info("Tracker suspended");
|
|
98
|
+
if (this.state.enabled) {
|
|
99
|
+
this.disable();
|
|
100
|
+
this.state.enabled = true;
|
|
105
101
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.state.suspended = false;
|
|
112
|
-
if (this.state.enabled) {
|
|
113
|
-
this.state.enabled = false;
|
|
114
|
-
this.enable();
|
|
115
|
-
}
|
|
102
|
+
this.state.suspended = true;
|
|
103
|
+
}
|
|
104
|
+
unsuspend() {
|
|
105
|
+
if (!this.state.suspended) {
|
|
106
|
+
return;
|
|
116
107
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (this.tab.isNew && !initEvents.tabOpened) {
|
|
123
|
-
initEvents.tabOpened = true;
|
|
124
|
-
this.trackTabOpen({ tabId: this.tab.id });
|
|
125
|
-
}
|
|
126
|
-
if (!initEvents.pageOpened) {
|
|
127
|
-
initEvents.pageOpened = true;
|
|
128
|
-
this.trackPageOpen({
|
|
129
|
-
url: this.tab.url,
|
|
130
|
-
referrer: this.tab.referrer,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
108
|
+
this.logger.info("Tracker unsuspended");
|
|
109
|
+
this.state.suspended = false;
|
|
110
|
+
if (this.state.enabled) {
|
|
111
|
+
this.state.enabled = false;
|
|
112
|
+
this.enable();
|
|
133
113
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
114
|
+
}
|
|
115
|
+
initialize() {
|
|
116
|
+
if (trackedEvents[this.tab.id] === void 0) {
|
|
117
|
+
trackedEvents[this.tab.id] = {};
|
|
139
118
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const startTimer = () => {
|
|
145
|
-
if (!this.inactivityRetryPolicy.shouldRetry(iteration + 1, this.inactivityTimer.since)) {
|
|
146
|
-
window.clearTimeout(this.inactivityTimer.id);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
iteration += 1;
|
|
150
|
-
this.inactivityTimer.id = window.setTimeout(() => {
|
|
151
|
-
this.trackInactivity();
|
|
152
|
-
startTimer();
|
|
153
|
-
}, this.inactivityRetryPolicy.getDelay(iteration));
|
|
154
|
-
};
|
|
155
|
-
startTimer();
|
|
119
|
+
const initEvents = trackedEvents[this.tab.id];
|
|
120
|
+
if (this.tab.isNew && !initEvents.tabOpened) {
|
|
121
|
+
initEvents.tabOpened = true;
|
|
122
|
+
this.trackTabOpen({ tabId: this.tab.id });
|
|
156
123
|
}
|
|
157
|
-
|
|
158
|
-
|
|
124
|
+
if (!initEvents.pageOpened) {
|
|
125
|
+
initEvents.pageOpened = true;
|
|
126
|
+
this.trackPageOpen({
|
|
127
|
+
url: this.tab.url,
|
|
128
|
+
referrer: this.tab.referrer
|
|
129
|
+
});
|
|
159
130
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
});
|
|
131
|
+
}
|
|
132
|
+
stopInactivityTimer() {
|
|
133
|
+
if (this.inactivityTimer.id !== void 0) {
|
|
134
|
+
window.clearTimeout(this.inactivityTimer.id);
|
|
135
|
+
delete this.inactivityTimer.id;
|
|
166
136
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
137
|
+
}
|
|
138
|
+
startInactivityTimer() {
|
|
139
|
+
this.stopInactivityTimer();
|
|
140
|
+
this.inactivityTimer.since = Date.now();
|
|
141
|
+
let iteration = -1;
|
|
142
|
+
const startTimer = () => {
|
|
143
|
+
if (!this.inactivityRetryPolicy.shouldRetry(iteration + 1, this.inactivityTimer.since)) {
|
|
144
|
+
window.clearTimeout(this.inactivityTimer.id);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
iteration += 1;
|
|
148
|
+
this.inactivityTimer.id = window.setTimeout(
|
|
149
|
+
() => {
|
|
150
|
+
this.trackInactivity();
|
|
151
|
+
startTimer();
|
|
152
|
+
},
|
|
153
|
+
this.inactivityRetryPolicy.getDelay(iteration)
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
startTimer();
|
|
157
|
+
}
|
|
158
|
+
track(event, timestamp = Date.now()) {
|
|
159
|
+
return this.dispatch(this.enrichEvent(event, timestamp), timestamp).then(() => event);
|
|
160
|
+
}
|
|
161
|
+
trackPageOpen({ referrer, ...payload }) {
|
|
162
|
+
this.enqueue({
|
|
163
|
+
type: "pageOpened",
|
|
164
|
+
...payload,
|
|
165
|
+
...referrer.length > 0 ? { referrer } : {}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
trackPageLoad({ detail: { tab } }) {
|
|
169
|
+
this.enqueue({
|
|
170
|
+
type: "pageLoaded",
|
|
171
|
+
url: tab.url,
|
|
172
|
+
title: tab.title,
|
|
173
|
+
lastModifiedTime: Date.parse(tab.document.lastModified)
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
trackTabOpen(payload) {
|
|
177
|
+
this.enqueue({
|
|
178
|
+
type: "tabOpened",
|
|
179
|
+
...payload
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
trackTabUrlChange({ detail }) {
|
|
183
|
+
this.enqueue({
|
|
184
|
+
type: "tabUrlChanged",
|
|
185
|
+
tabId: detail.tab.id,
|
|
186
|
+
url: detail.url
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
trackTabVisibilityChange({ detail }) {
|
|
190
|
+
this.enqueue({
|
|
191
|
+
type: "tabVisibilityChanged",
|
|
192
|
+
tabId: detail.tab.id,
|
|
193
|
+
visibility: detail.visible ? "visible" : "hidden"
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
trackInactivity() {
|
|
197
|
+
this.enqueue({
|
|
198
|
+
type: "nothingChanged",
|
|
199
|
+
sinceTime: this.inactivityTimer.since
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
enqueue(event, timestamp = Date.now()) {
|
|
203
|
+
this.dispatch(event, timestamp).catch(() => {
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
notifyEvent(event) {
|
|
207
|
+
this.listeners.map((listener) => listener(event));
|
|
208
|
+
}
|
|
209
|
+
dispatch(event, timestamp) {
|
|
210
|
+
const userToken = this.tokenProvider.getToken();
|
|
211
|
+
const metadata = this.options.eventMetadata;
|
|
212
|
+
const context = {
|
|
213
|
+
tabId: this.tab.id,
|
|
214
|
+
url: this.tab.url,
|
|
215
|
+
...Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
216
|
+
};
|
|
217
|
+
const queuedEvent = {
|
|
218
|
+
...userToken !== null ? { userToken } : {},
|
|
219
|
+
event,
|
|
220
|
+
timestamp,
|
|
221
|
+
context
|
|
222
|
+
};
|
|
223
|
+
const processedEvents = this.processor !== void 0 ? this.processor.process(queuedEvent) : [queuedEvent];
|
|
224
|
+
processedEvents.sort((left, right) => left.timestamp - right.timestamp);
|
|
225
|
+
let result = null;
|
|
226
|
+
for (const processedEvent of processedEvents) {
|
|
227
|
+
if (processedEvent === queuedEvent) {
|
|
228
|
+
result = this.publish(queuedEvent);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
this.publish(processedEvent);
|
|
174
232
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
type: 'tabOpened',
|
|
178
|
-
...payload,
|
|
179
|
-
});
|
|
233
|
+
if (result === null) {
|
|
234
|
+
return Promise.reject(new Error("Event suppressed."));
|
|
180
235
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
publish(queuedEvent) {
|
|
239
|
+
const { event } = queuedEvent;
|
|
240
|
+
if (event.type !== "nothingChanged") {
|
|
241
|
+
this.stopInactivityTimer();
|
|
187
242
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
243
|
+
const eventInfo = {
|
|
244
|
+
...queuedEvent,
|
|
245
|
+
status: "pending"
|
|
246
|
+
};
|
|
247
|
+
if (this.state.suspended) {
|
|
248
|
+
this.logger.warn(`Tracker is suspended, ignoring event "${event.type}"`);
|
|
249
|
+
this.notifyEvent({ ...eventInfo, status: "ignored" });
|
|
250
|
+
return Promise.reject(new Error("The tracker is suspended."));
|
|
194
251
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
dispatch(event, timestamp) {
|
|
210
|
-
const userToken = this.tokenProvider.getToken();
|
|
211
|
-
const metadata = this.options.eventMetadata;
|
|
212
|
-
const context = {
|
|
213
|
-
tabId: this.tab.id,
|
|
214
|
-
url: this.tab.url,
|
|
215
|
-
...(Object.keys(metadata).length > 0 ? { metadata: metadata } : {}),
|
|
216
|
-
};
|
|
217
|
-
const queuedEvent = {
|
|
218
|
-
...(userToken !== null ? { userToken: userToken } : {}),
|
|
219
|
-
event: event,
|
|
220
|
-
timestamp: timestamp,
|
|
221
|
-
context: context,
|
|
222
|
-
};
|
|
223
|
-
const processedEvents = this.processor !== undefined
|
|
224
|
-
? this.processor.process(queuedEvent)
|
|
225
|
-
: [queuedEvent];
|
|
226
|
-
// sort events by timestamp in ascending order
|
|
227
|
-
processedEvents.sort((left, right) => left.timestamp - right.timestamp);
|
|
228
|
-
let result = null;
|
|
229
|
-
for (const processedEvent of processedEvents) {
|
|
230
|
-
if (processedEvent === queuedEvent) {
|
|
231
|
-
result = this.publish(queuedEvent);
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
this.publish(processedEvent);
|
|
252
|
+
this.logger.info(`Tracked event "${event.type}"`);
|
|
253
|
+
this.notifyEvent(eventInfo);
|
|
254
|
+
return new Promise((resolve, reject) => {
|
|
255
|
+
const promise = this.channel.publish(this.createBeacon(queuedEvent)).then(
|
|
256
|
+
() => {
|
|
257
|
+
this.logger.debug(`Successfully published event "${event.type}"`);
|
|
258
|
+
this.notifyEvent({ ...eventInfo, status: "confirmed" });
|
|
259
|
+
resolve(event);
|
|
260
|
+
},
|
|
261
|
+
(cause) => {
|
|
262
|
+
this.logger.error(`Failed to publish event "${event.type}", reason: ${formatCause(cause)}`);
|
|
263
|
+
this.notifyEvent({ ...eventInfo, status: "failed" });
|
|
264
|
+
reject(cause);
|
|
235
265
|
}
|
|
236
|
-
|
|
237
|
-
|
|
266
|
+
);
|
|
267
|
+
this.pending.push(promise);
|
|
268
|
+
promise.finally(() => {
|
|
269
|
+
this.pending.splice(this.pending.indexOf(promise), 1);
|
|
270
|
+
});
|
|
271
|
+
if (this.state.enabled && event.type !== "nothingChanged") {
|
|
272
|
+
this.startInactivityTimer();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
enrichEvent(event, timestamp) {
|
|
277
|
+
if (isCartPartialEvent(event)) {
|
|
278
|
+
const { cart: { lastUpdateTime = timestamp, ...cart }, ...payload } = event;
|
|
279
|
+
return {
|
|
280
|
+
...payload,
|
|
281
|
+
cart: {
|
|
282
|
+
...cart,
|
|
283
|
+
lastUpdateTime
|
|
238
284
|
}
|
|
239
|
-
|
|
285
|
+
};
|
|
240
286
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
this.logger.info(`Tracked event "${event.type}"`);
|
|
256
|
-
this.notifyEvent(eventInfo);
|
|
257
|
-
return new Promise((resolve, reject) => {
|
|
258
|
-
const promise = this.channel
|
|
259
|
-
.publish(this.createBeacon(queuedEvent))
|
|
260
|
-
.then(() => {
|
|
261
|
-
this.logger.debug(`Successfully published event "${event.type}"`);
|
|
262
|
-
this.notifyEvent({ ...eventInfo, status: 'confirmed' });
|
|
263
|
-
resolve(event);
|
|
264
|
-
}, cause => {
|
|
265
|
-
this.logger.error(`Failed to publish event "${event.type}", reason: ${(0, error_1.formatCause)(cause)}`);
|
|
266
|
-
this.notifyEvent({ ...eventInfo, status: 'failed' });
|
|
267
|
-
reject(cause);
|
|
268
|
-
});
|
|
269
|
-
this.pending.push(promise);
|
|
270
|
-
promise.finally(() => {
|
|
271
|
-
this.pending.splice(this.pending.indexOf(promise), 1);
|
|
272
|
-
});
|
|
273
|
-
if (this.state.enabled && event.type !== 'nothingChanged') {
|
|
274
|
-
this.startInactivityTimer();
|
|
275
|
-
}
|
|
276
|
-
});
|
|
287
|
+
return event;
|
|
288
|
+
}
|
|
289
|
+
createBeacon({ event, timestamp, context, userToken }) {
|
|
290
|
+
return {
|
|
291
|
+
timestamp,
|
|
292
|
+
...userToken !== void 0 ? { token: userToken.toString() } : {},
|
|
293
|
+
context,
|
|
294
|
+
payload: this.enrichBeaconPayload(this.createBeaconPayload(event))
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
createBeaconPayload(event) {
|
|
298
|
+
if (!isIdentifiedUserEvent(event)) {
|
|
299
|
+
return event;
|
|
277
300
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
301
|
+
if (event.type === "userSignedUp" && event.profile !== void 0) {
|
|
302
|
+
const { userId: userId2, profile, ...payload2 } = event;
|
|
303
|
+
return {
|
|
304
|
+
...payload2,
|
|
305
|
+
externalUserId: userId2,
|
|
306
|
+
patch: {
|
|
307
|
+
operations: [
|
|
308
|
+
{
|
|
309
|
+
type: "merge",
|
|
310
|
+
path: ".",
|
|
311
|
+
value: profile
|
|
312
|
+
}
|
|
313
|
+
]
|
|
288
314
|
}
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
createBeacon({ event, timestamp, context, userToken }) {
|
|
292
|
-
return {
|
|
293
|
-
timestamp: timestamp,
|
|
294
|
-
...(userToken !== undefined ? { token: userToken.toString() } : {}),
|
|
295
|
-
context: context,
|
|
296
|
-
payload: this.enrichBeaconPayload(this.createBeaconPayload(event)),
|
|
297
|
-
};
|
|
315
|
+
};
|
|
298
316
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
patch: {
|
|
309
|
-
operations: [
|
|
310
|
-
{
|
|
311
|
-
type: 'merge',
|
|
312
|
-
path: '.',
|
|
313
|
-
value: profile,
|
|
314
|
-
},
|
|
315
|
-
],
|
|
316
|
-
},
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
const { userId, ...payload } = event;
|
|
317
|
+
const { userId, ...payload } = event;
|
|
318
|
+
return {
|
|
319
|
+
...payload,
|
|
320
|
+
externalUserId: userId
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
enrichBeaconPayload(event) {
|
|
324
|
+
switch (event.type) {
|
|
325
|
+
case "linkOpened":
|
|
320
326
|
return {
|
|
321
|
-
|
|
322
|
-
|
|
327
|
+
...event,
|
|
328
|
+
link: new URL(event.link, this.tab.url).toString()
|
|
323
329
|
};
|
|
330
|
+
default:
|
|
331
|
+
return event;
|
|
324
332
|
}
|
|
325
|
-
|
|
326
|
-
switch (event.type) {
|
|
327
|
-
case 'linkOpened':
|
|
328
|
-
return {
|
|
329
|
-
...event,
|
|
330
|
-
link: new URL(event.link, this.tab.url).toString(),
|
|
331
|
-
};
|
|
332
|
-
default:
|
|
333
|
-
return event;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
333
|
+
}
|
|
336
334
|
}
|
|
337
|
-
|
|
335
|
+
export {
|
|
336
|
+
Tracker
|
|
337
|
+
};
|
|
338
338
|
//# sourceMappingURL=tracker.js.map
|