@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.
Files changed (69) hide show
  1. package/README.md +86 -208
  2. package/dist/{sources/cart → cart}/index.d.ts +4 -4
  3. package/dist/{sources/cart → cart}/index.js +13 -3
  4. package/dist/cart/index.js.map +1 -0
  5. package/dist/chunk-JZ6HFGVJ.js +163 -0
  6. package/dist/chunk-JZ6HFGVJ.js.map +1 -0
  7. package/dist/{compatibility-Dc1JmTeG.d.ts → compatibility-wHn2I_ws.d.ts} +2 -2
  8. package/dist/{consent/index.d.ts → consent-types-DgKtGapr.d.ts} +5 -1
  9. package/dist/{consent/cookiebot → cookiebot}/index.d.ts +1 -1
  10. package/dist/{consent/cookiebot → cookiebot}/index.js +1 -1
  11. package/dist/cookiebot/index.js.map +1 -0
  12. package/dist/destination-types-DNMBOW_e.d.ts +22 -0
  13. package/dist/devtools/index.d.ts +18 -0
  14. package/dist/devtools/index.js +299 -0
  15. package/dist/devtools/index.js.map +1 -0
  16. package/dist/{sources/dom → dom}/index.d.ts +34 -40
  17. package/dist/{sources/dom → dom}/index.js +149 -247
  18. package/dist/dom/index.js.map +1 -0
  19. package/dist/events/index.d.ts +3 -6
  20. package/dist/events/index.js +5 -4
  21. package/dist/events/index.js.map +1 -1
  22. package/dist/flow/index.d.ts +10 -8
  23. package/dist/flow/index.js +23 -9
  24. package/dist/flow/index.js.map +1 -1
  25. package/dist/google/index.d.ts +32 -0
  26. package/dist/google/index.js +66 -0
  27. package/dist/google/index.js.map +1 -0
  28. package/dist/{page → navigation}/index.d.ts +7 -12
  29. package/dist/{page → navigation}/index.js +4 -10
  30. package/dist/navigation/index.js.map +1 -0
  31. package/dist/{consent/onetrust → onetrust}/index.d.ts +1 -1
  32. package/dist/{consent/onetrust → onetrust}/index.js +1 -1
  33. package/dist/onetrust/index.js.map +1 -0
  34. package/dist/shopify/index.d.ts +45 -0
  35. package/dist/{consent/shopify → shopify}/index.js +48 -20
  36. package/dist/shopify/index.js.map +1 -0
  37. package/dist/{sources/index.d.ts → source-types-fJXZeF2Q.d.ts} +1 -1
  38. package/dist/{types-DfPz7mBl.d.ts → types-CZEg03xW.d.ts} +3 -7
  39. package/docs/annotations.md +104 -0
  40. package/docs/context.md +64 -0
  41. package/docs/decisions/001-vendor-neutral-event-pipeline.md +2 -2
  42. package/docs/decisions/002-data-per-annotation-word.md +34 -0
  43. package/docs/events.md +93 -84
  44. package/docs/setup.md +189 -0
  45. package/package.json +41 -69
  46. package/dist/consent/cookiebot/index.js.map +0 -1
  47. package/dist/consent/index.js +0 -3
  48. package/dist/consent/index.js.map +0 -1
  49. package/dist/consent/onetrust/index.js.map +0 -1
  50. package/dist/consent/shopify/index.d.ts +0 -13
  51. package/dist/consent/shopify/index.js.map +0 -1
  52. package/dist/destinations/ga4/index.d.ts +0 -16
  53. package/dist/destinations/ga4/index.js +0 -15
  54. package/dist/destinations/ga4/index.js.map +0 -1
  55. package/dist/destinations/index.d.ts +0 -9
  56. package/dist/destinations/index.js +0 -17
  57. package/dist/destinations/index.js.map +0 -1
  58. package/dist/destinations/shopify/index.d.ts +0 -12
  59. package/dist/destinations/shopify/index.js +0 -18
  60. package/dist/destinations/shopify/index.js.map +0 -1
  61. package/dist/page/index.js.map +0 -1
  62. package/dist/sources/cart/index.js.map +0 -1
  63. package/dist/sources/cart/shopify/index.d.ts +0 -28
  64. package/dist/sources/cart/shopify/index.js +0 -16
  65. package/dist/sources/cart/shopify/index.js.map +0 -1
  66. package/dist/sources/dom/index.js.map +0 -1
  67. package/dist/sources/index.js +0 -3
  68. package/dist/sources/index.js.map +0 -1
  69. package/dist/types-BfJsv8AV.d.ts +0 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildinams/tracking",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "author": "Build in Amsterdam <development@buildinamsterdam.com> (https://www.buildinamsterdam.com/)",
@@ -29,57 +29,41 @@
29
29
  "types": "./dist/events/index.d.ts",
30
30
  "default": "./dist/events/index.js"
31
31
  },
32
- "./page": {
33
- "types": "./dist/page/index.d.ts",
34
- "default": "./dist/page/index.js"
35
- },
36
32
  "./flow": {
37
33
  "types": "./dist/flow/index.d.ts",
38
34
  "default": "./dist/flow/index.js"
39
35
  },
