@dotcms/events 0.0.0-stage → 26.10.5-1-alpha.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/README.md +516 -2
- package/decision.cjs.js +108 -0
- package/decision.esm.js +92 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +3674 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +3672 -0
- package/markup.cjs.default.js +1 -0
- package/markup.cjs.js +161 -0
- package/markup.cjs.mjs +2 -0
- package/markup.d.ts +1 -0
- package/markup.esm.js +159 -0
- package/package.json +77 -4
- package/react.cjs.default.js +1 -0
- package/react.cjs.js +39 -0
- package/react.cjs.mjs +2 -0
- package/react.d.ts +1 -0
- package/react.esm.js +37 -0
- package/src/index.d.ts +8 -0
- package/src/lib/clicks/constants.d.ts +14 -0
- package/src/lib/clicks/plugin.d.ts +35 -0
- package/src/lib/clicks/tracker.d.ts +42 -0
- package/src/lib/clicks/utils.d.ts +13 -0
- package/src/lib/contentlets/constants.d.ts +36 -0
- package/src/lib/contentlets/utils.d.ts +64 -0
- package/src/lib/contentlets/viewport.d.ts +23 -0
- package/src/lib/events.d.ts +17 -0
- package/src/lib/experiments/api.d.ts +9 -0
- package/src/lib/experiments/boot.d.ts +53 -0
- package/src/lib/experiments/constants.d.ts +46 -0
- package/src/lib/experiments/decision.d.ts +53 -0
- package/src/lib/experiments/dom.d.ts +62 -0
- package/src/lib/experiments/engine.d.ts +66 -0
- package/src/lib/experiments/markup.d.ts +17 -0
- package/src/lib/experiments/models.d.ts +62 -0
- package/src/lib/experiments/plugin.d.ts +27 -0
- package/src/lib/experiments/store.d.ts +54 -0
- package/src/lib/impressions/constants.d.ts +28 -0
- package/src/lib/impressions/plugin.d.ts +38 -0
- package/src/lib/impressions/tracker.d.ts +67 -0
- package/src/lib/impressions/utils.d.ts +10 -0
- package/src/lib/models.d.ts +130 -0
- package/src/lib/pipeline/constants.d.ts +88 -0
- package/src/lib/pipeline/enricher/plugin.d.ts +32 -0
- package/src/lib/pipeline/identity/activity.d.ts +19 -0
- package/src/lib/pipeline/identity/plugin.d.ts +60 -0
- package/src/lib/pipeline/logger.d.ts +74 -0
- package/src/lib/pipeline/models.d.ts +588 -0
- package/src/lib/pipeline/navigation.d.ts +21 -0
- package/src/lib/pipeline/sender/http.d.ts +9 -0
- package/src/lib/pipeline/sender/plugin.d.ts +47 -0
- package/src/lib/pipeline/sender/queue.d.ts +33 -0
- package/src/lib/pipeline/utils.d.ts +119 -0
- package/src/lib/react/DotCMSExperiment.d.ts +36 -0
- package/src/markup.d.ts +7 -0
- package/src/react.d.ts +8 -0
package/decision.esm.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attribute on the element that wraps what an experiment varies, with the experiment's id.
|
|
3
|
+
* `DotCMSExperiment` and `experimentMarkup` put it there; the engine reads it.
|
|
4
|
+
*/
|
|
5
|
+
const EXPERIMENT_ATTRIBUTE = 'data-dot-experiment';
|
|
6
|
+
/** Attribute with the variant the server rendered in that element. */
|
|
7
|
+
const VARIANT_ATTRIBUTE = 'data-dot-variant';
|
|
8
|
+
/** Name dotCMS gives the original variant. */
|
|
9
|
+
const DEFAULT_VARIANT = 'DEFAULT';
|
|
10
|
+
/** Query parameter the page API reads to render a variant. */
|
|
11
|
+
const VARIANT_QUERY_PARAM = 'variantName';
|
|
12
|
+
/** Endpoint that assigns the visitor to the running experiments. */
|
|
13
|
+
const IS_USER_INCLUDED_PATH = '/api/v1/experiments/isUserIncluded';
|
|
14
|
+
/**
|
|
15
|
+
* How long an experiment's content may stay hidden while its variant is decided. Past it the
|
|
16
|
+
* hiding rule shows the content, the boot script no longer redirects, and the engine's default
|
|
17
|
+
* wait ends.
|
|
18
|
+
*/
|
|
19
|
+
const DECISION_TIMEOUT_MS = 3000;
|
|
20
|
+
/** Default wait for the assignment on the pages the engine decides itself. */
|
|
21
|
+
const DEFAULT_ASSIGNMENT_TIMEOUT_MS = DECISION_TIMEOUT_MS;
|
|
22
|
+
/** The request itself may run longer than the wait, so the next page can use its answer. */
|
|
23
|
+
const IS_USER_INCLUDED_REQUEST_TIMEOUT_MS = 10000;
|
|
24
|
+
const ONE_DAY_MS = 24 * 60 * 60 * 1000;
|
|
25
|
+
/** How long the page being replaced keeps its new requests waiting. */
|
|
26
|
+
const QUIET_MS = 5000;
|
|
27
|
+
/**
|
|
28
|
+
* Rule printed before an experiment's content: the marked element stays hidden until the
|
|
29
|
+
* variant is decided, and shows on its own after `DECISION_TIMEOUT_MS` if nothing decides it
|
|
30
|
+
* (JavaScript off, SDK missing).
|
|
31
|
+
*/
|
|
32
|
+
const HIDING_RULE = `[${EXPERIMENT_ATTRIBUTE}]{visibility:hidden;animation:dotcms-experiment-timeout 0s linear ${DECISION_TIMEOUT_MS / 1000}s forwards}` +
|
|
33
|
+
`@keyframes dotcms-experiment-timeout{to{visibility:visible}}`;
|
|
34
|
+
const STORAGE_KEYS = {
|
|
35
|
+
/** localStorage: assignments and the experiment ids already evaluated. */
|
|
36
|
+
assignments: 'dot_events_experiments',
|
|
37
|
+
/** localStorage: until when the site answered 403 (Experiments off). */
|
|
38
|
+
disabledUntil: 'dot_events_experiments_off_until',
|
|
39
|
+
/** sessionStorage: this tab already asked `isUserIncluded`. */
|
|
40
|
+
checkedThisTab: 'dot_events_experiments_checked',
|
|
41
|
+
/** sessionStorage: the cumulative `context.experiments` of the analytics session. */
|
|
42
|
+
sessionExperiments: 'dot_events_session_experiments'
|
|
43
|
+
};
|
|
44
|
+
/** Window property where the boot script leaves its decision on the page it ran on. */
|
|
45
|
+
const BOOT_STATE_KEY = '__dotEventsExperimentBoot';
|
|
46
|
+
/** Id of the style element that reveals decided content. */
|
|
47
|
+
const REVEAL_STYLE_ID = 'dotcms-experiment-reveal';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Decides an experiment's content from what is stored. It is pure, and the boot script prints
|
|
51
|
+
* it with `Function.prototype.toString`, so it must not reference anything outside itself:
|
|
52
|
+
* the engine and the boot script run this same function.
|
|
53
|
+
*
|
|
54
|
+
* @param input - The page's experiment, the URL, the stored assignments and the shared names
|
|
55
|
+
* @returns What to do with the content
|
|
56
|
+
*/
|
|
57
|
+
function decideVariant(input) {
|
|
58
|
+
if (input.disabled) {
|
|
59
|
+
return { kind: 'excluded' };
|
|
60
|
+
}
|
|
61
|
+
const stored = (input.stored || {});
|
|
62
|
+
const experiments = Array.isArray(stored.experiments)
|
|
63
|
+
? stored.experiments
|
|
64
|
+
: [];
|
|
65
|
+
const evaluated = Array.isArray(stored.evaluatedIds) ? stored.evaluatedIds : [];
|
|
66
|
+
const assigned = experiments.find((experiment) => !!experiment &&
|
|
67
|
+
experiment.id === input.experimentId &&
|
|
68
|
+
(experiment.expiresAt || 0) > input.now);
|
|
69
|
+
const variant = assigned && assigned.variant && assigned.variant.name;
|
|
70
|
+
if (!variant) {
|
|
71
|
+
return evaluated.indexOf(input.experimentId) >= 0
|
|
72
|
+
? { kind: 'excluded' }
|
|
73
|
+
: { kind: 'unknown' };
|
|
74
|
+
}
|
|
75
|
+
if (variant === input.rendered) {
|
|
76
|
+
return { kind: 'assigned', variant };
|
|
77
|
+
}
|
|
78
|
+
const url = new URL(input.href);
|
|
79
|
+
const requested = variant === input.defaultVariant ? null : variant;
|
|
80
|
+
if (url.searchParams.get(input.param) === requested) {
|
|
81
|
+
return { kind: 'ignored', variant };
|
|
82
|
+
}
|
|
83
|
+
if (requested) {
|
|
84
|
+
url.searchParams.set(input.param, requested);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
url.searchParams.delete(input.param);
|
|
88
|
+
}
|
|
89
|
+
return { kind: 'redirect', variant, url: url.toString() };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { BOOT_STATE_KEY as B, DEFAULT_VARIANT as D, EXPERIMENT_ATTRIBUTE as E, HIDING_RULE as H, IS_USER_INCLUDED_REQUEST_TIMEOUT_MS as I, ONE_DAY_MS as O, QUIET_MS as Q, REVEAL_STYLE_ID as R, STORAGE_KEYS as S, VARIANT_ATTRIBUTE as V, DECISION_TIMEOUT_MS as a, VARIANT_QUERY_PARAM as b, IS_USER_INCLUDED_PATH as c, decideVariant as d, DEFAULT_ASSIGNMENT_TIMEOUT_MS as e };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|