@buildinams/tracking 0.2.0 → 0.4.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 +86 -208
- package/dist/{sources/cart → cart}/index.d.ts +4 -4
- package/dist/{sources/cart → cart}/index.js +13 -3
- package/dist/cart/index.js.map +1 -0
- package/dist/chunk-JZ6HFGVJ.js +163 -0
- package/dist/chunk-JZ6HFGVJ.js.map +1 -0
- package/dist/{compatibility-Dc1JmTeG.d.ts → compatibility-wHn2I_ws.d.ts} +2 -2
- package/dist/{consent/index.d.ts → consent-types-DgKtGapr.d.ts} +5 -1
- package/dist/{consent/cookiebot → cookiebot}/index.d.ts +1 -1
- package/dist/{consent/cookiebot → cookiebot}/index.js +1 -1
- package/dist/cookiebot/index.js.map +1 -0
- package/dist/destination-types-DNMBOW_e.d.ts +22 -0
- package/dist/devtools/index.d.ts +18 -0
- package/dist/devtools/index.js +299 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/{sources/dom → dom}/index.d.ts +34 -40
- package/dist/{sources/dom → dom}/index.js +149 -247
- package/dist/dom/index.js.map +1 -0
- package/dist/events/index.d.ts +3 -6
- package/dist/events/index.js +5 -4
- package/dist/events/index.js.map +1 -1
- package/dist/flow/index.d.ts +10 -8
- package/dist/flow/index.js +23 -9
- package/dist/flow/index.js.map +1 -1
- package/dist/google/index.d.ts +32 -0
- package/dist/google/index.js +66 -0
- package/dist/google/index.js.map +1 -0
- package/dist/{page → navigation}/index.d.ts +7 -12
- package/dist/{page → navigation}/index.js +4 -10
- package/dist/navigation/index.js.map +1 -0
- package/dist/{consent/onetrust → onetrust}/index.d.ts +1 -1
- package/dist/{consent/onetrust → onetrust}/index.js +1 -1
- package/dist/onetrust/index.js.map +1 -0
- package/dist/shopify/index.d.ts +45 -0
- package/dist/{consent/shopify → shopify}/index.js +48 -20
- package/dist/shopify/index.js.map +1 -0
- package/dist/{sources/index.d.ts → source-types-fJXZeF2Q.d.ts} +1 -1
- package/dist/{types-DfPz7mBl.d.ts → types-CZEg03xW.d.ts} +3 -7
- package/docs/annotations.md +104 -0
- package/docs/context.md +64 -0
- package/docs/decisions/001-vendor-neutral-event-pipeline.md +2 -2
- package/docs/decisions/002-data-per-annotation-word.md +34 -0
- package/docs/events.md +93 -84
- package/docs/setup.md +189 -0
- package/package.json +41 -69
- package/dist/consent/cookiebot/index.js.map +0 -1
- package/dist/consent/index.js +0 -3
- package/dist/consent/index.js.map +0 -1
- package/dist/consent/onetrust/index.js.map +0 -1
- package/dist/consent/shopify/index.d.ts +0 -13
- package/dist/consent/shopify/index.js.map +0 -1
- package/dist/destinations/ga4/index.d.ts +0 -16
- package/dist/destinations/ga4/index.js +0 -15
- package/dist/destinations/ga4/index.js.map +0 -1
- package/dist/destinations/index.d.ts +0 -9
- package/dist/destinations/index.js +0 -17
- package/dist/destinations/index.js.map +0 -1
- package/dist/destinations/shopify/index.d.ts +0 -12
- package/dist/destinations/shopify/index.js +0 -18
- package/dist/destinations/shopify/index.js.map +0 -1
- package/dist/page/index.js.map +0 -1
- package/dist/sources/cart/index.js.map +0 -1
- package/dist/sources/cart/shopify/index.d.ts +0 -28
- package/dist/sources/cart/shopify/index.js +0 -16
- package/dist/sources/cart/shopify/index.js.map +0 -1
- package/dist/sources/dom/index.js.map +0 -1
- package/dist/sources/index.js +0 -3
- package/dist/sources/index.js.map +0 -1
- package/dist/types-BfJsv8AV.d.ts +0 -30
|
@@ -1,160 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INTERACTIVE, flagSelector, roleSelector, isIgnored, isOptedIn, readAnnotated, readText, ANNOTATION_ATTRIBUTE, DATA_ATTRIBUTES, CLONE_ATTRIBUTE, IGNORE_ATTRIBUTE, compact, promotionItems, hasWord, surrounding, entryOf, indexIn, readData } from '../chunk-JZ6HFGVJ.js';
|
|
2
|
+
export { encodeData } from '../chunk-JZ6HFGVJ.js';
|
|
3
|
+
import { IS_DEVELOPMENT } from '../chunk-KLN5K6PR.js';
|
|
2
4
|
|
|
3
|
-
// src/
|
|
4
|
-
var ANNOTATION_ATTRIBUTE = "data-e";
|
|
5
|
-
var DATA_ATTRIBUTE = "data-e-data";
|
|
6
|
-
var ROLES = ["location", "list", "item", "promotion", "form"];
|
|
7
|
-
var wordSelector = (word) => `[${ANNOTATION_ATTRIBUTE}~="${word}"]`;
|
|
8
|
-
var roleSelector = (role) => wordSelector(role);
|
|
9
|
-
var flagSelector = (flag) => wordSelector(flag);
|
|
10
|
-
var ANY_ROLE = ROLES.map(roleSelector).join(", ");
|
|
11
|
-
var hasWord = (element, word) => (element.getAttribute(ANNOTATION_ATTRIBUTE) ?? "").split(/\s+/).includes(word);
|
|
12
|
-
var splitParts = (value) => {
|
|
13
|
-
const parts = [];
|
|
14
|
-
let part = "";
|
|
15
|
-
for (let index = 0; index < value.length; index++) {
|
|
16
|
-
const char = value[index];
|
|
17
|
-
const next = value[index + 1];
|
|
18
|
-
if (char === "\\" && (next === ";" || next === "\\")) {
|
|
19
|
-
part += next;
|
|
20
|
-
index++;
|
|
21
|
-
} else if (char === ";") {
|
|
22
|
-
parts.push(part);
|
|
23
|
-
part = "";
|
|
24
|
-
} else part += char;
|
|
25
|
-
}
|
|
26
|
-
parts.push(part);
|
|
27
|
-
return parts;
|
|
28
|
-
};
|
|
29
|
-
var parse = (value) => splitParts(value ?? "").map((part) => part.trim()).filter(Boolean).map((part) => {
|
|
30
|
-
const colon = part.indexOf(":");
|
|
31
|
-
return colon === -1 ? { key: part, value: void 0 } : {
|
|
32
|
-
key: part.slice(0, colon).trim(),
|
|
33
|
-
value: part.slice(colon + 1).trim()
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
var readData = (element) => {
|
|
37
|
-
const data = {};
|
|
38
|
-
for (const { key, value } of parse(element.getAttribute(DATA_ATTRIBUTE)))
|
|
39
|
-
if (value !== void 0) data[key] = value;
|
|
40
|
-
const fields = element.querySelectorAll(
|
|
41
|
-
`[${DATA_ATTRIBUTE}]:not([${ANNOTATION_ATTRIBUTE}])`
|
|
42
|
-
);
|
|
43
|
-
for (const field of fields) {
|
|
44
|
-
if (field.parentElement?.closest(ANY_ROLE) !== element) continue;
|
|
45
|
-
for (const { key, value } of parse(field.getAttribute(DATA_ATTRIBUTE)))
|
|
46
|
-
data[key] = value ?? field.textContent?.trim() ?? "";
|
|
47
|
-
}
|
|
48
|
-
return data;
|
|
49
|
-
};
|
|
50
|
-
var readAnnotated = (element) => {
|
|
51
|
-
const composed = {};
|
|
52
|
-
for (const role of ROLES) {
|
|
53
|
-
if (hasWord(element, role)) continue;
|
|
54
|
-
const surrounding2 = element.parentElement?.closest(roleSelector(role));
|
|
55
|
-
if (surrounding2) composed[role] = { data: readData(surrounding2) };
|
|
56
|
-
}
|
|
57
|
-
return { data: readData(element), composed };
|
|
58
|
-
};
|
|
59
|
-
var surrounding = (element, role) => element.parentElement?.closest(roleSelector(role)) ?? void 0;
|
|
60
|
-
var indexInList = (item, list) => [...list.querySelectorAll(roleSelector("item"))].filter((candidate) => surrounding(candidate, "list") === list).indexOf(item);
|
|
61
|
-
var INVALID_KEY = /[\s:;\\]/;
|
|
62
|
-
var escapeValue = (value) => value.replaceAll("\\", "\\\\").replaceAll(";", "\\;");
|
|
63
|
-
var annotate = (words, data) => {
|
|
64
|
-
const fields = [];
|
|
65
|
-
for (const [key, value] of Object.entries(data ?? {})) {
|
|
66
|
-
if (INVALID_KEY.test(key)) {
|
|
67
|
-
if (IS_DEVELOPMENT)
|
|
68
|
-
console.warn(
|
|
69
|
-
`[tracking] Annotation key "${key}" left out: keys can't contain whitespace, ":", ";" or "\\".`
|
|
70
|
-
);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (value != null) fields.push(`${key}:${escapeValue(String(value))}`);
|
|
74
|
-
}
|
|
75
|
-
const annotation = {
|
|
76
|
-
"data-e": (typeof words === "string" ? [words] : words).join(" ")
|
|
77
|
-
};
|
|
78
|
-
if (fields.length) annotation["data-e-data"] = fields.join(";");
|
|
79
|
-
return annotation;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/sources/dom/opt-in.ts
|
|
83
|
-
var AUTO_ATTRIBUTE = "data-e-auto";
|
|
84
|
-
var INTERACTIVE = 'a[href], button, [role="button"], input[type="submit"], input[type="button"]';
|
|
85
|
-
var isOptedIn = (element, { flag, kind, fallback }) => {
|
|
86
|
-
if (flag && hasWord(element, flag)) return true;
|
|
87
|
-
const scope = element.closest(`[${AUTO_ATTRIBUTE}]`);
|
|
88
|
-
if (!scope) return fallback;
|
|
89
|
-
return (scope.getAttribute(AUTO_ATTRIBUTE) ?? "").split(/\s+/).includes(kind);
|
|
90
|
-
};
|
|
91
|
-
var readText = (element) => (element.getAttribute("aria-label") ?? (element instanceof HTMLInputElement ? element.value : element.textContent) ?? "").replace(/\s+/g, " ").trim().slice(0, 100);
|
|
92
|
-
var compact = (data) => Object.fromEntries(
|
|
93
|
-
Object.entries(data).filter(
|
|
94
|
-
([, value]) => value !== void 0 && value !== ""
|
|
95
|
-
)
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// src/sources/dom/clicks.ts
|
|
5
|
+
// src/dom/clicks.ts
|
|
99
6
|
var CLICKABLE = `${INTERACTIVE}, ${flagSelector("click")}`;
|
|
100
|
-
var
|
|
101
|
-
"pdf",
|
|
102
|
-
"xls",
|
|
103
|
-
"xlsx",
|
|
104
|
-
"doc",
|
|
105
|
-
"docx",
|
|
106
|
-
"txt",
|
|
107
|
-
"rtf",
|
|
108
|
-
"csv",
|
|
109
|
-
"exe",
|
|
110
|
-
"key",
|
|
111
|
-
"pps",
|
|
112
|
-
"ppt",
|
|
113
|
-
"pptx",
|
|
114
|
-
"7z",
|
|
115
|
-
"pkg",
|
|
116
|
-
"rar",
|
|
117
|
-
"gz",
|
|
118
|
-
"zip",
|
|
119
|
-
"avi",
|
|
120
|
-
"mov",
|
|
121
|
-
"mp4",
|
|
122
|
-
"mpg",
|
|
123
|
-
"mpeg",
|
|
124
|
-
"wmv",
|
|
125
|
-
"mid",
|
|
126
|
-
"midi",
|
|
127
|
-
"mp3",
|
|
128
|
-
"wav",
|
|
129
|
-
"wma"
|
|
130
|
-
];
|
|
131
|
-
var readLink = (link, {
|
|
132
|
-
internalHosts,
|
|
133
|
-
downloadExtensions
|
|
134
|
-
}) => {
|
|
135
|
-
const url = new URL(link.href, location.href);
|
|
136
|
-
const web = url.protocol === "http:" || url.protocol === "https:";
|
|
137
|
-
const fileName = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
138
|
-
const extension = fileName.includes(".") ? fileName.split(".").pop().toLowerCase() : "";
|
|
139
|
-
const isDownload = link.hasAttribute("download") || downloadExtensions.includes(extension);
|
|
140
|
-
return compact({
|
|
141
|
-
url: link.href,
|
|
142
|
-
text: readText(link),
|
|
143
|
-
outbound: web && url.hostname !== location.hostname && !internalHosts.includes(url.hostname),
|
|
144
|
-
download: isDownload ? { name: link.getAttribute("download") || fileName, extension } : void 0
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
var clicks = ({
|
|
148
|
-
auto = {},
|
|
149
|
-
internalHosts = [],
|
|
150
|
-
downloadExtensions = DOWNLOAD_EXTENSIONS
|
|
151
|
-
} = {}) => ({
|
|
7
|
+
var clicks = ({ auto = {} } = {}) => ({
|
|
152
8
|
events: ["link:click", "button:click"],
|
|
153
9
|
start({ publish }) {
|
|
154
10
|
const onClick = (event) => {
|
|
155
11
|
if (!(event.target instanceof Element)) return;
|
|
156
12
|
const element = event.target.closest(CLICKABLE);
|
|
157
|
-
if (!element) return;
|
|
13
|
+
if (!element || isIgnored(element)) return;
|
|
158
14
|
const isLink = element instanceof HTMLAnchorElement && !!element.href;
|
|
159
15
|
const tracked = isOptedIn(element, {
|
|
160
16
|
flag: "click",
|
|
@@ -162,13 +18,10 @@ var clicks = ({
|
|
|
162
18
|
fallback: (isLink ? auto.links : auto.buttons) ?? false
|
|
163
19
|
});
|
|
164
20
|
if (!tracked) return;
|
|
165
|
-
const { data, composed } = readAnnotated(element);
|
|
21
|
+
const { data, composed } = readAnnotated(element, "click");
|
|
166
22
|
if (isLink)
|
|
167
23
|
publish("link:click", {
|
|
168
|
-
data: {
|
|
169
|
-
...readLink(element, { internalHosts, downloadExtensions }),
|
|
170
|
-
...data
|
|
171
|
-
},
|
|
24
|
+
data: { url: element.href, text: readText(element), ...data },
|
|
172
25
|
composed
|
|
173
26
|
});
|
|
174
27
|
else
|
|
@@ -182,13 +35,43 @@ var clicks = ({
|
|
|
182
35
|
}
|
|
183
36
|
});
|
|
184
37
|
|
|
185
|
-
// src/
|
|
186
|
-
var createDomSource = (broker, detectors, {
|
|
38
|
+
// src/dom/create-dom-source.ts
|
|
39
|
+
var createDomSource = (broker, detectors, { clientNavigation } = {}) => {
|
|
187
40
|
const flush = () => {
|
|
188
41
|
for (const detector of detectors) detector.flush?.();
|
|
189
42
|
};
|
|
43
|
+
const mutationListeners = /* @__PURE__ */ new Set();
|
|
44
|
+
let mutations;
|
|
190
45
|
const context = {
|
|
191
|
-
publish: (name, { data, composed }) => broker.publish(name, data, composed)
|
|
46
|
+
publish: (name, { data, composed }) => broker.publish(name, data, composed),
|
|
47
|
+
onMutation(listener) {
|
|
48
|
+
if (!mutations) {
|
|
49
|
+
mutations = new MutationObserver((records) => {
|
|
50
|
+
for (const notify of [...mutationListeners]) notify(records);
|
|
51
|
+
});
|
|
52
|
+
mutations.observe(document.documentElement, {
|
|
53
|
+
childList: true,
|
|
54
|
+
subtree: true,
|
|
55
|
+
characterData: true,
|
|
56
|
+
attributes: true,
|
|
57
|
+
attributeFilter: [
|
|
58
|
+
ANNOTATION_ATTRIBUTE,
|
|
59
|
+
...DATA_ATTRIBUTES,
|
|
60
|
+
CLONE_ATTRIBUTE,
|
|
61
|
+
IGNORE_ATTRIBUTE,
|
|
62
|
+
"hidden",
|
|
63
|
+
"open"
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
mutationListeners.add(listener);
|
|
68
|
+
return () => {
|
|
69
|
+
mutationListeners.delete(listener);
|
|
70
|
+
if (mutationListeners.size) return;
|
|
71
|
+
mutations?.disconnect();
|
|
72
|
+
mutations = void 0;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
192
75
|
};
|
|
193
76
|
return {
|
|
194
77
|
start() {
|
|
@@ -202,14 +85,14 @@ var createDomSource = (broker, detectors, { currentPage }) => {
|
|
|
202
85
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
203
86
|
document.addEventListener("click", onLinkClick, { capture: true });
|
|
204
87
|
const stops = detectors.map((detector) => detector.start(context));
|
|
205
|
-
const unsubscribe =
|
|
88
|
+
const unsubscribe = clientNavigation?.subscribe({
|
|
206
89
|
leave: flush,
|
|
207
90
|
enter: () => {
|
|
208
91
|
for (const detector of detectors) detector.reset?.();
|
|
209
92
|
}
|
|
210
93
|
});
|
|
211
94
|
return () => {
|
|
212
|
-
unsubscribe();
|
|
95
|
+
unsubscribe?.();
|
|
213
96
|
flush();
|
|
214
97
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
215
98
|
document.removeEventListener("click", onLinkClick, { capture: true });
|
|
@@ -220,47 +103,59 @@ var createDomSource = (broker, detectors, { currentPage }) => {
|
|
|
220
103
|
};
|
|
221
104
|
};
|
|
222
105
|
|
|
223
|
-
// src/
|
|
106
|
+
// src/dom/detail-views.ts
|
|
224
107
|
var SELECTOR = `${roleSelector("item")}${flagSelector("detail")}`;
|
|
225
|
-
var
|
|
226
|
-
|
|
108
|
+
var isShown = (element) => element.parentElement?.checkVisibility?.() ?? true;
|
|
109
|
+
var detailViews = ({
|
|
110
|
+
key = (data) => JSON.stringify(data)
|
|
111
|
+
} = {}) => {
|
|
112
|
+
let shown = /* @__PURE__ */ new Set();
|
|
113
|
+
let rescan = () => {
|
|
114
|
+
};
|
|
227
115
|
return {
|
|
228
116
|
events: ["item:view"],
|
|
229
|
-
start({ publish }) {
|
|
117
|
+
start({ publish, onMutation }) {
|
|
230
118
|
let scheduled = false;
|
|
231
119
|
const scan = () => {
|
|
232
120
|
scheduled = false;
|
|
121
|
+
const showing = /* @__PURE__ */ new Set();
|
|
233
122
|
for (const element of document.querySelectorAll(SELECTOR)) {
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
123
|
+
if (!isShown(element) || isIgnored(element)) continue;
|
|
124
|
+
const annotated = readAnnotated(element, "item");
|
|
125
|
+
let itemKey;
|
|
126
|
+
try {
|
|
127
|
+
itemKey = key(annotated.data);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (IS_DEVELOPMENT) console.error(error);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (showing.has(itemKey)) continue;
|
|
133
|
+
showing.add(itemKey);
|
|
134
|
+
if (!shown.has(itemKey)) publish("item:view", annotated);
|
|
239
135
|
}
|
|
136
|
+
shown = showing;
|
|
240
137
|
};
|
|
241
138
|
const schedule = () => {
|
|
242
139
|
if (scheduled) return;
|
|
243
140
|
scheduled = true;
|
|
244
141
|
queueMicrotask(scan);
|
|
245
142
|
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
childList: true,
|
|
249
|
-
subtree: true,
|
|
250
|
-
characterData: true,
|
|
251
|
-
attributes: true,
|
|
252
|
-
attributeFilter: [DATA_ATTRIBUTE, ANNOTATION_ATTRIBUTE]
|
|
253
|
-
});
|
|
143
|
+
rescan = schedule;
|
|
144
|
+
const stopObserving = onMutation(schedule);
|
|
254
145
|
scan();
|
|
255
146
|
return () => {
|
|
256
|
-
|
|
257
|
-
|
|
147
|
+
stopObserving();
|
|
148
|
+
rescan = () => {
|
|
149
|
+
};
|
|
150
|
+
shown = /* @__PURE__ */ new Set();
|
|
258
151
|
};
|
|
259
|
-
}
|
|
152
|
+
},
|
|
153
|
+
// A router can show a kept page again by changing only its styles, which the observer doesn't watch.
|
|
154
|
+
reset: () => rescan()
|
|
260
155
|
};
|
|
261
156
|
};
|
|
262
157
|
|
|
263
|
-
// src/
|
|
158
|
+
// src/dom/forms.ts
|
|
264
159
|
var forms = ({ auto = false } = {}) => {
|
|
265
160
|
let started = /* @__PURE__ */ new WeakSet();
|
|
266
161
|
const resolve = (target) => {
|
|
@@ -268,10 +163,10 @@ var forms = ({ auto = false } = {}) => {
|
|
|
268
163
|
const annotated = target.closest(roleSelector("form"));
|
|
269
164
|
const form = target.closest("form");
|
|
270
165
|
const element = annotated ?? form;
|
|
271
|
-
if (!element) return void 0;
|
|
166
|
+
if (!element || isIgnored(element)) return void 0;
|
|
272
167
|
if (!annotated && !isOptedIn(element, { kind: "forms", fallback: auto }))
|
|
273
168
|
return void 0;
|
|
274
|
-
const { data, composed } = readAnnotated(element);
|
|
169
|
+
const { data, composed } = readAnnotated(element, "form");
|
|
275
170
|
const base = compact({
|
|
276
171
|
id: form?.id,
|
|
277
172
|
name: form?.getAttribute("name") ?? void 0,
|
|
@@ -313,7 +208,7 @@ var forms = ({ auto = false } = {}) => {
|
|
|
313
208
|
};
|
|
314
209
|
};
|
|
315
210
|
|
|
316
|
-
// src/
|
|
211
|
+
// src/dom/impressions.ts
|
|
317
212
|
var OBSERVED = [roleSelector("promotion"), roleSelector("item")].join(", ");
|
|
318
213
|
var impressions = ({
|
|
319
214
|
threshold = 0.5,
|
|
@@ -330,7 +225,7 @@ var impressions = ({
|
|
|
330
225
|
const pending = batches;
|
|
331
226
|
batches = /* @__PURE__ */ new Map();
|
|
332
227
|
for (const [list, items] of pending) {
|
|
333
|
-
const { data, composed } = readAnnotated(list);
|
|
228
|
+
const { data, composed } = readAnnotated(list, "list");
|
|
334
229
|
context?.publish("list:view", {
|
|
335
230
|
data: {
|
|
336
231
|
...data,
|
|
@@ -341,17 +236,29 @@ var impressions = ({
|
|
|
341
236
|
}
|
|
342
237
|
};
|
|
343
238
|
const onVisible = (element) => {
|
|
239
|
+
if (isIgnored(element)) return;
|
|
344
240
|
if (element.matches(roleSelector("promotion"))) {
|
|
345
|
-
|
|
241
|
+
const { data, composed } = readAnnotated(element, "promotion");
|
|
242
|
+
context?.publish("promotion:view", {
|
|
243
|
+
data: { ...data, items: promotionItems(element) },
|
|
244
|
+
composed
|
|
245
|
+
});
|
|
346
246
|
return;
|
|
347
247
|
}
|
|
248
|
+
if (hasWord(element, "detail")) return;
|
|
348
249
|
const list = surrounding(element, "list");
|
|
349
250
|
if (!list) return;
|
|
251
|
+
const entry = entryOf(element, list, "list");
|
|
252
|
+
if (!entry) return;
|
|
253
|
+
if (entry !== element) {
|
|
254
|
+
if (seen.has(entry)) return;
|
|
255
|
+
seen.add(entry);
|
|
256
|
+
}
|
|
350
257
|
let items = batches.get(list);
|
|
351
258
|
if (!items) batches.set(list, items = /* @__PURE__ */ new Map());
|
|
352
|
-
items.set(
|
|
353
|
-
...readData(
|
|
354
|
-
index:
|
|
259
|
+
items.set(entry, {
|
|
260
|
+
...readData(entry, "item"),
|
|
261
|
+
index: indexIn(entry, list, "list")
|
|
355
262
|
});
|
|
356
263
|
timer ??= setTimeout(flush, delay);
|
|
357
264
|
};
|
|
@@ -368,26 +275,24 @@ var impressions = ({
|
|
|
368
275
|
observer = new IntersectionObserver(
|
|
369
276
|
(entries) => {
|
|
370
277
|
for (const entry of entries) {
|
|
371
|
-
if (!entry.isIntersecting
|
|
278
|
+
if (!entry.isIntersecting) continue;
|
|
279
|
+
observer?.unobserve(entry.target);
|
|
280
|
+
if (seen.has(entry.target)) continue;
|
|
372
281
|
seen.add(entry.target);
|
|
373
282
|
onVisible(entry.target);
|
|
374
283
|
}
|
|
375
284
|
},
|
|
376
285
|
{ threshold }
|
|
377
286
|
);
|
|
378
|
-
const
|
|
287
|
+
const stopObserving = nextContext.onMutation((records) => {
|
|
379
288
|
for (const record of records)
|
|
380
289
|
for (const node of record.addedNodes)
|
|
381
290
|
if (node instanceof Element) observeAll(node);
|
|
382
291
|
});
|
|
383
292
|
observeAll(document);
|
|
384
|
-
mutations.observe(document.documentElement, {
|
|
385
|
-
childList: true,
|
|
386
|
-
subtree: true
|
|
387
|
-
});
|
|
388
293
|
return () => {
|
|
389
294
|
flush();
|
|
390
|
-
|
|
295
|
+
stopObserving();
|
|
391
296
|
observer?.disconnect();
|
|
392
297
|
observer = void 0;
|
|
393
298
|
context = void 0;
|
|
@@ -402,11 +307,11 @@ var impressions = ({
|
|
|
402
307
|
};
|
|
403
308
|
};
|
|
404
309
|
|
|
405
|
-
// src/
|
|
310
|
+
// src/dom/page-views.ts
|
|
406
311
|
var view = ({ publish }) => {
|
|
407
312
|
const data = {};
|
|
408
313
|
for (const element of document.querySelectorAll(flagSelector("page")))
|
|
409
|
-
Object.assign(data, readData(element));
|
|
314
|
+
if (!isIgnored(element)) Object.assign(data, readData(element, "page"));
|
|
410
315
|
publish("page:view", { data, composed: {} });
|
|
411
316
|
};
|
|
412
317
|
var pageViews = () => {
|
|
@@ -426,50 +331,20 @@ var pageViews = () => {
|
|
|
426
331
|
};
|
|
427
332
|
};
|
|
428
333
|
|
|
429
|
-
// src/
|
|
430
|
-
var withoutTrailingSlash = (path) => path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
431
|
-
var matches = (matcher, url) => {
|
|
432
|
-
if (typeof matcher === "function") return matcher(url);
|
|
433
|
-
if (matcher instanceof RegExp) return matcher.test(url.pathname);
|
|
434
|
-
if (matcher.endsWith("/*"))
|
|
435
|
-
return url.pathname.startsWith(matcher.slice(0, -1));
|
|
436
|
-
return withoutTrailingSlash(url.pathname) === withoutTrailingSlash(matcher);
|
|
437
|
-
};
|
|
438
|
-
var restrict = (detector, isAllowed) => {
|
|
439
|
-
let active = false;
|
|
440
|
-
const decide = () => {
|
|
441
|
-
active = isAllowed(new URL(location.href));
|
|
442
|
-
};
|
|
443
|
-
return {
|
|
444
|
-
events: detector.events,
|
|
445
|
-
start(context) {
|
|
446
|
-
decide();
|
|
447
|
-
return detector.start({
|
|
448
|
-
publish: (name, event) => {
|
|
449
|
-
if (active) context.publish(name, event);
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
},
|
|
453
|
-
flush: () => detector.flush?.(),
|
|
454
|
-
// Decided first: a Detector may publish from `reset()`, e.g. `pageViews()`.
|
|
455
|
-
reset() {
|
|
456
|
-
decide();
|
|
457
|
-
detector.reset?.();
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
};
|
|
461
|
-
var only = (detector, paths) => restrict(detector, (url) => paths.some((path) => matches(path, url)));
|
|
462
|
-
var except = (detector, paths) => restrict(detector, (url) => !paths.some((path) => matches(path, url)));
|
|
463
|
-
|
|
464
|
-
// src/sources/dom/scroll.ts
|
|
334
|
+
// src/dom/scroll.ts
|
|
465
335
|
var scroll = ({
|
|
466
336
|
thresholds = [25, 50, 75, 100]
|
|
467
337
|
} = {}) => {
|
|
468
338
|
let reached = /* @__PURE__ */ new Set();
|
|
339
|
+
let listen = () => {
|
|
340
|
+
};
|
|
469
341
|
return {
|
|
470
342
|
events: ["page:scroll"],
|
|
471
343
|
start({ publish }) {
|
|
472
|
-
|
|
344
|
+
let frame;
|
|
345
|
+
let listening = false;
|
|
346
|
+
const check = () => {
|
|
347
|
+
frame = void 0;
|
|
473
348
|
const { scrollHeight } = document.documentElement;
|
|
474
349
|
if (!scrollHeight) return;
|
|
475
350
|
const depth = (window.scrollY + window.innerHeight) / scrollHeight * 100;
|
|
@@ -481,51 +356,78 @@ var scroll = ({
|
|
|
481
356
|
composed: {}
|
|
482
357
|
});
|
|
483
358
|
}
|
|
359
|
+
if (thresholds.every((threshold) => reached.has(threshold))) unlisten();
|
|
360
|
+
};
|
|
361
|
+
const onScroll = () => {
|
|
362
|
+
frame ??= requestAnimationFrame(check);
|
|
363
|
+
};
|
|
364
|
+
const unlisten = () => {
|
|
365
|
+
listening = false;
|
|
366
|
+
window.removeEventListener("scroll", onScroll);
|
|
367
|
+
};
|
|
368
|
+
listen = () => {
|
|
369
|
+
if (listening) return;
|
|
370
|
+
listening = true;
|
|
371
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
372
|
+
};
|
|
373
|
+
listen();
|
|
374
|
+
return () => {
|
|
375
|
+
unlisten();
|
|
376
|
+
if (frame !== void 0) cancelAnimationFrame(frame);
|
|
377
|
+
frame = void 0;
|
|
378
|
+
listen = () => {
|
|
379
|
+
};
|
|
484
380
|
};
|
|
485
|
-
window.addEventListener("scroll", onScroll, { passive: true });
|
|
486
|
-
return () => window.removeEventListener("scroll", onScroll);
|
|
487
381
|
},
|
|
488
382
|
reset() {
|
|
489
383
|
reached = /* @__PURE__ */ new Set();
|
|
384
|
+
listen();
|
|
490
385
|
}
|
|
491
386
|
};
|
|
492
387
|
};
|
|
493
388
|
|
|
494
|
-
// src/
|
|
389
|
+
// src/dom/selections.ts
|
|
495
390
|
var selections = () => ({
|
|
496
391
|
events: ["item:select", "promotion:select"],
|
|
497
392
|
start({ publish }) {
|
|
498
393
|
const onClick = (event) => {
|
|
499
394
|
if (!(event.target instanceof Element)) return;
|
|
500
395
|
const target = event.target.closest(INTERACTIVE);
|
|
501
|
-
if (!target) return;
|
|
396
|
+
if (!target || isIgnored(target)) return;
|
|
502
397
|
const item = target.closest(roleSelector("item"));
|
|
503
398
|
if (item && hasWord(item, "detail")) return;
|
|
504
399
|
if (item) {
|
|
505
|
-
const { data, composed } = readAnnotated(item);
|
|
400
|
+
const { data: data2, composed: composed2 } = readAnnotated(item, "item");
|
|
506
401
|
const list = surrounding(item, "list");
|
|
402
|
+
const promotion2 = surrounding(item, "promotion");
|
|
403
|
+
const index = list ? indexIn(item, list, "list") : promotion2 && indexIn(item, promotion2, "promotion");
|
|
507
404
|
publish("item:select", {
|
|
508
|
-
data:
|
|
509
|
-
composed
|
|
405
|
+
data: index === void 0 ? data2 : { ...data2, index },
|
|
406
|
+
composed: composed2
|
|
510
407
|
});
|
|
511
408
|
return;
|
|
512
409
|
}
|
|
513
410
|
const promotion = target.closest(roleSelector("promotion"));
|
|
514
|
-
if (promotion)
|
|
411
|
+
if (!promotion) return;
|
|
412
|
+
const { data, composed } = readAnnotated(promotion, "promotion");
|
|
413
|
+
publish("promotion:select", {
|
|
414
|
+
data: { ...data, items: promotionItems(promotion) },
|
|
415
|
+
composed
|
|
416
|
+
});
|
|
515
417
|
};
|
|
516
418
|
document.addEventListener("click", onClick, { capture: true });
|
|
517
419
|
return () => document.removeEventListener("click", onClick, { capture: true });
|
|
518
420
|
}
|
|
519
421
|
});
|
|
520
422
|
|
|
521
|
-
// src/
|
|
423
|
+
// src/dom/videos.ts
|
|
522
424
|
var videos = ({
|
|
523
425
|
auto = false,
|
|
524
426
|
thresholds = [10, 25, 50, 75]
|
|
525
427
|
} = {}) => {
|
|
526
428
|
let playbacks = /* @__PURE__ */ new WeakMap();
|
|
527
429
|
const read = (video, percent) => {
|
|
528
|
-
const { data, composed } = readAnnotated(video);
|
|
430
|
+
const { data, composed } = readAnnotated(video, "video");
|
|
529
431
|
const duration = Number.isFinite(video.duration) ? video.duration : 0;
|
|
530
432
|
const base = compact({
|
|
531
433
|
url: video.currentSrc || video.src,
|
|
@@ -536,7 +438,7 @@ var videos = ({
|
|
|
536
438
|
});
|
|
537
439
|
return { data: { ...base, ...data }, composed };
|
|
538
440
|
};
|
|
539
|
-
const tracked = (target) => target instanceof HTMLVideoElement && isOptedIn(target, {
|
|
441
|
+
const tracked = (target) => target instanceof HTMLVideoElement && !isIgnored(target) && isOptedIn(target, {
|
|
540
442
|
flag: "video",
|
|
541
443
|
kind: "videos",
|
|
542
444
|
fallback: auto
|
|
@@ -592,6 +494,6 @@ var videos = ({
|
|
|
592
494
|
};
|
|
593
495
|
};
|
|
594
496
|
|
|
595
|
-
export {
|
|
497
|
+
export { clicks, createDomSource, detailViews, forms, impressions, pageViews, scroll, selections, videos };
|
|
596
498
|
//# sourceMappingURL=index.js.map
|
|
597
499
|
//# sourceMappingURL=index.js.map
|