40
- "./sources": {
41
- "types": "./dist/sources/index.d.ts",
42
- "default": "./dist/sources/index.js"
43
- },
44
- "./sources/dom": {
45
- "types": "./dist/sources/dom/index.d.ts",
46
- "default": "./dist/sources/dom/index.js"
47
- },
48
- "./sources/cart": {
49
- "types": "./dist/sources/cart/index.d.ts",
50
- "default": "./dist/sources/cart/index.js"
51
- },
52
- "./sources/cart/shopify": {
53
- "types": "./dist/sources/cart/shopify/index.d.ts",
54
- "default": "./dist/sources/cart/shopify/index.js"
36
+ "./dom": {
37
+ "types": "./dist/dom/index.d.ts",
38
+ "default": "./dist/dom/index.js"
55
39
  },
56
- "./consent": {
57
- "types": "./dist/consent/index.d.ts",
58
- "default": "./dist/consent/index.js"
40
+ "./navigation": {
41
+ "types": "./dist/navigation/index.d.ts",
42
+ "default": "./dist/navigation/index.js"
59
43
  },
60
- "./consent/cookiebot": {
61
- "types": "./dist/consent/cookiebot/index.d.ts",
62
- "default": "./dist/consent/cookiebot/index.js"
44
+ "./cart": {
45
+ "types": "./dist/cart/index.d.ts",
46
+ "default": "./dist/cart/index.js"
63
47
  },
64
- "./consent/onetrust": {
65
- "types": "./dist/consent/onetrust/index.d.ts",
66
- "default": "./dist/consent/onetrust/index.js"
48
+ "./devtools": {
49
+ "types": "./dist/devtools/index.d.ts",
50
+ "default": "./dist/devtools/index.js"
67
51
  },
68
- "./consent/shopify": {
69
- "types": "./dist/consent/shopify/index.d.ts",
70
- "default": "./dist/consent/shopify/index.js"
52
+ "./google": {
53
+ "types": "./dist/google/index.d.ts",
54
+ "default": "./dist/google/index.js"
71
55
  },
72
- "./destinations": {
73
- "types": "./dist/destinations/index.d.ts",
74
- "default": "./dist/destinations/index.js"
56
+ "./shopify": {
57
+ "types": "./dist/shopify/index.d.ts",
58
+ "default": "./dist/shopify/index.js"
75
59
  },
76
- "./destinations/ga4": {
77
- "types": "./dist/destinations/ga4/index.d.ts",
78
- "default": "./dist/destinations/ga4/index.js"
60
+ "./cookiebot": {
61
+ "types": "./dist/cookiebot/index.d.ts",
62
+ "default": "./dist/cookiebot/index.js"
79
63
  },
80
- "./destinations/shopify": {
81
- "types": "./dist/destinations/shopify/index.d.ts",
82
- "default": "./dist/destinations/shopify/index.js"
64
+ "./onetrust": {
65
+ "types": "./dist/onetrust/index.d.ts",
66
+ "default": "./dist/onetrust/index.js"
83
67
  }
84
68
  },
85
69
  "typesVersions": {
@@ -87,44 +71,32 @@
87
71
  "./events": [
88
72
  "./dist/events/index.d.ts"
89
73
  ],
90
- "./page": [
91
- "./dist/page/index.d.ts"
92
- ],
93
74
  "./flow": [
94
75
  "./dist/flow/index.d.ts"
95
76
  ],
96
- "./sources": [
97
- "./dist/sources/index.d.ts"
98
- ],
99
- "./sources/dom": [
100
- "./dist/sources/dom/index.d.ts"
101
- ],
102
- "./sources/cart": [
103
- "./dist/sources/cart/index.d.ts"
104
- ],
105
- "./sources/cart/shopify": [
106
- "./dist/sources/cart/shopify/index.d.ts"
77
+ "./dom": [
78
+ "./dist/dom/index.d.ts"
107
79
  ],
108
- "./consent": [
109
- "./dist/consent/index.d.ts"
80
+ "./navigation": [
81
+ "./dist/navigation/index.d.ts"
110
82
  ],
111
- "./consent/cookiebot": [
112
- "./dist/consent/cookiebot/index.d.ts"
83
+ "./cart": [
84
+ "./dist/cart/index.d.ts"
113
85
  ],
114
- "./consent/onetrust": [
115
- "./dist/consent/onetrust/index.d.ts"
86
+ "./devtools": [
87
+ "./dist/devtools/index.d.ts"
116
88
  ],
117
- "./consent/shopify": [
118
- "./dist/consent/shopify/index.d.ts"
89
+ "./google": [
90
+ "./dist/google/index.d.ts"
119
91
  ],
120
- "./destinations": [
121
- "./dist/destinations/index.d.ts"
92
+ "./shopify": [
93
+ "./dist/shopify/index.d.ts"
122
94
  ],
123
- "./destinations/ga4": [
124
- "./dist/destinations/ga4/index.d.ts"
95
+ "./cookiebot": [
96
+ "./dist/cookiebot/index.d.ts"
125
97
  ],
126
- "./destinations/shopify": [
127
- "./dist/destinations/shopify/index.d.ts"
98
+ "./onetrust": [
99
+ "./dist/onetrust/index.d.ts"
128
100
  ]
129
101
  }
130
102
  },
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/consent/cookiebot/cookiebot.ts"],"names":["cookiebot"],"mappings":";AASA,IAAM,MAAA,GAAS;AAAA,EACd,yBAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACD,CAAA;AAEA,IAAM,OAAO,MAAsB;AAClC,EAAA,MAAMA,aAAa,MAAA,CAA2B,SAAA;AAC9C,EAAA,IAAI,CAACA,UAAAA,EAAW,WAAA,IAAe,CAACA,UAAAA,CAAU,SAAS,OAAO,IAAA;AAC1D,EAAA,MAAM,EAAE,WAAA,EAAa,UAAA,EAAY,SAAA,KAAcA,UAAAA,CAAU,OAAA;AACzD,EAAA,OAAO,EAAE,SAAA,EAAW,IAAA,EAAM,WAAA,EAAa,SAAA,EAAW,YAAY,SAAA,EAAU;AACzE,CAAA;AAEO,IAAM,YAAY,OAAwB;AAAA,EAChD,IAAA,EAAM,WAAA;AAAA,EACN,GAAA,EAAK,IAAA;AAAA,EACL,UAAU,QAAA,EAAU;AACnB,IAAA,MAAM,QAAA,GAAW,MAAM,QAAA,CAAS,IAAA,EAAM,CAAA;AACtC,IAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,EAAQ,MAAA,CAAO,gBAAA,CAAiB,MAAM,QAAQ,CAAA;AACjE,IAAA,OAAO,MAAM;AACZ,MAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,EAAQ,MAAA,CAAO,mBAAA,CAAoB,MAAM,QAAQ,CAAA;AAAA,IACrE,CAAA;AAAA,EACD;AACD,CAAA","file":"index.js","sourcesContent":["import type { Consent, ConsentProvider } from \"..\";\n\ntype CookiebotGlobal = {\n\tCookiebot?: {\n\t\thasResponse?: boolean;\n\t\tconsent?: { preferences: boolean; statistics: boolean; marketing: boolean };\n\t};\n};\n\nconst EVENTS = [\n\t\"CookiebotOnConsentReady\",\n\t\"CookiebotOnAccept\",\n\t\"CookiebotOnDecline\",\n];\n\nconst read = (): Consent | null => {\n\tconst cookiebot = (window as CookiebotGlobal).Cookiebot;\n\tif (!cookiebot?.hasResponse || !cookiebot.consent) return null;\n\tconst { preferences, statistics, marketing } = cookiebot.consent;\n\treturn { necessary: true, preferences, analytics: statistics, marketing };\n};\n\nexport const cookiebot = (): ConsentProvider => ({\n\tname: \"cookiebot\",\n\tget: read,\n\tsubscribe(listener) {\n\t\tconst onChange = () => listener(read());\n\t\tfor (const name of EVENTS) window.addEventListener(name, onChange);\n\t\treturn () => {\n\t\t\tfor (const name of EVENTS) window.removeEventListener(name, onChange);\n\t\t};\n\t},\n});\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/consent/onetrust/onetrust.ts"],"names":[],"mappings":";AAYA,IAAM,cAAA,GAAkD;AAAA,EACvD,SAAA,EAAW,OAAA;AAAA,EACX,SAAA,EAAW,OAAA;AAAA,EACX,WAAA,EAAa,OAAA;AAAA,EACb,SAAA,EAAW;AACZ,CAAA;AAEO,IAAM,WAAW,CAAC,EAAE,MAAA,EAAO,GAAqB,EAAC,KAAuB;AAC9E,EAAA,MAAM,GAAA,GAAM,EAAE,GAAG,cAAA,EAAgB,GAAG,MAAA,EAAO;AAE3C,EAAA,MAAM,OAAO,MAAsB;AAClC,IAAA,MAAM,EAAE,QAAA,EAAU,oBAAA,EAAqB,GAAI,MAAA;AAC3C,IAAA,IAAI,CAAC,QAAA,EAAU,gBAAA,IAAmB,IAAK,oBAAA,KAAyB,MAAA;AAC/D,MAAA,OAAO,IAAA;AACR,IAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,oBAAA,CAAqB,MAAM,GAAG,CAAA,CAAE,MAAA,CAAO,OAAO,CAAC,CAAA;AACtE,IAAA,OAAO;AAAA,MACN,SAAA,EAAW,IAAA;AAAA,MACX,WAAA,EAAa,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,WAAW,CAAA;AAAA,MACvC,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,SAAS,CAAA;AAAA,MACnC,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,GAAA,CAAI,SAAS;AAAA,KACpC;AAAA,EACD,CAAA;AAEA,EAAA,OAAO;AAAA,IACN,IAAA,EAAM,UAAA;AAAA,IACN,GAAA,EAAK,IAAA;AAAA,IACL,UAAU,QAAA,EAAU;AACnB,MAAA,MAAM,QAAA,GAAW,MAAM,QAAA,CAAS,IAAA,EAAM,CAAA;AACtC,MAAA,MAAA,CAAO,gBAAA,CAAiB,yBAAyB,QAAQ,CAAA;AACzD,MAAA,OAAO,MACN,MAAA,CAAO,mBAAA,CAAoB,uBAAA,EAAyB,QAAQ,CAAA;AAAA,IAC9D;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import type { Consent, ConsentCategory, ConsentProvider } from \"..\";\n\nexport type OneTrustOptions = {\n\t/** OneTrust category ID per consent category; defaults to OneTrust's standard IDs. */\n\tgroups?: Partial<Record<ConsentCategory, string>>;\n};\n\ntype OneTrustGlobal = {\n\tOnetrustActiveGroups?: string;\n\tOneTrust?: { IsAlertBoxClosed?(): boolean };\n};\n\nconst DEFAULT_GROUPS: Record<ConsentCategory, string> = {\n\tnecessary: \"C0001\",\n\tanalytics: \"C0002\",\n\tpreferences: \"C0003\",\n\tmarketing: \"C0004\",\n};\n\nexport const onetrust = ({ groups }: OneTrustOptions = {}): ConsentProvider => {\n\tconst ids = { ...DEFAULT_GROUPS, ...groups };\n\n\tconst read = (): Consent | null => {\n\t\tconst { OneTrust, OnetrustActiveGroups } = window as OneTrustGlobal;\n\t\tif (!OneTrust?.IsAlertBoxClosed?.() || OnetrustActiveGroups === undefined)\n\t\t\treturn null;\n\t\tconst active = new Set(OnetrustActiveGroups.split(\",\").filter(Boolean));\n\t\treturn {\n\t\t\tnecessary: true,\n\t\t\tpreferences: active.has(ids.preferences),\n\t\t\tanalytics: active.has(ids.analytics),\n\t\t\tmarketing: active.has(ids.marketing),\n\t\t};\n\t};\n\n\treturn {\n\t\tname: \"onetrust\",\n\t\tget: read,\n\t\tsubscribe(listener) {\n\t\t\tconst onChange = () => listener(read());\n\t\t\twindow.addEventListener(\"OneTrustGroupsUpdated\", onChange);\n\t\t\treturn () =>\n\t\t\t\twindow.removeEventListener(\"OneTrustGroupsUpdated\", onChange);\n\t\t},\n\t};\n};\n"]}
@@ -1,13 +0,0 @@
1
- import { ConsentProvider, ConsentCategory, Consent, ConsentSink } from '../index.js';
2
-
3
- /** Reads consent from Shopify's Customer Privacy API, e.g. its privacy banner. */
4
- declare const shopifyConsent: () => ConsentProvider;
5
-
6
- type ShopifyCustomerPrivacyOptions = {
7
- /** What Shopify's `sale_of_data` follows: a consent category, or a function of the answer. */
8
- saleOfData?: ConsentCategory | ((consent: Consent) => boolean);
9
- };
10
- /** Forwards consent to Shopify's Customer Privacy API. */
11
- declare const shopifyCustomerPrivacy: ({ saleOfData, }?: ShopifyCustomerPrivacyOptions) => ConsentSink;
12
-
13
- export { type ShopifyCustomerPrivacyOptions, shopifyConsent, shopifyCustomerPrivacy };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/consent/shopify/customer-privacy-api.ts","../../../src/consent/shopify/shopify-consent.ts","../../../src/consent/shopify/shopify-customer-privacy.ts"],"names":[],"mappings":";;;AAqCO,IAAM,IAAA,GAAO,IAAI,IAAA,KAAoB;AAC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AAA,EAAW,SAAA,EAAW,WAAA,EAAY,GAAI,OAAA;AAC9C,IAAA,MAAM,YAAA,GACL,OAAO,UAAA,KAAe,UAAA,GACnB,WAAW,OAAO,CAAA,GAClB,QAAQ,UAAU,CAAA;AACtB,IAAA,mBAAA;AAAA,MAAoB,CAAC,QACpB,GAAA,CAAI,kBAAA;AAAA,QACH,EAAE,SAAA,EAAW,SAAA,EAAW,WAAA,EAAa,YAAA,EAAa;AAAA,QAClD,CAAC,MAAA,KAAW;AACX,UAAA,IAAI,MAAA,EAAQ,KAAA;AACX,YAAA,IAAA,CAAK,uCAAA,EAAyC,OAAO,KAAK,CAAA;AAAA,QAC5D;AAAA;AACD,KACD;AAAA,EACD;AACD,CAAA","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../../config\";\n\ntype ConsentValue = \"yes\" | \"no\" | \"\";\n\nexport type CustomerPrivacyApi = {\n\tsetTrackingConsent(\n\t\tconsent: {\n\t\t\tanalytics: boolean;\n\t\t\tmarketing: boolean;\n\t\t\tpreferences: boolean;\n\t\t\tsale_of_data: boolean;\n\t\t},\n\t\tcallback: (result?: { error?: unknown }) => void,\n\t): void;\n\tcurrentVisitorConsent(): {\n\t\tanalytics: ConsentValue;\n\t\tmarketing: ConsentValue;\n\t\tpreferences: ConsentValue;\n\t};\n\tshouldShowBanner(): boolean;\n\tanalyticsProcessingAllowed(): boolean;\n\tmarketingAllowed(): boolean;\n\tpreferencesProcessingAllowed(): boolean;\n\t/** Set on headless storefronts, by Shopify's scripts. */\n\tconsentStatus?: \"loading\" | \"loaded\";\n};\n\ntype ShopifyGlobal = {\n\tShopify?: {\n\t\tcustomerPrivacy?: Partial<CustomerPrivacyApi>;\n\t\tloadFeatures?(\n\t\t\tfeatures: { name: string; version: string }[],\n\t\t\tcallback: (error?: unknown) => void,\n\t\t): void;\n\t};\n};\n\nexport const warn = (...args: unknown[]) => {\n\tif (IS_DEVELOPMENT) console.warn(\"[tracking]\", ...args);\n};\n\n/** Fired on `document` by Shopify's scripts on headless storefronts once the API has loaded. */\nconst API_LOADED_EVENT = \"consentTrackingApiLoaded\";\n\n// Headless storefronts expose a placeholder first: without methods, then one that allows everything while loading.\nconst isLoaded = (\n\tapi: Partial<CustomerPrivacyApi> | undefined,\n): api is CustomerPrivacyApi =>\n\ttypeof api?.setTrackingConsent === \"function\" &&\n\tapi.consentStatus !== \"loading\";\n\n/** The API once it has loaded, else `undefined`. */\nexport const readCustomerPrivacy = () => {\n\tconst api = (window as ShopifyGlobal).Shopify?.customerPrivacy;\n\treturn isLoaded(api) ? api : undefined;\n};\n\n/** Calls back with the API once it has loaded: loading it on themes, waiting for Shopify's scripts on headless storefronts. */\nexport const withCustomerPrivacy = (\n\tcallback: (api: CustomerPrivacyApi) => void,\n) => {\n\tconst api = readCustomerPrivacy();\n\tif (api) return callback(api);\n\tconst shopify = (window as ShopifyGlobal).Shopify;\n\tif (!shopify?.loadFeatures) {\n\t\tdocument.addEventListener(\n\t\t\tAPI_LOADED_EVENT,\n\t\t\t() => {\n\t\t\t\tconst loaded = readCustomerPrivacy();\n\t\t\t\tif (loaded) callback(loaded);\n\t\t\t\telse warn(\"Shopify's Customer Privacy API didn't load\");\n\t\t\t},\n\t\t\t{ once: true },\n\t\t);\n\t\treturn;\n\t}\n\tshopify.loadFeatures(\n\t\t[{ name: \"consent-tracking-api\", version: \"0.1\" }],\n\t\t(error) => {\n\t\t\tconst loaded = readCustomerPrivacy();\n\t\t\tif (error || !loaded)\n\t\t\t\twarn(\"Shopify's Customer Privacy API didn't load\", error);\n\t\t\telse callback(loaded);\n\t\t},\n\t);\n};\n","import type { Consent, ConsentProvider } from \"..\";\nimport {\n\treadCustomerPrivacy,\n\twithCustomerPrivacy,\n} from \"./customer-privacy-api\";\n\nconst read = (): Consent | null => {\n\tconst api = readCustomerPrivacy();\n\tif (!api) return null;\n\tconst { analytics, marketing, preferences } = api.currentVisitorConsent();\n\t// Where no banner is required, Shopify's regional defaults are the answer.\n\tconst answered =\n\t\t!api.shouldShowBanner() ||\n\t\t[analytics, marketing, preferences].some(Boolean);\n\tif (!answered) return null;\n\treturn {\n\t\tnecessary: true,\n\t\tpreferences: api.preferencesProcessingAllowed(),\n\t\tanalytics: api.analyticsProcessingAllowed(),\n\t\tmarketing: api.marketingAllowed(),\n\t};\n};\n\n/** Reads consent from Shopify's Customer Privacy API, e.g. its privacy banner. */\nexport const shopifyConsent = (): ConsentProvider => ({\n\tname: \"shopify\",\n\tget: read,\n\tsubscribe(listener) {\n\t\tlet active = true;\n\t\tconst onChange = () => listener(read());\n\t\tdocument.addEventListener(\"visitorConsentCollected\", onChange);\n\t\twithCustomerPrivacy(() => {\n\t\t\tif (active) onChange();\n\t\t});\n\t\treturn () => {\n\t\t\tactive = false;\n\t\t\tdocument.removeEventListener(\"visitorConsentCollected\", onChange);\n\t\t};\n\t},\n});\n","import type { Consent, ConsentCategory, ConsentSink } from \"..\";\nimport { warn, withCustomerPrivacy } from \"./customer-privacy-api\";\n\nexport type ShopifyCustomerPrivacyOptions = {\n\t/** What Shopify's `sale_of_data` follows: a consent category, or a function of the answer. */\n\tsaleOfData?: ConsentCategory | ((consent: Consent) => boolean);\n};\n\n/** Forwards consent to Shopify's Customer Privacy API. */\nexport const shopifyCustomerPrivacy = ({\n\tsaleOfData = \"marketing\",\n}: ShopifyCustomerPrivacyOptions = {}): ConsentSink => ({\n\tname: \"shopify\",\n\tapply(consent) {\n\t\tconst { analytics, marketing, preferences } = consent;\n\t\tconst sale_of_data =\n\t\t\ttypeof saleOfData === \"function\"\n\t\t\t\t? saleOfData(consent)\n\t\t\t\t: consent[saleOfData];\n\t\twithCustomerPrivacy((api) =>\n\t\t\tapi.setTrackingConsent(\n\t\t\t\t{ analytics, marketing, preferences, sale_of_data },\n\t\t\t\t(result) => {\n\t\t\t\t\tif (result?.error)\n\t\t\t\t\t\twarn(\"Shopify rejected the tracking consent\", result.error);\n\t\t\t\t},\n\t\t\t),\n\t\t);\n\t},\n});\n"]}
@@ -1,16 +0,0 @@
1
- import { c as Destination } from '../../types-BfJsv8AV.js';
2
- import '../../consent/index.js';
3
- import '../../types-DfPz7mBl.js';
4
-
5
- type Ga4Event = {
6
- name: string;
7
- payload: Record<string, unknown>;
8
- };
9
- type Ga4Options = {
10
- /** The GTM data layer's global name. */
11
- dataLayerName?: string;
12
- };
13
- /** Pushes to GTM's data layer; GA4 Consent Mode in the container gates it. */
14
- declare const ga4: ({ dataLayerName, }?: Ga4Options) => Destination<Ga4Event>;
15
-
16
- export { type Ga4Event, type Ga4Options, ga4 };
@@ -1,15 +0,0 @@
1
- // src/destinations/ga4/ga4.ts
2
- var ga4 = ({
3
- dataLayerName = "dataLayer"
4
- } = {}) => ({
5
- name: "ga4",
6
- send({ name, payload }) {
7
- const target = window;
8
- const dataLayer = target[dataLayerName] ??= [];
9
- dataLayer.push({ event: name, ...payload });
10
- }
11
- });
12
-
13
- export { ga4 };
14
- //# sourceMappingURL=index.js.map
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/destinations/ga4/ga4.ts"],"names":[],"mappings":";AAUO,IAAM,MAAM,CAAC;AAAA,EACnB,aAAA,GAAgB;AACjB,CAAA,GAAgB,EAAC,MAA8B;AAAA,EAC9C,IAAA,EAAM,KAAA;AAAA,EACN,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,EAAQ,EAAG;AACvB,IAAA,MAAM,MAAA,GAAS,MAAA;AACf,IAAA,MAAM,SAAA,GAAa,MAAA,CAAO,aAAa,CAAA,KAAM,EAAC;AAC9C,IAAA,SAAA,CAAU,KAAK,EAAE,KAAA,EAAO,IAAA,EAAM,GAAG,SAAS,CAAA;AAAA,EAC3C;AACD,CAAA","file":"index.js","sourcesContent":["import type { Destination } from \"..\";\n\nexport type Ga4Event = { name: string; payload: Record<string, unknown> };\n\nexport type Ga4Options = {\n\t/** The GTM data layer's global name. */\n\tdataLayerName?: string;\n};\n\n/** Pushes to GTM's data layer; GA4 Consent Mode in the container gates it. */\nexport const ga4 = ({\n\tdataLayerName = \"dataLayer\",\n}: Ga4Options = {}): Destination<Ga4Event> => ({\n\tname: \"ga4\",\n\tsend({ name, payload }) {\n\t\tconst target = window as unknown as Record<string, unknown[] | undefined>;\n\t\tconst dataLayer = (target[dataLayerName] ??= []);\n\t\tdataLayer.push({ event: name, ...payload });\n\t},\n});\n"]}
@@ -1,9 +0,0 @@
1
- import { ConsentRequirement } from '../consent/index.js';
2
- import { C as Catalog, B as BrokerEvents } from '../types-DfPz7mBl.js';
3
- import { M as MappedDestination, D as Destinations, a as DestinationEvent, C as ConsentedDestination, b as Mapping, c as Destination } from '../types-BfJsv8AV.js';
4
-
5
- declare const withConsent: <E extends DestinationEvent>(destination: Destination<E>, requires: ConsentRequirement) => ConsentedDestination<E>;
6
- declare const map: <C extends Catalog, E extends DestinationEvent, Cx>({ destination, requires }: ConsentedDestination<E>, mapping: NoInfer<Mapping<C, E, Cx>>) => MappedDestination<C, Cx>;
7
- declare const createDestinations: <C extends Catalog, Cx>(events: BrokerEvents<C, Cx>, mapped: MappedDestination<C, Cx>[]) => Destinations<C, Cx>;
8
-
9
- export { ConsentedDestination, Destination, DestinationEvent, Destinations, MappedDestination, Mapping, createDestinations, map, withConsent };
@@ -1,17 +0,0 @@
1
- // src/destinations/create-destinations.ts
2
- var withConsent = (destination, requires) => ({ destination, requires });
3
- var map = ({ destination, requires }, mapping) => ({
4
- name: destination.name,
5
- requires,
6
- deliver(event) {
7
- const toEvent = mapping[event.name];
8
- const mapped = toEvent?.(event);
9
- if (!mapped) return false;
10
- return destination.send(mapped);
11
- }
12
- });
13
- var createDestinations = (events, mapped) => ({ events, mapped });
14
-
15
- export { createDestinations, map, withConsent };
16
- //# sourceMappingURL=index.js.map
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/destinations/create-destinations.ts"],"names":[],"mappings":";AAgBO,IAAM,cAAc,CAC1B,WAAA,EACA,QAAA,MAC8B,EAAE,aAAa,QAAA,EAAS;AAEhD,IAAM,MAAM,CAClB,EAAE,WAAA,EAAa,QAAA,IAEf,OAAA,MAC+B;AAAA,EAC/B,MAAM,WAAA,CAAY,IAAA;AAAA,EAClB,QAAA;AAAA,EACA,QAAQ,KAAA,EAAO;AACd,IAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA;AAGlC,IAAA,MAAM,MAAA,GAAS,UAAU,KAAK,CAAA;AAC9B,IAAA,IAAI,CAAC,QAAQ,OAAO,KAAA;AACpB,IAAA,OAAO,WAAA,CAAY,KAAK,MAAM,CAAA;AAAA,EAC/B;AACD,CAAA;AAEO,IAAM,qBAAqB,CACjC,MAAA,EACA,MAAA,MAC0B,EAAE,QAAQ,MAAA,EAAO","file":"index.js","sourcesContent":["import type { ConsentRequirement } from \"../consent\";\nimport type {\n\tBrokerEvents,\n\tCatalog,\n\tEventName,\n\tTrackingEvent,\n} from \"../events\";\nimport type {\n\tConsentedDestination,\n\tDestination,\n\tDestinationEvent,\n\tDestinations,\n\tMappedDestination,\n\tMapping,\n} from \"./types\";\n\nexport const withConsent = <E extends DestinationEvent>(\n\tdestination: Destination<E>,\n\trequires: ConsentRequirement,\n): ConsentedDestination<E> => ({ destination, requires });\n\nexport const map = <C extends Catalog, E extends DestinationEvent, Cx>(\n\t{ destination, requires }: ConsentedDestination<E>,\n\t// Only createDestinations()'s catalog decides C and Cx, so a Mapping ignoring its Event still gets typed.\n\tmapping: NoInfer<Mapping<C, E, Cx>>,\n): MappedDestination<C, Cx> => ({\n\tname: destination.name,\n\trequires,\n\tdeliver(event) {\n\t\tconst toEvent = mapping[event.name] as\n\t\t\t| ((event: TrackingEvent<C, EventName<C>, Cx>) => E | null | undefined)\n\t\t\t| undefined;\n\t\tconst mapped = toEvent?.(event);\n\t\tif (!mapped) return false;\n\t\treturn destination.send(mapped);\n\t},\n});\n\nexport const createDestinations = <C extends Catalog, Cx>(\n\tevents: BrokerEvents<C, Cx>,\n\tmapped: MappedDestination<C, Cx>[],\n): Destinations<C, Cx> => ({ events, mapped });\n"]}
@@ -1,12 +0,0 @@
1
- import { c as Destination } from '../../types-BfJsv8AV.js';
2
- import '../../consent/index.js';
3
- import '../../types-DfPz7mBl.js';
4
-
5
- type ShopifyEvent = {
6
- name: string;
7
- payload: Record<string, unknown>;
8
- };
9
- /** Publishes to Shopify's analytics bus, `Shopify.analytics.publish()`. */
10
- declare const shopify: () => Destination<ShopifyEvent>;
11
-
12
- export { type ShopifyEvent, shopify };
@@ -1,18 +0,0 @@
1
- import { IS_DEVELOPMENT } from '../../chunk-KLN5K6PR.js';
2
-
3
- // src/destinations/shopify/shopify.ts
4
- var shopify = () => ({
5
- name: "shopify",
6
- send({ name, payload }) {
7
- const analytics = window.Shopify?.analytics;
8
- if (analytics) analytics.publish(name, payload);
9
- else if (IS_DEVELOPMENT)
10
- console.warn(
11
- `[tracking] Shopify.analytics isn't loaded; "${name}" not sent.`
12
- );
13
- }
14
- });
15
-
16
- export { shopify };
17
- //# sourceMappingURL=index.js.map
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/destinations/shopify/shopify.ts"],"names":[],"mappings":";;;AAYO,IAAM,UAAU,OAAkC;AAAA,EACxD,IAAA,EAAM,SAAA;AAAA,EACN,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,EAAQ,EAAG;AACvB,IAAA,MAAM,SAAA,GAAa,OAAyB,OAAA,EAAS,SAAA;AACrD,IAAA,IAAI,SAAA,EAAW,SAAA,CAAU,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AAAA,SAAA,IACrC,cAAA;AACR,MAAA,OAAA,CAAQ,IAAA;AAAA,QACP,+CAA+C,IAAI,CAAA,WAAA;AAAA,OACpD;AAAA,EACF;AACD,CAAA","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../../config\";\nimport type { Destination } from \"..\";\n\nexport type ShopifyEvent = { name: string; payload: Record<string, unknown> };\n\ntype ShopifyGlobal = {\n\tShopify?: {\n\t\tanalytics?: { publish(name: string, payload: unknown): void };\n\t};\n};\n\n/** Publishes to Shopify's analytics bus, `Shopify.analytics.publish()`. */\nexport const shopify = (): Destination<ShopifyEvent> => ({\n\tname: \"shopify\",\n\tsend({ name, payload }) {\n\t\tconst analytics = (window as ShopifyGlobal).Shopify?.analytics;\n\t\tif (analytics) analytics.publish(name, payload);\n\t\telse if (IS_DEVELOPMENT)\n\t\t\tconsole.warn(\n\t\t\t\t`[tracking] Shopify.analytics isn't loaded; \"${name}\" not sent.`,\n\t\t\t);\n\t},\n});\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/page/create-current-page.ts"],"names":[],"mappings":";;;AA8BO,IAAM,oBAAoB,CAAC;AAAA,EACjC,GAAA,GAAM,CAAC,GAAA,KAAQ,GAAA,CAAI;AACpB,CAAA,GAAwB,EAAC,KAAmB;AAC3C,EAAA,MAAM,SAAA,uBAAgB,GAAA,EAAkB;AACxC,EAAA,MAAM,MAAA,GAAS,CAAC,IAAA,EAAyB,UAAA,KAA+B;AACvE,IAAA,KAAA,MAAW,YAAY,UAAA,EAAY;AAClC,MAAA,IAAI;AACH,QAAA,QAAA,CAAS,IAAI,CAAA,IAAI;AAAA,MAClB,SAAS,KAAA,EAAO;AACf,QAAA,IAAI,cAAA,EAAgB,OAAA,CAAQ,KAAA,CAAM,KAAK,CAAA;AAAA,MACxC;AAAA,IACD;AAAA,EACD,CAAA;AACA,EAAA,IAAI,IAAA;AAEJ,EAAA,MAAM,OAAA,GAAU,MACd,IAAA,KAAS;AAAA,IACT,KAAK,GAAA,CAAI,IAAI,GAAA,CAAI,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,IAC/B,KAAK,QAAA,CAAS,IAAA;AAAA,IACd,UAAU,QAAA,CAAS;AAAA,GACpB;AAED,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAA,EAAQ;AAE3C,EAAA,OAAO;AAAA,IACN,MAAM,OAAO;AAAA,MACZ,KAAK,QAAA,CAAS,IAAA;AAAA,MACd,MAAM,QAAA,CAAS,QAAA;AAAA,MACf,OAAO,QAAA,CAAS,KAAA;AAAA,MAChB,QAAA,EAAU,SAAQ,CAAE,QAAA;AAAA,MACpB,QAAA,EAAU,QAAA,CAAS,eAAA,CAAgB,IAAA,IAAQ,SAAA,CAAU;AAAA,KACtD,CAAA;AAAA,IACA,IAAA,GAAO;AACN,MAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACnC,MAAA,MAAM,WAAW,OAAA,EAAQ;AACzB,MAAA,MAAM,OAAO,GAAA,CAAI,IAAI,GAAA,CAAI,QAAA,CAAS,IAAI,CAAC,CAAA;AACvC,MAAA,IAAI,IAAA,KAAS,SAAS,GAAA,EAAK;AAC1B,QAAA,QAAA,CAAS,MAAM,QAAA,CAAS,IAAA;AACxB,QAAA;AAAA,MACD;AAEA,MAAA,MAAM,UAAA,GAAa,CAAC,GAAG,SAAS,CAAA;AAChC,MAAA,MAAA,CAAO,SAAS,UAAU,CAAA;AAC1B,MAAA,IAAA,GAAO,EAAE,KAAK,IAAA,EAAM,GAAA,EAAK,SAAS,IAAA,EAAM,QAAA,EAAU,SAAS,GAAA,EAAI;AAC/D,MAAA,MAAA,CAAO,SAAS,UAAU,CAAA;AAAA,IAC3B,CAAA;AAAA,IACA,UAAU,QAAA,EAAU;AACnB,MAAA,SAAA,CAAU,IAAI,QAAQ,CAAA;AACtB,MAAA,OAAO,MAAM;AACZ,QAAA,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,MAC1B,CAAA;AAAA,IACD;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import { IS_DEVELOPMENT } from \"../config\";\n\nexport type PageFacts = {\n\turl: string;\n\tpath: string;\n\ttitle: string;\n\treferrer: string;\n\tlanguage: string;\n};\n\nexport type PageListener = {\n\t/** The Page is ending; still the current one. */\n\tleave?(): void;\n\t/** The next Page has started. */\n\tenter?(): void;\n};\n\nexport type CurrentPage = {\n\tread(): PageFacts;\n\t/** Starts the next Page if the URL's key changed since the last call; call it after every client-side navigation. */\n\tsync(): void;\n\t/** Every listener's `leave()` runs before the Page changes, every `enter()` after. */\n\tsubscribe(listener: PageListener): () => void;\n};\n\nexport type CurrentPageOptions = {\n\t/** What makes a URL another Page; by default its pathname, so query and hash changes aren't. */\n\tkey?: (url: URL) => string;\n};\n\nexport const createCurrentPage = ({\n\tkey = (url) => url.pathname,\n}: CurrentPageOptions = {}): CurrentPage => {\n\tconst listeners = new Set<PageListener>();\n\tconst notify = (step: \"leave\" | \"enter\", subscribed: PageListener[]) => {\n\t\tfor (const listener of subscribed) {\n\t\t\ttry {\n\t\t\t\tlistener[step]?.();\n\t\t\t} catch (error) {\n\t\t\t\tif (IS_DEVELOPMENT) console.error(error);\n\t\t\t}\n\t\t}\n\t};\n\tlet page: { key: string; url: string; referrer: string } | undefined;\n\n\tconst current = () =>\n\t\t(page ??= {\n\t\t\tkey: key(new URL(location.href)),\n\t\t\turl: location.href,\n\t\t\treferrer: document.referrer,\n\t\t});\n\t// The URL it was created on is the first Page, even if the first `sync()` comes after a navigation.\n\tif (typeof window !== \"undefined\") current();\n\n\treturn {\n\t\tread: () => ({\n\t\t\turl: location.href,\n\t\t\tpath: location.pathname,\n\t\t\ttitle: document.title,\n\t\t\treferrer: current().referrer,\n\t\t\tlanguage: document.documentElement.lang || navigator.language,\n\t\t}),\n\t\tsync() {\n\t\t\tif (typeof window === \"undefined\") return;\n\t\t\tconst previous = current();\n\t\t\tconst next = key(new URL(location.href));\n\t\t\tif (next === previous.key) {\n\t\t\t\tprevious.url = location.href;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst subscribed = [...listeners];\n\t\t\tnotify(\"leave\", subscribed);\n\t\t\tpage = { key: next, url: location.href, referrer: previous.url };\n\t\t\tnotify(\"enter\", subscribed);\n\t\t},\n\t\tsubscribe(listener) {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.del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I,KAAA,GAAQ,GAAG,OAAA,CAAQ,UAAA,EAAY,EAAE,IAAA,EAAM,QAAA,EAAU,OAAO,CAAA;AAC5D,UAAA,IAAI,KAAA,GAAQ,GAAG,OAAA,CAAQ,aAAA,EAAe,EAAE,IAAA,EAAM,QAAA,EAAU,CAAC,KAAA,EAAO,CAAA;AAAA,QACjE;AAAA,MACD;AACA,MAAA,QAAA,GAAW,IAAA;AAAA,IACZ;AAAA,GACD;AACD","file":"index.js","sourcesContent":["import type {\n\tCatalog,\n\tCatalogEntry,\n\tEventBroker,\n\tRequireCompatible,\n} from \"../../events\";\nimport type { Source } from \"../types\";\n\nexport type CartChange<Line> = { line: Line; quantity: number };\n\n/** How the Cart Source reads a cart; see `shopifyCart()` in `/sources/cart/shopify`. */\nexport type CartAdapter<Cart, Line> = {\n\tlines(cart: Cart): readonly Line[];\n\t/** Identifies a line across Snapshots; lines sharing a key are summed, and a changed key is a remove plus an add. */\n\tkey(line: Line): string;\n\tquantity(line: Line): number;\n};\n\ntype CartPublished<Line> = {\n\t\"cart:add\": CartChange<Line>;\n\t\"cart:remove\": CartChange<Line>;\n};\n\nexport type CartSource<Cart> = Source & {\n\t/** `null` or `undefined` while the cart isn't loaded; ignored. */\n\tsetSnapshot(cart: Cart | null | undefined): void;\n};\n\ntype CartCatalog = Catalog & Record<\"cart:add\" | \"cart:remove\", CatalogEntry>;\n\nexport const createCartSource = <C extends CartCatalog, Cart, Line>(\n\tbroker: EventBroker<C>,\n\t{\n\t\tlines,\n\t\tkey,\n\t\tquantity,\n\t}: CartAdapter<Cart, Line> & RequireCompatible<C, CartPublished<Line>>,\n): CartSource<Cart> => {\n\tlet previous: Map<string, { line: Line; total: number }> | undefined;\n\tconst publish = broker.publish as (\n\t\tname: \"cart:add\" | \"cart:remove\",\n\t\tdata: CartChange<Line>,\n\t) => void;\n\n\treturn {\n\t\tstart: () => () => {},\n\t\tsetSnapshot(cart) {\n\t\t\tif (cart == null) return;\n\t\t\t// Summed per key: e.g. the same variant can sit on several lines with different attributes.\n\t\t\tconst next = new Map<string, { line: Line; total: number }>();\n\t\t\tfor (const line of lines(cart)) {\n\t\t\t\tconst id = key(line);\n\t\t\t\tnext.set(id, {\n\t\t\t\t\tline,\n\t\t\t\t\ttotal: (next.get(id)?.total ?? 0) + quantity(line),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// The first Snapshot is the cart as loaded, not something the shopper did.\n\t\t\tif (previous) {\n\t\t\t\tfor (const [id, { line, total }] of previous)\n\t\t\t\t\tif (!next.has(id)) publish(\"cart:remove\", { line, quantity: total });\n\t\t\t\tfor (const [id, { line, total }] of next) {\n\t\t\t\t\tconst delta = total - (previous.get(id)?.total ?? 0);\n\t\t\t\t\tif (delta > 0) publish(\"cart:add\", { line, quantity: delta });\n\t\t\t\t\tif (delta < 0) publish(\"cart:remove\", { line, quantity: -delta });\n\t\t\t\t}\n\t\t\t}\n\t\t\tprevious = next;\n\t\t},\n\t};\n};\n"]}
@@ -1,28 +0,0 @@
1
- import { CartAdapter } from '../index.js';
2
- import '../../../compatibility-Dc1JmTeG.js';
3
- import '../../../types-DfPz7mBl.js';
4
- import '../../index.js';
5
-
6
- type ShopifyCartLine = {
7
- id: string;
8
- quantity: number;
9
- merchandise?: {
10
- id: string;
11
- };
12
- };
13
- /** Storefront API connections and Hydrogen's flattened arrays both fit. */
14
- type Lines<Line> = readonly Line[] | {
15
- nodes: readonly Line[];
16
- } | {
17
- edges: readonly {
18
- node: Line;
19
- }[];
20
- };
21
- type ShopifyCart = {
22
- lines?: Lines<ShopifyCartLine> | null;
23
- };
24
- type ShopifyCartLineOf<Cart extends ShopifyCart> = (NonNullable<Cart["lines"]> extends Lines<infer Line> ? Line : never) & ShopifyCartLine;
25
- /** Reads Storefront API and Hydrogen carts, keying lines by variant. */
26
- declare const shopifyCart: <Cart extends ShopifyCart = ShopifyCart>() => CartAdapter<Cart, ShopifyCartLineOf<Cart>>;
27
-
28
- export { type ShopifyCart, type ShopifyCartLine, type ShopifyCartLineOf, shopifyCart };
@@ -1,16 +0,0 @@
1
- // src/sources/cart/shopify/shopify-cart.ts
2
- var shopifyCart = () => ({
3
- lines(cart) {
4
- const lines = cart.lines;
5
- if (!lines) return [];
6
- if ("nodes" in lines) return lines.nodes;
7
- if ("edges" in lines) return lines.edges.map(({ node }) => node);
8
- return lines;
9
- },
10
- key: (line) => line.merchandise?.id ?? line.id,
11
- quantity: (line) => line.quantity
12
- });
13
-
14
- export { shopifyCart };
15
- //# sourceMappingURL=index.js.map
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/sources/cart/shopify/shopify-cart.ts"],"names":[],"mappings":";AAwBO,IAAM,cAAc,OAEyB;AAAA,EACnD,MAAM,IAAA,EAAM;AACX,IAAA,MAAM,QAAQ,IAAA,CAAK,KAAA;AAInB,IAAA,IAAI,CAAC,KAAA,EAAO,OAAO,EAAC;AACpB,IAAA,IAAI,OAAA,IAAW,KAAA,EAAO,OAAO,KAAA,CAAM,KAAA;AACnC,IAAA,IAAI,OAAA,IAAW,KAAA,EAAO,OAAO,KAAA,CAAM,KAAA,CAAM,IAAI,CAAC,EAAE,IAAA,EAAK,KAAM,IAAI,CAAA;AAC/D,IAAA,OAAO,KAAA;AAAA,EACR,CAAA;AAAA,EACA,KAAK,CAAC,IAAA,KAAS,IAAA,CAAK,WAAA,EAAa,MAAM,IAAA,CAAK,EAAA;AAAA,EAC5C,QAAA,EAAU,CAAC,IAAA,KAAS,IAAA,CAAK;AAC1B,CAAA","file":"index.js","sourcesContent":["import type { CartAdapter } from \"..\";\n\nexport type ShopifyCartLine = {\n\tid: string;\n\tquantity: number;\n\tmerchandise?: { id: string };\n};\n\n/** Storefront API connections and Hydrogen's flattened arrays both fit. */\ntype Lines<Line> =\n\t| readonly Line[]\n\t| { nodes: readonly Line[] }\n\t| { edges: readonly { node: Line }[] };\n\nexport type ShopifyCart = { lines?: Lines<ShopifyCartLine> | null };\n\nexport type ShopifyCartLineOf<Cart extends ShopifyCart> = (NonNullable<\n\tCart[\"lines\"]\n> extends Lines<infer Line>\n\t? Line\n\t: never) &\n\tShopifyCartLine;\n\n/** Reads Storefront API and Hydrogen carts, keying lines by variant. */\nexport const shopifyCart = <\n\tCart extends ShopifyCart = ShopifyCart,\n>(): CartAdapter<Cart, ShopifyCartLineOf<Cart>> => ({\n\tlines(cart) {\n\t\tconst lines = cart.lines as\n\t\t\t| Lines<ShopifyCartLineOf<Cart>>\n\t\t\t| null\n\t\t\t| undefined;\n\t\tif (!lines) return [];\n\t\tif (\"nodes\" in lines) return lines.nodes;\n\t\tif (\"edges\" in lines) return lines.edges.map(({ node }) => node);\n\t\treturn lines;\n\t},\n\tkey: (line) => line.merchandise?.id ?? line.id,\n\tquantity: (line) => line.quantity,\n});\n"]}
@@ -1 +0,0 @@
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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AAA,CAAM,MAAM,CAAA;AAClC,QAAA,IAAI,CAAC,KAAA,EAAO;AACZ,QAAA,OAAA,CAAQ,gBAAA,EAAkB,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"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -1,30 +0,0 @@
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 };