@buildinams/tracking 0.0.0-stage → 0.2.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.
Files changed (51) hide show
  1. package/README.md +267 -2
  2. package/dist/chunk-KLN5K6PR.js +6 -0
  3. package/dist/chunk-KLN5K6PR.js.map +1 -0
  4. package/dist/compatibility-Dc1JmTeG.d.ts +35 -0
  5. package/dist/consent/cookiebot/index.d.ts +5 -0
  6. package/dist/consent/cookiebot/index.js +27 -0
  7. package/dist/consent/cookiebot/index.js.map +1 -0
  8. package/dist/consent/index.d.ts +18 -0
  9. package/dist/consent/index.js +3 -0
  10. package/dist/consent/index.js.map +1 -0
  11. package/dist/consent/onetrust/index.d.ts +9 -0
  12. package/dist/consent/onetrust/index.js +35 -0
  13. package/dist/consent/onetrust/index.js.map +1 -0
  14. package/dist/consent/shopify/index.d.ts +13 -0
  15. package/dist/consent/shopify/index.js +93 -0
  16. package/dist/consent/shopify/index.js.map +1 -0
  17. package/dist/destinations/ga4/index.d.ts +16 -0
  18. package/dist/destinations/ga4/index.js +15 -0
  19. package/dist/destinations/ga4/index.js.map +1 -0
  20. package/dist/destinations/index.d.ts +9 -0
  21. package/dist/destinations/index.js +17 -0
  22. package/dist/destinations/index.js.map +1 -0
  23. package/dist/destinations/shopify/index.d.ts +12 -0
  24. package/dist/destinations/shopify/index.js +18 -0
  25. package/dist/destinations/shopify/index.js.map +1 -0
  26. package/dist/events/index.d.ts +16 -0
  27. package/dist/events/index.js +77 -0
  28. package/dist/events/index.js.map +1 -0
  29. package/dist/flow/index.d.ts +16 -0
  30. package/dist/flow/index.js +82 -0
  31. package/dist/flow/index.js.map +1 -0
  32. package/dist/page/index.d.ts +27 -0
  33. package/dist/page/index.js +56 -0
  34. package/dist/page/index.js.map +1 -0
  35. package/dist/sources/cart/index.d.ts +27 -0
  36. package/dist/sources/cart/index.js +38 -0
  37. package/dist/sources/cart/index.js.map +1 -0
  38. package/dist/sources/cart/shopify/index.d.ts +28 -0
  39. package/dist/sources/cart/shopify/index.js +16 -0
  40. package/dist/sources/cart/shopify/index.js.map +1 -0
  41. package/dist/sources/dom/index.d.ts +202 -0
  42. package/dist/sources/dom/index.js +597 -0
  43. package/dist/sources/dom/index.js.map +1 -0
  44. package/dist/sources/index.d.ts +6 -0
  45. package/dist/sources/index.js +3 -0
  46. package/dist/sources/index.js.map +1 -0
  47. package/dist/types-BfJsv8AV.d.ts +30 -0
  48. package/dist/types-DfPz7mBl.d.ts +49 -0
  49. package/docs/decisions/001-vendor-neutral-event-pipeline.md +33 -0
  50. package/docs/events.md +187 -0
  51. package/package.json +141 -5
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/sources/dom/annotations.ts","../../../src/sources/dom/opt-in.ts","../../../src/sources/dom/clicks.ts","../../../src/sources/dom/create-dom-source.ts","../../../src/sources/dom/detail-views.ts","../../../src/sources/dom/forms.ts","../../../src/sources/dom/impressions.ts","../../../src/sources/dom/page-views.ts","../../../src/sources/dom/pages.ts","../../../src/sources/dom/scroll.ts","../../../src/sources/dom/selections.ts","../../../src/sources/dom/videos.ts"],"names":["surrounding"],"mappings":";;;AAGO,IAAM,oBAAA,GAAuB,QAAA;AAC7B,IAAM,cAAA,GAAiB,aAAA;AAEvB,IAAM,QAAQ,CAAC,UAAA,EAAY,MAAA,EAAQ,MAAA,EAAQ,aAAa,MAAM,CAAA;AAqBrE,IAAM,eAAe,CAAC,IAAA,KAAiB,CAAA,CAAA,EAAI,oBAAoB,MAAM,IAAI,CAAA,EAAA,CAAA;AAElE,IAAM,YAAA,GAAe,CAAC,IAAA,KAAe,YAAA,CAAa,IAAI,CAAA;AACtD,IAAM,YAAA,GAAe,CAAC,IAAA,KAAe,YAAA,CAAa,IAAI,CAAA;AAG7D,IAAM,WAAW,KAAA,CAAM,GAAA,CAAI,YAAY,CAAA,CAAE,KAAK,IAAI,CAAA;AAE3C,IAAM,OAAA,GAAU,CAAC,OAAA,EAAkB,IAAA,KAAA,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AkB,IAAA,CAAK,KAAA,EAAO,GAAG,CAAC,CAAA;AAE1C,QAAA,SAAA,CAAU,OAAO,KAAK,CAAA;AAAA,MACvB,CAAA;AAGA,MAAA,MAAM,OAAA,GAAU,EAAE,OAAA,EAAS,IAAA,EAAK;AAChC,MAAA,QAAA,CAAS,gBAAA,CAAiB,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA;AACjD,MAAA,QAAA,CAAS,gBAAA,CAAiB,YAAA,EAAc,YAAA,EAAc,OAAO,CAAA;AAC7D,MAAA,QAAA,CAAS,gBAAA,CAAiB,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AACnD,MAAA,OAAO,MAAM;AACZ,QAAA,QAAA,CAAS,mBAAA,CAAoB,MAAA,EAAQ,MAAA,EAAQ,OAAO,CAAA;AACpD,QAAA,QAAA,CAAS,mBAAA,CAAoB,YAAA,EAAc,YAAA,EAAc,OAAO,CAAA;AAChE,QAAA,QAAA,CAAS,mBAAA,CAAoB,OAAA,EAAS,OAAA,EAAS,OAAO,CAAA;AAAA,MACvD,CAAA;AAAA,IACD,CAAA;AAAA,IACA,KAAA,GAAQ;AACP,MAAA,SAAA,uBAAgB,OAAA,EAAQ;AAAA,IACzB;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../../config\";\n\n/** Space-separated words: Roles, and Flags that opt the element in to a Detector. */\nexport const ANNOTATION_ATTRIBUTE = \"data-e\";\nexport const DATA_ATTRIBUTE = \"data-e-data\";\n\nexport const ROLES = [\"location\", \"list\", \"item\", \"promotion\", \"form\"] as const;\nexport const FLAGS = [\"click\", \"video\", \"detail\", \"page\"] as const;\n\nexport type Role = (typeof ROLES)[number];\nexport type Flag = (typeof FLAGS)[number];\n\nexport type AnnotationData = Record<string, string>;\n\nexport type AnnotationValue = string | number | boolean | null | undefined;\n\n/** Attributes to spread onto an element. */\nexport type Annotation = {\n\t\"data-e\": string;\n\t\"data-e-data\"?: string;\n};\n\nexport type Annotated = {\n\tdata: AnnotationData;\n\tcomposed: Partial<Record<Role, { data: AnnotationData }>>;\n};\n\nconst wordSelector = (word: string) => `[${ANNOTATION_ATTRIBUTE}~=\"${word}\"]`;\n\nexport const roleSelector = (role: Role) => wordSelector(role);\nexport const flagSelector = (flag: Flag) => wordSelector(flag);\n\n/** Only elements with a Role own fields and appear in Compositions; Flags never do. */\nconst ANY_ROLE = ROLES.map(roleSelector).join(\", \");\n\nexport const hasWord = (element: Element, word: Role | Flag) =>\n\t(element.getAttribute(ANNOTATION_ATTRIBUTE) ?? \"\")\n\t\t.split(/\\s+/)\n\t\t.includes(word);\n\n/** Splits `data-e-data` on `;`, reading `\\;` and `\\\\` as a literal `;` and `\\`. */\nconst splitParts = (value: string) => {\n\tconst parts: string[] = [];\n\tlet part = \"\";\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst char = value[index];\n\t\tconst next = value[index + 1];\n\t\tif (char === \"\\\\\" && (next === \";\" || next === \"\\\\\")) {\n\t\t\tpart += next;\n\t\t\tindex++;\n\t\t} else if (char === \";\") {\n\t\t\tparts.push(part);\n\t\t\tpart = \"\";\n\t\t} else part += char;\n\t}\n\tparts.push(part);\n\treturn parts;\n};\n\nconst parse = (value: string | null) =>\n\tsplitParts(value ?? \"\")\n\t\t.map((part) => part.trim())\n\t\t.filter(Boolean)\n\t\t.map((part) => {\n\t\t\tconst colon = part.indexOf(\":\");\n\t\t\treturn colon === -1\n\t\t\t\t? { key: part, value: undefined }\n\t\t\t\t: {\n\t\t\t\t\t\tkey: part.slice(0, colon).trim(),\n\t\t\t\t\t\tvalue: part.slice(colon + 1).trim(),\n\t\t\t\t\t};\n\t\t});\n\nexport const readData = (element: Element): AnnotationData => {\n\tconst data: AnnotationData = {};\n\tfor (const { key, value } of parse(element.getAttribute(DATA_ATTRIBUTE)))\n\t\tif (value !== undefined) data[key] = value;\n\n\t// A flagged element's own `data-e-data` is for its own Events, not a field of its owner.\n\tconst fields = element.querySelectorAll(\n\t\t`[${DATA_ATTRIBUTE}]:not([${ANNOTATION_ATTRIBUTE}])`,\n\t);\n\tfor (const field of fields) {\n\t\tif (field.parentElement?.closest(ANY_ROLE) !== element) continue;\n\t\tfor (const { key, value } of parse(field.getAttribute(DATA_ATTRIBUTE)))\n\t\t\tdata[key] = value ?? field.textContent?.trim() ?? \"\";\n\t}\n\treturn data;\n};\n\n/** The element's own Data, with the nearest Annotated Element of every other role above it as its Composition. */\nexport const readAnnotated = (element: Element): Annotated => {\n\tconst composed: Annotated[\"composed\"] = {};\n\tfor (const role of ROLES) {\n\t\tif (hasWord(element, role)) continue;\n\t\tconst surrounding = element.parentElement?.closest(roleSelector(role));\n\t\tif (surrounding) composed[role] = { data: readData(surrounding) };\n\t}\n\treturn { data: readData(element), composed };\n};\n\n/** The nearest Annotated Element of `role` above `element`. */\nexport const surrounding = (element: Element, role: Role) =>\n\telement.parentElement?.closest(roleSelector(role)) ?? undefined;\n\n/** An Item's 0-based position among the Items whose nearest List is `list`. */\nexport const indexInList = (item: Element, list: Element) =>\n\t[...list.querySelectorAll(roleSelector(\"item\"))]\n\t\t.filter((candidate) => surrounding(candidate, \"list\") === list)\n\t\t.indexOf(item);\n\nconst INVALID_KEY = /[\\s:;\\\\]/;\n\nconst escapeValue = (value: string) =>\n\tvalue.replaceAll(\"\\\\\", \"\\\\\\\\\").replaceAll(\";\", \"\\\\;\");\n\n/**\n * The `data-e` and `data-e-data` attributes for an element with these Roles and Flags and this Data,\n * e.g. `<div {...annotate([\"item\", \"detail\"], { id, title })} />`. Values may contain `;`;\n * `null` and `undefined` ones are left out.\n */\nexport const annotate = <D extends { [K in keyof D]: AnnotationValue }>(\n\twords: Role | Flag | readonly (Role | Flag)[],\n\tdata?: D,\n): Annotation => {\n\tconst fields: string[] = [];\n\tfor (const [key, value] of Object.entries<AnnotationValue>(data ?? {})) {\n\t\tif (INVALID_KEY.test(key)) {\n\t\t\tif (IS_DEVELOPMENT)\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[tracking] Annotation key \"${key}\" left out: keys can't contain whitespace, \":\", \";\" or \"\\\\\".`,\n\t\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (value != null) fields.push(`${key}:${escapeValue(String(value))}`);\n\t}\n\tconst annotation: Annotation = {\n\t\t\"data-e\": (typeof words === \"string\" ? [words] : words).join(\" \"),\n\t};\n\tif (fields.length) annotation[\"data-e-data\"] = fields.join(\";\");\n\treturn annotation;\n};\n","import type { Flag } from \"./annotations\";\nimport { hasWord } from \"./annotations\";\n\nexport const AUTO_ATTRIBUTE = \"data-e-auto\";\n\n/** What counts as a link or button click. */\nexport const INTERACTIVE =\n\t'a[href], button, [role=\"button\"], input[type=\"submit\"], input[type=\"button\"]';\n\nexport type AutoKind = \"links\" | \"buttons\" | \"forms\" | \"videos\";\n\n/**\n * The element's own Flag opts it in; otherwise the nearest `data-e-auto` on or above it decides,\n * e.g. `\"links buttons\"`, or `\"none\"` to opt out; otherwise `fallback`.\n */\nexport const isOptedIn = (\n\telement: Element,\n\t{ flag, kind, fallback }: { flag?: Flag; kind: AutoKind; fallback: boolean },\n) => {\n\tif (flag && hasWord(element, flag)) return true;\n\tconst scope = element.closest(`[${AUTO_ATTRIBUTE}]`);\n\tif (!scope) return fallback;\n\treturn (scope.getAttribute(AUTO_ATTRIBUTE) ?? \"\").split(/\\s+/).includes(kind);\n};\n\nexport const readText = (element: Element) =>\n\t(\n\t\telement.getAttribute(\"aria-label\") ??\n\t\t(element instanceof HTMLInputElement\n\t\t\t? element.value\n\t\t\t: element.textContent) ??\n\t\t\"\"\n\t)\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim()\n\t\t.slice(0, 100);\n\n/** Leaves out absent fields, so they don't show up as `undefined` in payloads. */\nexport const compact = <T extends Record<string, unknown>>(data: T) =>\n\tObject.fromEntries(\n\t\tObject.entries(data).filter(\n\t\t\t([, value]) => value !== undefined && value !== \"\",\n\t\t),\n\t) as T;\n","import { flagSelector, readAnnotated } from \"./annotations\";\nimport { compact, INTERACTIVE, isOptedIn, readText } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nconst CLICKABLE = `${INTERACTIVE}, ${flagSelector(\"click\")}`;\n\nconst DOWNLOAD_EXTENSIONS = [\n\t\"pdf\",\n\t\"xls\",\n\t\"xlsx\",\n\t\"doc\",\n\t\"docx\",\n\t\"txt\",\n\t\"rtf\",\n\t\"csv\",\n\t\"exe\",\n\t\"key\",\n\t\"pps\",\n\t\"ppt\",\n\t\"pptx\",\n\t\"7z\",\n\t\"pkg\",\n\t\"rar\",\n\t\"gz\",\n\t\"zip\",\n\t\"avi\",\n\t\"mov\",\n\t\"mp4\",\n\t\"mpg\",\n\t\"mpeg\",\n\t\"wmv\",\n\t\"mid\",\n\t\"midi\",\n\t\"mp3\",\n\t\"wav\",\n\t\"wma\",\n];\n\nexport type LinkClickData = {\n\turl: string;\n\ttext: string;\n\t/** On another host than the page and `internalHosts`. */\n\toutbound: boolean;\n\tdownload?: { name: string; extension: string };\n\t[field: string]: unknown;\n};\n\nexport type ButtonClickData = {\n\ttext: string;\n\t[field: string]: unknown;\n};\n\nexport type ClicksOptions = {\n\t/** Whether links and buttons are tracked where no `data-e-auto` decides. */\n\tauto?: { links?: boolean; buttons?: boolean };\n\t/** Hosts besides the page's own that links aren't outbound to. */\n\tinternalHosts?: string[];\n\tdownloadExtensions?: string[];\n};\n\nconst readLink = (\n\tlink: HTMLAnchorElement,\n\t{\n\t\tinternalHosts,\n\t\tdownloadExtensions,\n\t}: Required<Pick<ClicksOptions, \"internalHosts\" | \"downloadExtensions\">>,\n): LinkClickData => {\n\tconst url = new URL(link.href, location.href);\n\tconst web = url.protocol === \"http:\" || url.protocol === \"https:\";\n\tconst fileName = decodeURIComponent(url.pathname.split(\"/\").pop() ?? \"\");\n\tconst extension = fileName.includes(\".\")\n\t\t? fileName.split(\".\").pop()!.toLowerCase()\n\t\t: \"\";\n\tconst isDownload =\n\t\tlink.hasAttribute(\"download\") || downloadExtensions.includes(extension);\n\n\treturn compact({\n\t\turl: link.href,\n\t\ttext: readText(link),\n\t\toutbound:\n\t\t\tweb &&\n\t\t\turl.hostname !== location.hostname &&\n\t\t\t!internalHosts.includes(url.hostname),\n\t\tdownload: isDownload\n\t\t\t? { name: link.getAttribute(\"download\") || fileName, extension }\n\t\t\t: undefined,\n\t});\n};\n\n/** Publishes `link:click` and `button:click` for opted-in links and buttons. */\nexport const clicks = ({\n\tauto = {},\n\tinternalHosts = [],\n\tdownloadExtensions = DOWNLOAD_EXTENSIONS,\n}: ClicksOptions = {}): Detector<{\n\t\"link:click\": LinkClickData;\n\t\"button:click\": ButtonClickData;\n}> => ({\n\tevents: [\"link:click\", \"button:click\"],\n\tstart({ publish }) {\n\t\tconst onClick = (event: MouseEvent) => {\n\t\t\tif (!(event.target instanceof Element)) return;\n\t\t\tconst element = event.target.closest(CLICKABLE);\n\t\t\tif (!element) return;\n\n\t\t\tconst isLink = element instanceof HTMLAnchorElement && !!element.href;\n\t\t\tconst tracked = isOptedIn(element, {\n\t\t\t\tflag: \"click\",\n\t\t\t\tkind: isLink ? \"links\" : \"buttons\",\n\t\t\t\tfallback: (isLink ? auto.links : auto.buttons) ?? false,\n\t\t\t});\n\t\t\tif (!tracked) return;\n\n\t\t\tconst { data, composed } = readAnnotated(element);\n\t\t\tif (isLink)\n\t\t\t\tpublish(\"link:click\", {\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t...readLink(element, { internalHosts, downloadExtensions }),\n\t\t\t\t\t\t...data,\n\t\t\t\t\t},\n\t\t\t\t\tcomposed,\n\t\t\t\t});\n\t\t\telse\n\t\t\t\tpublish(\"button:click\", {\n\t\t\t\t\tdata: { text: readText(element), ...data },\n\t\t\t\t\tcomposed,\n\t\t\t\t});\n\t\t};\n\t\tdocument.addEventListener(\"click\", onClick, { capture: true });\n\t\treturn () =>\n\t\t\tdocument.removeEventListener(\"click\", onClick, { capture: true });\n\t},\n});\n","import type { Catalog, CheckPublished, EventBroker } from \"../../events\";\nimport type { CurrentPage } from \"../../page\";\nimport type { Source } from \"../types\";\nimport type { Detector, DetectorContext } from \"./types\";\n\nexport type DomSourceOptions = {\n\tcurrentPage: Pick<CurrentPage, \"subscribe\">;\n};\n\nexport type DomSource = Source & {\n\tflush(): void;\n};\n\nexport const createDomSource = <\n\tC extends Catalog,\n\t// `any`: Detector is invariant in its Data map, so specific Detectors aren't assignable to the default.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tconst D extends readonly Detector<any>[],\n>(\n\tbroker: EventBroker<C>,\n\tdetectors: [...D] & {\n\t\t[I in keyof D]: D[I] extends Detector<infer P>\n\t\t\t? Detector<CheckPublished<C, P>>\n\t\t\t: never;\n\t},\n\t{ currentPage }: DomSourceOptions,\n): DomSource => {\n\tconst flush = () => {\n\t\tfor (const detector of detectors) detector.flush?.();\n\t};\n\n\tconst context: DetectorContext = {\n\t\tpublish: (name, { data, composed }) =>\n\t\t\t(\n\t\t\t\tbroker.publish as (\n\t\t\t\t\tname: string,\n\t\t\t\t\tdata: unknown,\n\t\t\t\t\tcomposed: unknown,\n\t\t\t\t) => void\n\t\t\t)(name, data, composed),\n\t};\n\n\treturn {\n\t\tstart() {\n\t\t\tconst onVisibilityChange = () => {\n\t\t\t\tif (document.visibilityState === \"hidden\") flush();\n\t\t\t};\n\t\t\t// Before the router changes the URL, so batches still get the Page they belong to.\n\t\t\tconst onLinkClick = (event: MouseEvent) => {\n\t\t\t\tif (event.target instanceof Element && event.target.closest(\"a[href]\"))\n\t\t\t\t\tflush();\n\t\t\t};\n\t\t\tdocument.addEventListener(\"visibilitychange\", onVisibilityChange);\n\t\t\t// Registered before the Detectors' listeners, so batches go out before what the click itself publishes.\n\t\t\tdocument.addEventListener(\"click\", onLinkClick, { capture: true });\n\t\t\tconst stops = detectors.map((detector) => detector.start(context));\n\t\t\tconst unsubscribe = currentPage.subscribe({\n\t\t\t\tleave: flush,\n\t\t\t\tenter: () => {\n\t\t\t\t\tfor (const detector of detectors) detector.reset?.();\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn () => {\n\t\t\t\tunsubscribe();\n\t\t\t\tflush();\n\t\t\t\tdocument.removeEventListener(\"visibilitychange\", onVisibilityChange);\n\t\t\t\tdocument.removeEventListener(\"click\", onLinkClick, { capture: true });\n\t\t\t\tfor (const stop of stops) stop();\n\t\t\t};\n\t\t},\n\t\tflush,\n\t};\n};\n","import type { AnnotationData } from \"./annotations\";\nimport {\n\tANNOTATION_ATTRIBUTE,\n\tDATA_ATTRIBUTE,\n\tflagSelector,\n\treadAnnotated,\n\troleSelector,\n} from \"./annotations\";\nimport type { Detector } from \"./types\";\n\nconst SELECTOR = `${roleSelector(\"item\")}${flagSelector(\"detail\")}`;\n\n/** Publishes `item:view` when an Item flagged `detail` (`data-e=\"item detail\"`), e.g. a product page's, is rendered or shows another Item. */\nexport const detailViews = (): Detector<{ \"item:view\": AnnotationData }> => {\n\t// Keyed by element and Data, not reset per Page: a product page reused across navigations reports each product once.\n\tlet reported = new WeakMap<Element, string>();\n\n\treturn {\n\t\tevents: [\"item:view\"],\n\t\tstart({ publish }) {\n\t\t\tlet scheduled = false;\n\t\t\tconst scan = () => {\n\t\t\t\tscheduled = false;\n\t\t\t\tfor (const element of document.querySelectorAll(SELECTOR)) {\n\t\t\t\t\tconst annotated = readAnnotated(element);\n\t\t\t\t\tconst key = JSON.stringify(annotated.data);\n\t\t\t\t\tif (reported.get(element) === key) continue;\n\t\t\t\t\treported.set(element, key);\n\t\t\t\t\tpublish(\"item:view\", annotated);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst schedule = () => {\n\t\t\t\tif (scheduled) return;\n\t\t\t\tscheduled = true;\n\t\t\t\tqueueMicrotask(scan);\n\t\t\t};\n\n\t\t\tconst mutations = new MutationObserver(schedule);\n\t\t\tmutations.observe(document.documentElement, {\n\t\t\t\tchildList: true,\n\t\t\t\tsubtree: true,\n\t\t\t\tcharacterData: true,\n\t\t\t\tattributes: true,\n\t\t\t\tattributeFilter: [DATA_ATTRIBUTE, ANNOTATION_ATTRIBUTE],\n\t\t\t});\n\t\t\tscan();\n\t\t\treturn () => {\n\t\t\t\tmutations.disconnect();\n\t\t\t\treported = new WeakMap();\n\t\t\t};\n\t\t},\n\t};\n};\n","import { readAnnotated, roleSelector } from \"./annotations\";\nimport { compact, isOptedIn, readText } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nexport type FormEventData = {\n\tid?: string;\n\tname?: string;\n\t/** The form's `action`, absolute. */\n\tdestination?: string;\n\t[field: string]: unknown;\n};\n\nexport type FormSubmitData = FormEventData & {\n\t/** The submitting button's text. */\n\tsubmitText?: string;\n};\n\nexport type FormsOptions = {\n\t/** Whether forms are tracked where neither a Form Annotation nor `data-e-auto` decides. */\n\tauto?: boolean;\n};\n\n/** Publishes `form:start` on the first interaction with a form per Page, and `form:submit`; field values are never read. */\nexport const forms = ({ auto = false }: FormsOptions = {}): Detector<{\n\t\"form:start\": FormEventData;\n\t\"form:submit\": FormSubmitData;\n}> => {\n\tlet started = new WeakSet<Element>();\n\n\tconst resolve = (target: EventTarget | null) => {\n\t\tif (!(target instanceof Element)) return undefined;\n\t\tconst annotated = target.closest(roleSelector(\"form\"));\n\t\tconst form = target.closest(\"form\");\n\t\tconst element = annotated ?? form;\n\t\tif (!element) return undefined;\n\t\tif (!annotated && !isOptedIn(element, { kind: \"forms\", fallback: auto }))\n\t\t\treturn undefined;\n\n\t\tconst { data, composed } = readAnnotated(element);\n\t\tconst base: FormEventData = compact({\n\t\t\tid: form?.id,\n\t\t\tname: form?.getAttribute(\"name\") ?? undefined,\n\t\t\tdestination: form?.action,\n\t\t});\n\t\treturn { element, data: { ...base, ...data }, composed };\n\t};\n\n\treturn {\n\t\tevents: [\"form:start\", \"form:submit\"],\n\t\tstart({ publish }) {\n\t\t\tconst onInteraction = (event: Event) => {\n\t\t\t\tconst form = resolve(event.target);\n\t\t\t\tif (!form || started.has(form.element)) return;\n\t\t\t\tstarted.add(form.element);\n\t\t\t\tpublish(\"form:start\", form);\n\t\t\t};\n\t\t\tconst onSubmit = (event: SubmitEvent) => {\n\t\t\t\tconst form = resolve(event.target);\n\t\t\t\tif (!form) return;\n\t\t\t\tconst submitText = event.submitter\n\t\t\t\t\t? readText(event.submitter)\n\t\t\t\t\t: undefined;\n\t\t\t\tpublish(\"form:submit\", {\n\t\t\t\t\tdata: { ...compact({ submitText }), ...form.data },\n\t\t\t\t\tcomposed: form.composed,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst options = { capture: true };\n\t\t\tdocument.addEventListener(\"input\", onInteraction, options);\n\t\t\tdocument.addEventListener(\"change\", onInteraction, options);\n\t\t\tdocument.addEventListener(\"submit\", onSubmit, options);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"input\", onInteraction, options);\n\t\t\t\tdocument.removeEventListener(\"change\", onInteraction, options);\n\t\t\t\tdocument.removeEventListener(\"submit\", onSubmit, options);\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\tstarted = new WeakSet();\n\t\t},\n\t};\n};\n","import type { AnnotationData } from \"./annotations\";\nimport {\n\tindexInList,\n\treadAnnotated,\n\treadData,\n\troleSelector,\n\tsurrounding,\n} from \"./annotations\";\nimport type { Detector, DetectorContext } from \"./types\";\n\nexport type ListViewItem = {\n\tindex: number;\n\t[field: string]: unknown;\n};\n\nexport type ListViewData = {\n\t/** The List's Items seen since the last batch, in List order. */\n\titems: ListViewItem[];\n\t[field: string]: unknown;\n};\n\nexport type ImpressionsOptions = {\n\t/** Share of an element that must be visible. */\n\tthreshold?: number;\n\t/** Milliseconds Items are batched per List before `list:view` is published. */\n\tdelay?: number;\n};\n\nconst OBSERVED = [roleSelector(\"promotion\"), roleSelector(\"item\")].join(\", \");\n\n/**\n * Publishes `promotion:view` the first time a Promotion is visible on a Page, and\n * `list:view` with the Items of a List first visible on a Page, batched per List.\n */\nexport const impressions = ({\n\tthreshold = 0.5,\n\tdelay = 1000,\n}: ImpressionsOptions = {}): Detector<{\n\t\"promotion:view\": AnnotationData;\n\t\"list:view\": ListViewData;\n}> => {\n\tlet seen = new WeakSet<Element>();\n\tlet batches = new Map<Element, Map<Element, ListViewItem>>();\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tlet context: DetectorContext | undefined;\n\tlet observer: IntersectionObserver | undefined;\n\n\tconst flush = () => {\n\t\tclearTimeout(timer);\n\t\ttimer = undefined;\n\t\tconst pending = batches;\n\t\tbatches = new Map();\n\t\tfor (const [list, items] of pending) {\n\t\t\tconst { data, composed } = readAnnotated(list);\n\t\t\tcontext?.publish(\"list:view\", {\n\t\t\t\tdata: {\n\t\t\t\t\t...data,\n\t\t\t\t\titems: [...items.values()].sort((a, b) => a.index - b.index),\n\t\t\t\t},\n\t\t\t\tcomposed,\n\t\t\t});\n\t\t}\n\t};\n\n\tconst onVisible = (element: Element) => {\n\t\tif (element.matches(roleSelector(\"promotion\"))) {\n\t\t\tcontext?.publish(\"promotion:view\", readAnnotated(element));\n\t\t\treturn;\n\t\t}\n\t\tconst list = surrounding(element, \"list\");\n\t\tif (!list) return;\n\t\tlet items = batches.get(list);\n\t\tif (!items) batches.set(list, (items = new Map()));\n\t\t// Read now: the Item may be gone or moved by the time the batch is published.\n\t\titems.set(element, {\n\t\t\t...readData(element),\n\t\t\tindex: indexInList(element, list),\n\t\t});\n\t\ttimer ??= setTimeout(flush, delay);\n\t};\n\n\tconst observeAll = (root: ParentNode) => {\n\t\tif (root instanceof Element && root.matches(OBSERVED))\n\t\t\tobserver?.observe(root);\n\t\tfor (const element of root.querySelectorAll(OBSERVED))\n\t\t\tobserver?.observe(element);\n\t};\n\n\treturn {\n\t\tevents: [\"promotion:view\", \"list:view\"],\n\t\tstart(nextContext) {\n\t\t\tcontext = nextContext;\n\t\t\tobserver = new IntersectionObserver(\n\t\t\t\t(entries) => {\n\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\tif (!entry.isIntersecting || seen.has(entry.target)) continue;\n\t\t\t\t\t\tseen.add(entry.target);\n\t\t\t\t\t\tonVisible(entry.target);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ threshold },\n\t\t\t);\n\t\t\tconst mutations = new MutationObserver((records) => {\n\t\t\t\tfor (const record of records)\n\t\t\t\t\tfor (const node of record.addedNodes)\n\t\t\t\t\t\tif (node instanceof Element) observeAll(node);\n\t\t\t});\n\t\t\tobserveAll(document);\n\t\t\tmutations.observe(document.documentElement, {\n\t\t\t\tchildList: true,\n\t\t\t\tsubtree: true,\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tflush();\n\t\t\t\tmutations.disconnect();\n\t\t\t\tobserver?.disconnect();\n\t\t\t\tobserver = undefined;\n\t\t\t\tcontext = undefined;\n\t\t\t};\n\t\t},\n\t\tflush,\n\t\treset() {\n\t\t\tseen = new WeakSet();\n\t\t\t// Re-observing makes the observer report elements already in view again.\n\t\t\tobserver?.disconnect();\n\t\t\tobserveAll(document);\n\t\t},\n\t};\n};\n","import type { AnnotationData } from \"./annotations\";\nimport { flagSelector, readData } from \"./annotations\";\nimport type { Detector, DetectorContext } from \"./types\";\n\nconst view = ({ publish }: DetectorContext) => {\n\tconst data: AnnotationData = {};\n\tfor (const element of document.querySelectorAll(flagSelector(\"page\")))\n\t\tObject.assign(data, readData(element));\n\tpublish(\"page:view\", { data, composed: {} });\n};\n\n/** Publishes `page:view` once per Page, with the Data of every element flagged `page` (`data-e=\"page\"`), later ones winning on conflicts. */\nexport const pageViews = (): Detector<{ \"page:view\": AnnotationData }> => {\n\tlet started: DetectorContext | undefined;\n\n\treturn {\n\t\tevents: [\"page:view\"],\n\t\tstart(context) {\n\t\t\tstarted = context;\n\t\t\tview(context);\n\t\t\treturn () => {\n\t\t\t\tstarted = undefined;\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\tif (started) view(started);\n\t\t},\n\t};\n};\n","import type { Detector } from \"./types\";\n\n/**\n * An exact pathname (`\"/search\"`), a pathname ending in `/*` for everything below it\n * (`\"/collections/*\"`), a `RegExp` tested against the pathname, or a function of the URL.\n */\nexport type PathMatcher = string | RegExp | ((url: URL) => boolean);\n\nconst withoutTrailingSlash = (path: string) =>\n\tpath.length > 1 && path.endsWith(\"/\") ? path.slice(0, -1) : path;\n\nconst matches = (matcher: PathMatcher, url: URL) => {\n\tif (typeof matcher === \"function\") return matcher(url);\n\tif (matcher instanceof RegExp) return matcher.test(url.pathname);\n\tif (matcher.endsWith(\"/*\"))\n\t\treturn url.pathname.startsWith(matcher.slice(0, -1));\n\treturn withoutTrailingSlash(url.pathname) === withoutTrailingSlash(matcher);\n};\n\nconst restrict = <P extends Record<string, object>>(\n\tdetector: Detector<P>,\n\tisAllowed: (url: URL) => boolean,\n): Detector<P> => {\n\t// Decided per Page rather than per publish: batches are flushed on leaving a Page, before the URL counts as changed.\n\tlet active = false;\n\tconst decide = () => {\n\t\tactive = isAllowed(new URL(location.href));\n\t};\n\n\treturn {\n\t\tevents: detector.events,\n\t\tstart(context) {\n\t\t\tdecide();\n\t\t\treturn detector.start({\n\t\t\t\tpublish: (name, event) => {\n\t\t\t\t\tif (active) context.publish(name, event);\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tflush: () => detector.flush?.(),\n\t\t// Decided first: a Detector may publish from `reset()`, e.g. `pageViews()`.\n\t\treset() {\n\t\t\tdecide();\n\t\t\tdetector.reset?.();\n\t\t},\n\t};\n};\n\n/** Publishes the Detector's Events only on Pages matching one of `paths`. */\nexport const only = <P extends Record<string, object>>(\n\tdetector: Detector<P>,\n\tpaths: PathMatcher[],\n) => restrict(detector, (url) => paths.some((path) => matches(path, url)));\n\n/** Publishes the Detector's Events on every Page except those matching one of `paths`. */\nexport const except = <P extends Record<string, object>>(\n\tdetector: Detector<P>,\n\tpaths: PathMatcher[],\n) => restrict(detector, (url) => !paths.some((path) => matches(path, url)));\n","import type { Detector } from \"./types\";\n\nexport type ScrollOptions = {\n\t/** Percentages of the page height. */\n\tthresholds?: number[];\n};\n\n/** Publishes `page:scroll` once per threshold per Page, with `{ depth }`. */\nexport const scroll = ({\n\tthresholds = [25, 50, 75, 100],\n}: ScrollOptions = {}): Detector<{ \"page:scroll\": { depth: string } }> => {\n\tlet reached = new Set<number>();\n\n\treturn {\n\t\tevents: [\"page:scroll\"],\n\t\tstart({ publish }) {\n\t\t\tconst onScroll = () => {\n\t\t\t\tconst { scrollHeight } = document.documentElement;\n\t\t\t\tif (!scrollHeight) return;\n\t\t\t\tconst depth =\n\t\t\t\t\t((window.scrollY + window.innerHeight) / scrollHeight) * 100;\n\t\t\t\tfor (const threshold of thresholds) {\n\t\t\t\t\tif (depth < threshold || reached.has(threshold)) continue;\n\t\t\t\t\treached.add(threshold);\n\t\t\t\t\tpublish(\"page:scroll\", {\n\t\t\t\t\t\tdata: { depth: String(threshold) },\n\t\t\t\t\t\tcomposed: {},\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t};\n\t\t\twindow.addEventListener(\"scroll\", onScroll, { passive: true });\n\t\t\treturn () => window.removeEventListener(\"scroll\", onScroll);\n\t\t},\n\t\treset() {\n\t\t\treached = new Set();\n\t\t},\n\t};\n};\n","import type { AnnotationData } from \"./annotations\";\nimport {\n\thasWord,\n\tindexInList,\n\treadAnnotated,\n\troleSelector,\n\tsurrounding,\n} from \"./annotations\";\nimport { INTERACTIVE } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nexport type ItemSelectData = {\n\t/** Position in its List, when it's in one. */\n\tindex?: number;\n\t[field: string]: unknown;\n};\n\n/**\n * Publishes `item:select` for link and button clicks in an Item, its List and Promotion in its\n * Composition, and `promotion:select` for link and button clicks in a Promotion outside any Item.\n * Clicks in an Item flagged `detail` select nothing.\n */\nexport const selections = (): Detector<{\n\t\"item:select\": ItemSelectData;\n\t\"promotion:select\": AnnotationData;\n}> => ({\n\tevents: [\"item:select\", \"promotion:select\"],\n\tstart({ publish }) {\n\t\tconst onClick = (event: MouseEvent) => {\n\t\t\tif (!(event.target instanceof Element)) return;\n\t\t\tconst target = event.target.closest(INTERACTIVE);\n\t\t\tif (!target) return;\n\t\t\tconst item = target.closest(roleSelector(\"item\"));\n\t\t\t// On its own detail page, clicking an Item's actions (add to cart, variants) isn't selecting it.\n\t\t\tif (item && hasWord(item, \"detail\")) return;\n\t\t\tif (item) {\n\t\t\t\tconst { data, composed } = readAnnotated(item);\n\t\t\t\tconst list = surrounding(item, \"list\");\n\t\t\t\tpublish(\"item:select\", {\n\t\t\t\t\tdata: list ? { ...data, index: indexInList(item, list) } : data,\n\t\t\t\t\tcomposed,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst promotion = target.closest(roleSelector(\"promotion\"));\n\t\t\tif (promotion) publish(\"promotion:select\", readAnnotated(promotion));\n\t\t};\n\t\tdocument.addEventListener(\"click\", onClick, { capture: true });\n\t\treturn () =>\n\t\t\tdocument.removeEventListener(\"click\", onClick, { capture: true });\n\t},\n});\n","import { readAnnotated } from \"./annotations\";\nimport { compact, isOptedIn } from \"./opt-in\";\nimport type { Detector } from \"./types\";\n\nexport type VideoEventData = {\n\turl: string;\n\ttitle?: string;\n\t/** Seconds, rounded. */\n\tduration: number;\n\t/** Seconds, rounded. */\n\tcurrentTime: number;\n\t/** For `video:progress`, the threshold reached; otherwise the share played. */\n\tpercent: number;\n\t[field: string]: unknown;\n};\n\nexport type VideosOptions = {\n\t/** Whether videos are tracked where neither a `video` Flag nor `data-e-auto` decides. */\n\tauto?: boolean;\n\t/** Percentages reported once per video per Page. */\n\tthresholds?: number[];\n};\n\ntype Playback = { started: boolean; reached: Set<number> };\n\n/** Publishes `video:start`, `video:progress` and `video:complete` for opted-in `<video>` elements. */\nexport const videos = ({\n\tauto = false,\n\tthresholds = [10, 25, 50, 75],\n}: VideosOptions = {}): Detector<{\n\t\"video:start\": VideoEventData;\n\t\"video:progress\": VideoEventData;\n\t\"video:complete\": VideoEventData;\n}> => {\n\tlet playbacks = new WeakMap<HTMLVideoElement, Playback>();\n\n\tconst read = (video: HTMLVideoElement, percent?: number) => {\n\t\tconst { data, composed } = readAnnotated(video);\n\t\tconst duration = Number.isFinite(video.duration) ? video.duration : 0;\n\t\tconst base: VideoEventData = compact({\n\t\t\turl: video.currentSrc || video.src,\n\t\t\ttitle: video.title || video.getAttribute(\"aria-label\") || undefined,\n\t\t\tduration: Math.round(duration),\n\t\t\tcurrentTime: Math.round(video.currentTime),\n\t\t\tpercent:\n\t\t\t\tpercent ??\n\t\t\t\t(duration ? Math.round((video.currentTime / duration) * 100) : 0),\n\t\t});\n\t\treturn { data: { ...base, ...data }, composed };\n\t};\n\n\tconst tracked = (target: EventTarget | null) =>\n\t\ttarget instanceof HTMLVideoElement &&\n\t\tisOptedIn(target, {\n\t\t\tflag: \"video\",\n\t\t\tkind: \"videos\",\n\t\t\tfallback: auto,\n\t\t})\n\t\t\t? target\n\t\t\t: undefined;\n\n\tconst playback = (video: HTMLVideoElement) => {\n\t\tlet state = playbacks.get(video);\n\t\tif (!state)\n\t\t\tplaybacks.set(video, (state = { started: false, reached: new Set() }));\n\t\treturn state;\n\t};\n\n\treturn {\n\t\tevents: [\"video:start\", \"video:progress\", \"video:complete\"],\n\t\tstart({ publish }) {\n\t\t\tconst onPlay = (event: Event) => {\n\t\t\t\tconst video = tracked(event.target);\n\t\t\t\tif (!video) return;\n\t\t\t\tconst state = playback(video);\n\t\t\t\tif (state.started) return;\n\t\t\t\tstate.started = true;\n\t\t\t\tpublish(\"video:start\", read(video));\n\t\t\t};\n\t\t\tconst onTimeUpdate = (event: Event) => {\n\t\t\t\tconst video = tracked(event.target);\n\t\t\t\tif (!video || !Number.isFinite(video.duration) || !video.duration)\n\t\t\t\t\treturn;\n\t\t\t\tconst state = playback(video);\n\t\t\t\tconst percent = (video.currentTime / video.duration) * 100;\n\t\t\t\tfor (const threshold of thresholds) {\n\t\t\t\t\tif (percent < threshold || state.reached.has(threshold)) continue;\n\t\t\t\t\tstate.reached.add(threshold);\n\t\t\t\t\tpublish(\"video:progress\", read(video, threshold));\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst onEnded = (event: Event) => {\n\t\t\t\tconst video = tracked(event.target);\n\t\t\t\tif (!video) return;\n\t\t\t\tpublish(\"video:complete\", read(video, 100));\n\t\t\t\t// Playing it again is a new start.\n\t\t\t\tplaybacks.delete(video);\n\t\t\t};\n\n\t\t\t// Media events don't bubble, but capturing listeners on the document still see them.\n\t\t\tconst options = { capture: true };\n\t\t\tdocument.addEventListener(\"play\", onPlay, options);\n\t\t\tdocument.addEventListener(\"timeupdate\", onTimeUpdate, options);\n\t\t\tdocument.addEventListener(\"ended\", onEnded, options);\n\t\t\treturn () => {\n\t\t\t\tdocument.removeEventListener(\"play\", onPlay, options);\n\t\t\t\tdocument.removeEventListener(\"timeupdate\", onTimeUpdate, options);\n\t\t\t\tdocument.removeEventListener(\"ended\", onEnded, options);\n\t\t\t};\n\t\t},\n\t\treset() {\n\t\t\tplaybacks = new WeakMap();\n\t\t},\n\t};\n};\n"]}
@@ -0,0 +1,6 @@
1
+ type Source = {
2
+ /** Returns the function that stops it. */
3
+ start(): () => void;
4
+ };
5
+
6
+ export type { Source };
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,30 @@
1
+ import { ConsentRequirement } from './consent/index.js';
2
+ import { C as Catalog, T as TrackingEvent, a as EventName, B as BrokerEvents } from './types-DfPz7mBl.js';
3
+
4
+ type DestinationEvent = {
5
+ name: string;
6
+ payload: unknown;
7
+ };
8
+ type Destination<E extends DestinationEvent = DestinationEvent> = {
9
+ name: string;
10
+ send(event: E): void | Promise<void>;
11
+ };
12
+ type ConsentedDestination<E extends DestinationEvent> = {
13
+ destination: Destination<E>;
14
+ requires: ConsentRequirement;
15
+ };
16
+ type Mapping<C extends Catalog, E extends DestinationEvent, Cx> = {
17
+ [N in EventName<C>]?: (event: TrackingEvent<C, N, Cx>) => E | null | undefined;
18
+ };
19
+ type MappedDestination<C extends Catalog, Cx = unknown> = {
20
+ name: string;
21
+ requires: ConsentRequirement;
22
+ /** Maps and sends; `false` when the Event has no Mapping or it returned nothing. */
23
+ deliver(event: TrackingEvent<C, EventName<C>, Cx>): false | void | Promise<void>;
24
+ };
25
+ type Destinations<C extends Catalog, Cx = unknown> = {
26
+ readonly events: BrokerEvents<C, Cx>;
27
+ readonly mapped: readonly MappedDestination<C, Cx>[];
28
+ };
29
+
30
+ export type { ConsentedDestination as C, Destinations as D, MappedDestination as M, DestinationEvent as a, Mapping as b, Destination as c };
@@ -0,0 +1,49 @@
1
+ declare const SHAPE: unique symbol;
2
+ declare const CONTEXT: unique symbol;
3
+ type Shape<T> = {
4
+ readonly [SHAPE]?: T;
5
+ };
6
+ type CatalogEntry = {
7
+ data: Shape<unknown>;
8
+ composed?: Shape<Record<string, unknown>>;
9
+ };
10
+ type Catalog = Record<string, CatalogEntry>;
11
+ type ShapeOf<S> = S extends Shape<infer T> ? T : never;
12
+ type EventName<C extends Catalog> = keyof C & string;
13
+ type EventData<C extends Catalog, N extends EventName<C>> = ShapeOf<C[N]["data"]>;
14
+ type Composition<C extends Catalog, N extends EventName<C>> = C[N] extends {
15
+ composed: infer S;
16
+ } ? {
17
+ [R in keyof ShapeOf<S>]?: {
18
+ data: ShapeOf<S>[R];
19
+ };
20
+ } : Record<never, never>;
21
+ type EventMeta = {
22
+ id: string;
23
+ timestamp: number;
24
+ seq: number;
25
+ };
26
+ type TrackingEvent<C extends Catalog, N extends EventName<C> = EventName<C>, Cx = unknown> = {
27
+ [K in N]: {
28
+ readonly name: K;
29
+ readonly data: EventData<C, K>;
30
+ readonly composed: Readonly<Composition<C, K>>;
31
+ readonly context: Readonly<Cx>;
32
+ readonly meta: Readonly<EventMeta>;
33
+ };
34
+ }[N];
35
+ type SubscribeOptions = {
36
+ /** Receive the Events held while nobody asked for replay first. */
37
+ replay?: boolean;
38
+ };
39
+ /** The catalog, carrying the Broker's Context type so `createDestinations()` can read it from `broker.events`. */
40
+ type BrokerEvents<C extends Catalog, Cx> = C & {
41
+ readonly [CONTEXT]?: Cx;
42
+ };
43
+ type EventBroker<C extends Catalog, Cx = unknown> = {
44
+ readonly events: BrokerEvents<C, Cx>;
45
+ publish<N extends EventName<C>>(name: N, data: EventData<C, N>, composed?: Composition<C, N>): void;
46
+ subscribe(listener: (event: TrackingEvent<C, EventName<C>, Cx>) => void, options?: SubscribeOptions): () => void;
47
+ };
48
+
49
+ export type { BrokerEvents as B, Catalog as C, EventBroker as E, Shape as S, TrackingEvent as T, EventName as a, EventData as b, CatalogEntry as c, Composition as d, EventMeta as e, SubscribeOptions as f };
@@ -0,0 +1,33 @@
1
+ # Vendor-neutral events, mapped per Destination
2
+
3
+ Date: 2026-11-13
4
+
5
+ Status: proposed
6
+
7
+ ## Context
8
+
9
+ The same shopper action feeds several Destinations (GA4, Shopify Analytics) with different event names, schemas and consent needs. Ecommerce reports are only useful with an action's surroundings: which List, Promotion and Location an Item sat in. Passing those by hand through every component is where tracking usually breaks.
10
+
11
+ Options considered:
12
+
13
+ - **Vendor calls in components** (`gtag(...)`, `Shopify.analytics.publish(...)`). Every component knows every vendor schema, consent is checked in N places, and adding a Destination touches the whole codebase.
14
+ - **GTM's `dataLayer` as the hub.** Untyped and GA4-shaped, with mapping logic in a GTM container outside version control and review.
15
+ - **A hosted CDP** (Segment, RudderStack). Cost and a third party in the data path for what is mostly fan-out to two Destinations.
16
+ - **Composition through React context.** Needs client components around every List and Item, and misses markup rendered by server components or a CMS.
17
+
18
+ ## Decision
19
+
20
+ One in-page pipeline, described in [events.md](../events.md):
21
+
22
+ - **Sources publish vendor-neutral Events** declared in a typed Event Catalog to a Broker, which stamps their Meta and Context and keeps them in order.
23
+ - **The Broker only publishes and subscribes.** The Current Page provides Context and tells Sources when the Page changes, and the Flow starts the Sources, so the Broker knows neither pages nor Sources.
24
+ - **Each Event is mapped per Destination,** gated by that Destination's Consent Requirement. Vendor names and fields exist only in Mappings.
25
+ - **Composition comes from Annotations** (`data-e`, `data-e-data`) in the rendered markup, not from component props or context.
26
+ - **The cart is observed through Snapshots,** not add and remove calls, so it works with any cart state the storefront already has.
27
+
28
+ ## Consequences
29
+
30
+ - Adding or removing a Destination is a Mapping plus its adapter; no Source or component changes.
31
+ - Annotations are part of the analytics contract: renaming or removing a `data-e` attribute silently changes reports, so annotated markup needs the care of an API.
32
+ - Catalog shapes aren't validated at runtime, and DOM-derived Data is strings, so Mappings must tolerate missing or loosely typed fields.
33
+ - A CDP can still be added later as one more Destination.
package/docs/events.md ADDED
@@ -0,0 +1,187 @@
1
+ # Events module
2
+
3
+ The events module records what shoppers do on the storefront as vendor-neutral Events and delivers them, consent permitting, to each Destination in that Destination's own format. Why it's shaped this way: [ADR 001](decisions/001-vendor-neutral-event-pipeline.md).
4
+
5
+ ## Non-goals
6
+
7
+ - **Sending from the server.** Events are collected and delivered in the browser only.
8
+ - **Loading vendor scripts.** A Destination delivers to a vendor script the project already loads.
9
+ - **Deciding consent.** The module reads consent from a Consent Provider; it never shows a banner or stores an answer.
10
+ - **Tracking without Annotations.** Nothing in the markup is tracked unless an Annotation asks for it.
11
+ - **Validating Data at runtime.** Catalog shapes exist only in the types.
12
+ - **Persisting across page loads.** Events still held when the document unloads are lost.
13
+
14
+ ## Glossary
15
+
16
+ ### Events
17
+
18
+ | Term | Definition | Avoid |
19
+ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
20
+ | Event | A record of one thing a shopper did or saw, made of its Event Name, Data, Composition, Context and Meta. | Hit, tag, track call |
21
+ | Event Name | The `subject:action` identifier of an Event, e.g. `item:select`. Describes the shopper's action, never a vendor's event name. | Event type, action |
22
+ | Event Catalog | The single list of every Event Name the storefront may emit, with the shape of its Data and Composition. | Schema, registry |
23
+ | Data | The subject of an Event: the thing acted upon, such as a product variant or a form. | Payload, properties |
24
+ | Composition | The named surroundings the subject sat inside when the Event happened, such as its List, Promotion and Location. Each entry carries its own Data. | Parents, ancestors, container |
25
+ | Context | Facts about the browsing situation rather than the subject, such as current page and referrer. Its shape is the project's. | Environment, page data |
26
+ | Meta | The identity and ordering of an Event: its Event ID, Timestamp and Sequence Number. | |
27
+ | Event ID | The unique identifier of one Event, reused by every Destination so duplicates can be detected downstream. | Hit ID |
28
+ | Sequence Number | The position of an Event in the order the Broker accepted it. | Index, counter |
29
+
30
+ ### Composition roles
31
+
32
+ | Term | Definition | Avoid |
33
+ | --------- | ----------------------------------------------------------------------------- | ---------------------------- |
34
+ | Location | A named region of a page, such as a content block or section. | Section, block, slot |
35
+ | List | An ordered collection of Items shown together, such as a product grid. | Collection (Shopify's), grid |
36
+ | Item | A single product (variant) shown or acted upon. | Product card, tile |
37
+ | Promotion | Marketing content that frames an Item or Location, such as a campaign banner. | Campaign, banner |
38
+ | Form | A shopper-facing form whose submission is an Event, e.g. a newsletter signup. | |
39
+
40
+ ### Pipeline
41
+
42
+ | Term | Definition | Avoid |
43
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
44
+ | Broker | The in-page hub that accepts Events from Sources, stamps their Meta and Context, and hands them on in order. | Bus, dataLayer, emitter |
45
+ | Source | Anything that observes part of the storefront and publishes Events to the Broker. | Producer, publisher, tracker |
46
+ | DOM Source | The Source that turns shopper interaction with Annotated Elements into Events, using Detectors. | |
47
+ | Detector | One way the DOM Source notices something happened: Page views, Item selections, clicks, forms, videos, scroll depth or impressions. | Trigger (GTM's), listener, plugin |
48
+ | Annotation | Markup that declares an element's Roles, Flags and Data (`data-e`, `data-e-data`). | Data attributes, tagging |
49
+ | Annotated Element | An element with a Role in its Annotation; it contributes that Role and its Data to every Event inside it. | |
50
+ | Flag | A `data-e` word that opts an element in to a Detector (`click`, `video`, `detail`, `page`) without giving it a Role. | Marker, opt-in attribute |
51
+ | Impression | A Promotion, or an Item in a List, becoming visible to the shopper for the first time on a Page. | View, exposure |
52
+ | Page | One visit to a URL as the shopper experiences it, including client-side navigations. | Route, screen, pageview |
53
+ | Current Page | Tracks the current Page: reads its facts for Context, starts the next Page on `sync()` when the URL's key changed, and tells subscribed Sources when a Page ends and the next starts. | Page tracker, router, environment |
54
+ | Cart Source | The Source that derives cart Events by comparing successive Cart Snapshots. | |
55
+ | Cart Snapshot | The full contents of the cart at one moment, as the storefront knows it. | Cart state, cart diff |
56
+ | Cart Adapter | How the Cart Source reads a project's cart: its lines, a key per line and a quantity, e.g. `shopifyCart()` for Shopify carts. | Cart mapper, cart parser |
57
+
58
+ ### Delivery
59
+
60
+ | Term | Definition | Avoid |
61
+ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
62
+ | Destination | An external analytics service Events are delivered to, such as GA4 or Shopify Analytics. | Sink, integration, provider, vendor |
63
+ | Mapping | The per-Destination translation from an Event to zero or one Destination event. | Transform, adapter, converter |
64
+ | Mapped Destination | A Destination with its Mapping and Consent Requirement; `createDestinations()` gathers them for the Flow. | Route, router |
65
+ | Consent Requirement | The consent categories a Destination needs before it may receive Events; `none` means always. | Permission, gate |
66
+ | Consent Provider | The consent management platform that reports which categories the shopper granted, such as Cookiebot. | CMP adapter, cookie banner |
67
+ | Consent Sink | A platform that is told every consent answer so it can gate its own tracking, such as Shopify Customer Privacy. | Consent target, consent forwarder |
68
+ | Flow | The running pipeline connecting the Broker, the Sources, the Mapped Destinations and the Consent Provider; `startTracking()` starts it. | Analytics instance, pipeline |
69
+
70
+ ## Behavior rules
71
+
72
+ ### Lifecycle + SSR
73
+
74
+ | Behavior | Description |
75
+ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
76
+ | B-001 | Creating the Broker, Destinations and Sources has no side effects, so the modules that create them are safe to import on the server. |
77
+ | B-002 | Annotations are plain string attributes, so server components and CMS HTML render them without client JavaScript per element. |
78
+ | B-003 | Nothing is observed, held or delivered on the server; starting the Flow there does nothing. |
79
+ | B-004 | Starting the Flow subscribes it to the Broker with replay, starts the Sources and the Consent Provider, and delivers held Events in Sequence Number order. |
80
+ | B-005 | Starting the Flow again (e.g. after HMR) stops the previous Flow and its Sources first, so nothing is subscribed or listened to twice. |
81
+ | B-006 | The DOM Source reads server-rendered markup, so Impressions of content visible before hydration are recorded once the Flow starts. |
82
+ | B-007 | `currentPage.sync()` must be called on every client-side navigation, after the URL changed and before the new page's DOM is reported: in React, from a layout effect. It starts a new Page only when the URL's key (by default its pathname) changed; otherwise it does nothing. |
83
+ | B-008 | The DOM Source flushes when a Page ends and when the document is hidden, so batched Events survive navigation and tab close. |
84
+ | B-009 | Starting a new Page tells every subscribed Source the Page ends, then moves the Current Page on (the last URL seen on the previous Page, e.g. with its `?sort=`, becomes the referrer), then tells them the next Page started: every Source flushes under the old Page and resets under the new one. |
85
+
86
+ ### Events and the Catalog
87
+
88
+ | Behavior | Description |
89
+ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
90
+ | B-101 | Every Event Name is declared in the Event Catalog; publishing an undeclared name is a type error. |
91
+ | B-102 | Event Names follow `subject:action` and describe what the shopper did (`item:select`, not `select_item`). |
92
+ | B-103 | An Event is immutable once the Broker accepts it; Mappings must not mutate it. |
93
+ | B-104 | A Source accepts a Detector or Cart Adapter only when the catalog declares every Event Name it publishes, and every field the catalog declares for it accepts the type it's published with. Fields the catalog adds, such as `data-e-data` ones, or leaves out are fine. |
94
+
95
+ ### Broker
96
+
97
+ | Behavior | Description |
98
+ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
99
+ | B-201 | On accept, the Broker stamps Meta: a unique Event ID, a Timestamp and the next Sequence Number, counted per page load. |
100
+ | B-202 | On accept, the Broker reads Context from the reader it was given, so it reflects the moment of the action rather than the moment of delivery. Without a reader, Context is `undefined`. |
101
+ | B-203 | While no subscriber asked for replay, the Broker holds accepted Events, up to 100 by default; past it the oldest are dropped with a development warning. |
102
+ | B-205 | A subscriber asking for replay first receives the held Events, which are then no longer held; others receive only Events published after they subscribed. |
103
+ | B-204 | Every subscriber receives Events in Sequence Number order. |
104
+
105
+ ### DOM Source
106
+
107
+ | Behavior | Description |
108
+ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
109
+ | B-301 | `data-e` holds space-separated words in any order: Roles (`location`, `list`, `item`, `promotion`, `form`) make an Annotated Element; Flags (`click`, `video`, `detail`, `page`) opt it in to Detectors. An element may have several, e.g. `data-e="item detail"`. |
110
+ | B-302 | `data-e-data="key:value;key:value"` gives an Annotated Element literal Data. `\;` and `\\` stand for a `;` or `\` in a value; `annotate()` writes them. |
111
+ | B-303 | A bare `data-e-data="<key>"` on an element without `data-e` contributes its text as field `<key>` of the nearest Annotated Element above it; Flags in between never take fields away from it. |
112
+ | B-304 | Composition is built by walking up from the target, taking the nearest Annotated Element of each role; the target's own element is Data. |
113
+ | B-305 | A role with no Annotated Element above the target is absent from the Composition, not empty. |
114
+ | B-306 | An Impression is counted at most once per Annotated Element per Page. A Promotion's publishes `promotion:view`; Items' are batched per List into one `list:view` with each Item's `index`; Items outside a List aren't reported. |
115
+ | B-307 | A new Page publishes `page:view` (B-319), resets Impressions and scroll depth and refreshes Context. |
116
+ | B-308 | Links, buttons and videos are tracked only when opted in: by their own `click` / `video` Flag, else by the nearest `data-e-auto` on or above them (`links`, `buttons`, `forms`, `videos`, or `none` to opt out, also on the element itself), else by the Detector's `auto` option, off by default. |
117
+ | B-309 | A Form Annotation always tracks its form; other forms follow `data-e-auto` and the `auto` option. |
118
+ | B-310 | A tracked element's own `data-e-data` is merged into the Data the Detector derives, and wins on conflicts. |
119
+ | B-311 | A link click is outbound when it leads over http(s) to a host other than the page's and the configured internal hosts, and a download when it has a `download` attribute or a known file extension. |
120
+ | B-312 | `form:start` is published on the first input in a form per Page; `form:submit` on submission, with the submit button's text. Field values are never read. |
121
+ | B-313 | A video publishes `video:start` once per playback, each progress threshold once per playback, and `video:complete` when it ends; playing it again after that is a new playback. |
122
+ | B-314 | A link or button click in an Item publishes `item:select`, with the Item's `index` added when it's in a List; whether it counts as a List or Promotion selection is for Mappings to decide from its Composition. Clicks in an Item flagged `detail`, such as add to cart on its own detail page, select nothing; Items nested in it, like related products, still do. |
123
+ | B-315 | A link or button click in a Promotion outside any Item publishes `promotion:select`. Clicks elsewhere in an Item or Promotion, e.g. on an image or text, select nothing. |
124
+ | B-316 | `list:view` batches are published after a delay, before every link click is handled, when the document is hidden, and before a new Page, so they carry the Page they were seen on. |
125
+ | B-317 | `item:view` is published only for an Item flagged `detail` (`data-e="item detail"`, an item detail page), once per Item it shows, including when the same element shows another Item after a navigation. |
126
+ | B-318 | `only(detector, paths)` and `except(detector, paths)` limit a Detector to Pages whose URL does or doesn't match one of `paths` (exact pathname, pathname ending in `/*`, `RegExp` or function of the URL). It's decided at the start of each Page, so batches flushed when a Page ends follow the Page they were collected on. |
127
+ | B-319 | `page:view` is published once per Page: when the DOM Source starts and whenever a new Page starts, with the Data of every element flagged `page` (`data-e="page"`) merged in document order, later ones winning. A Page without one still publishes it, with empty Data. It reads the DOM at that moment, so page Annotations must be rendered by then, not behind a Suspense boundary; put them on elements without a Role, or that Role's Data is mixed in. |
128
+
129
+ ### Cart Source
130
+
131
+ | Behavior | Description |
132
+ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | B-401 | The Cart Source receives whole Cart Snapshots, never individual add or remove calls. |
134
+ | B-402 | Events come from the difference between the previous and new Snapshot: a quantity increase adds the difference, a decrease removes it. |
135
+ | B-403 | The first Snapshot after load is the baseline and produces no Events, so hydrating an existing cart isn't reported as adds. |
136
+ | B-404 | The Cart Source reads carts only through its Cart Adapter and assumes no platform's cart shape; `shopifyCart()` keys Shopify lines by variant, so a variant swap is a remove plus an add. |
137
+ | B-405 | The Cart Source diffs Snapshots whether or not the Flow is running; the Broker holds its Events until the Flow starts. Its `start()` does nothing yet; pass it in `sources` so whatever it later needs from the Flow is already wired. |
138
+
139
+ ### Destinations
140
+
141
+ | Behavior | Description |
142
+ | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
143
+ | B-501 | A Mapping is a pure function from one Event to zero or one Destination event `{ name, payload }`; returning nothing skips it. |
144
+ | B-502 | An Event without a Mapping for a Destination is never sent to it. |
145
+ | B-503 | Mappings produce the Destination's native names and fields; vendor knowledge lives only in Mappings and Destinations. |
146
+ | B-504 | Mappings pass the Event ID through wherever the Destination supports a dedupe key. |
147
+ | B-505 | One Destination failing never blocks or fails another. |
148
+
149
+ ### Consent
150
+
151
+ | Behavior | Description |
152
+ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
153
+ | B-601 | Consent Requirements use the module's own categories; the Consent Provider translates its platform's (e.g. Cookiebot's `statistics`). |
154
+ | B-602 | `none` means the Destination always receives Events; it's for Destinations that enforce consent themselves, like GA4 Consent Mode. |
155
+ | B-603 | While consent is unanswered, Events for a gated Destination are held (up to 100, oldest dropped); once granted they're delivered in order, once denied discarded. |
156
+ | B-604 | Withdrawing consent stops delivery from that moment; it never recalls what was sent. |
157
+ | B-605 | Every consent answer is applied to each Consent Sink before Destinations receive Events under it, including an answer already given when the Flow starts. |
158
+ | B-606 | A Consent Sink named like the Consent Provider is skipped, so consent is never written back to its source. |
159
+ | B-607 | One Consent Sink failing never blocks another, or delivery. |
160
+ | B-608 | Shopify's Customer Privacy API counts once loaded; a headless store's placeholder allows everything until `consentTrackingApiLoaded`. |
161
+
162
+ ## Built-in Event Names
163
+
164
+ A Source's Event Names must be in the Event Catalog for it to be used (B-101). Each element's own Annotation Data is merged into the derived Data (B-310).
165
+
166
+ | Event Name | Published by | Data |
167
+ | ------------------ | --------------- | ----------------------------------------------------------------------- |
168
+ | `item:select` | `selections()` | `ItemSelectData`: the Item's Data, plus `index` in its List |
169
+ | `promotion:select` | `selections()` | The Promotion's Data |
170
+ | `promotion:view` | `impressions()` | The Promotion's Data |
171
+ | `list:view` | `impressions()` | `ListViewData`: the List's Data, plus `items` with their `index` |
172
+ | `item:view` | `detailViews()` | The detail Item's Data |
173
+ | `page:view` | `pageViews()` | The Data of every `data-e="page"` element |
174
+ | `link:click` | `clicks()` | `LinkClickData`: `url`, `text`, `outbound`, `download?` |
175
+ | `button:click` | `clicks()` | `ButtonClickData`: `text` |
176
+ | `form:start` | `forms()` | `FormEventData`: `id?`, `name?`, `destination?` |
177
+ | `form:submit` | `forms()` | `FormSubmitData`: as `form:start`, plus `submitText?`; no field values |
178
+ | `video:start` | `videos()` | `VideoEventData`: `url`, `title?`, `duration`, `currentTime`, `percent` |
179
+ | `video:progress` | `videos()` | `VideoEventData`, `percent` being the threshold reached |
180
+ | `video:complete` | `videos()` | `VideoEventData` |
181
+ | `page:scroll` | `scroll()` | `{ depth }`, the threshold reached |
182
+ | `cart:add` | Cart Source | `{ line, quantity }`, quantity added |
183
+ | `cart:remove` | Cart Source | `{ line, quantity }`, quantity removed |
184
+
185
+ ## Open questions
186
+
187
+ - **Embedded players.** `videos()` covers `<video>` elements; YouTube and Vimeo embeds need their players' APIs.