@10x-media/analytics 1.0.0-beta.14 → 1.0.0-beta.15

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 (168) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/adapters/ga4/ga4.d.ts +7 -0
  3. package/dist/adapters/ga4/ga4.js +17 -3
  4. package/dist/adapters/ga4/ga4.js.map +1 -1
  5. package/dist/adapters/plausible/plausible.d.ts +6 -0
  6. package/dist/adapters/plausible/plausible.js +6 -3
  7. package/dist/adapters/plausible/plausible.js.map +1 -1
  8. package/dist/adapters/posthog/posthog.d.ts +7 -0
  9. package/dist/adapters/posthog/posthog.js +92 -19
  10. package/dist/adapters/posthog/posthog.js.map +1 -1
  11. package/dist/adapters/posthog/projectCheck.js +56 -0
  12. package/dist/adapters/posthog/projectCheck.js.map +1 -0
  13. package/dist/adapters/umami/umami.d.ts +6 -0
  14. package/dist/adapters/umami/umami.js +3 -1
  15. package/dist/adapters/umami/umami.js.map +1 -1
  16. package/dist/capture/trackerConfig.js +29 -6
  17. package/dist/capture/trackerConfig.js.map +1 -1
  18. package/dist/capture/withoutConsent.js +91 -0
  19. package/dist/capture/withoutConsent.js.map +1 -0
  20. package/dist/core/capture.d.ts +41 -11
  21. package/dist/core/captureOptions.js +97 -8
  22. package/dist/core/captureOptions.js.map +1 -1
  23. package/dist/core/contract.d.ts +25 -0
  24. package/dist/core/contract.js.map +1 -1
  25. package/dist/core/options.d.ts +24 -2
  26. package/dist/core/options.js.map +1 -1
  27. package/dist/core/sourceOptions.js +2 -1
  28. package/dist/core/sourceOptions.js.map +1 -1
  29. package/dist/exports/adapters/contract.d.ts +3 -3
  30. package/dist/exports/adapters/ga4.d.ts +4 -4
  31. package/dist/exports/adapters/native.d.ts +5 -5
  32. package/dist/exports/adapters/plausible.d.ts +4 -4
  33. package/dist/exports/adapters/posthog.d.ts +4 -4
  34. package/dist/exports/adapters/umami.d.ts +4 -4
  35. package/dist/exports/next.d.ts +4 -4
  36. package/dist/exports/react.d.ts +3 -2
  37. package/dist/exports/site.d.ts +2 -2
  38. package/dist/exports/testing.d.ts +4 -4
  39. package/dist/exports/tracker.d.ts +3 -2
  40. package/dist/exports/types.d.ts +5 -5
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +2 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/native/collections/hits.js +1 -0
  45. package/dist/native/collections/hits.js.map +1 -1
  46. package/dist/native/engine/engine.js +5 -1
  47. package/dist/native/engine/engine.js.map +1 -1
  48. package/dist/native/engine/planner.js +2 -1
  49. package/dist/native/engine/planner.js.map +1 -1
  50. package/dist/native/engine/toHit.js +4 -2
  51. package/dist/native/engine/toHit.js.map +1 -1
  52. package/dist/native/ingest/endpoint.js +5 -2
  53. package/dist/native/ingest/endpoint.js.map +1 -1
  54. package/dist/native/ingest/normalizeEvent.d.ts +6 -1
  55. package/dist/native/ingest/normalizeEvent.js +17 -7
  56. package/dist/native/ingest/normalizeEvent.js.map +1 -1
  57. package/dist/native/ingest/serverTrack.js +2 -1
  58. package/dist/native/ingest/serverTrack.js.map +1 -1
  59. package/dist/native/ingest/validate.js +3 -0
  60. package/dist/native/ingest/validate.js.map +1 -1
  61. package/dist/native/nativeAdapter.d.ts +10 -1
  62. package/dist/native/nativeAdapter.js +11 -1
  63. package/dist/native/nativeAdapter.js.map +1 -1
  64. package/dist/native/store/aggregate.js +1 -1
  65. package/dist/native/store/aggregate.js.map +1 -1
  66. package/dist/native/store/hitRow.js +3 -0
  67. package/dist/native/store/hitRow.js.map +1 -1
  68. package/dist/native/store/hits.js +3 -1
  69. package/dist/native/store/hits.js.map +1 -1
  70. package/dist/native/store/mongo/aggregatePipelines.js +10 -2
  71. package/dist/native/store/mongo/aggregatePipelines.js.map +1 -1
  72. package/dist/native/store/mongo/pipelines.js +15 -5
  73. package/dist/native/store/mongo/pipelines.js.map +1 -1
  74. package/dist/native/store/parts.js +9 -3
  75. package/dist/native/store/parts.js.map +1 -1
  76. package/dist/native/store/rawRead.js +6 -3
  77. package/dist/native/store/rawRead.js.map +1 -1
  78. package/dist/native/store/sql/aggregateSql.js +6 -2
  79. package/dist/native/store/sql/aggregateSql.js.map +1 -1
  80. package/dist/native/store/sql/columns.js +1 -0
  81. package/dist/native/store/sql/columns.js.map +1 -1
  82. package/dist/native/store/sql/compile.js +19 -7
  83. package/dist/native/store/sql/compile.js.map +1 -1
  84. package/dist/native/store/types.d.ts +7 -1
  85. package/dist/native/store/types.js +10 -0
  86. package/dist/native/store/types.js.map +1 -0
  87. package/dist/plugin/createRuntime.js +10 -1
  88. package/dist/plugin/createRuntime.js.map +1 -1
  89. package/dist/plugin/runtime.js.map +1 -1
  90. package/dist/providers/collection.d.ts +2 -0
  91. package/dist/providers/collection.js +22 -1
  92. package/dist/providers/collection.js.map +1 -1
  93. package/dist/providers/factory.d.ts +9 -1
  94. package/dist/providers/factory.js +14 -5
  95. package/dist/providers/factory.js.map +1 -1
  96. package/dist/providers/registry.js +2 -1
  97. package/dist/providers/registry.js.map +1 -1
  98. package/dist/react/AnalyticsProvider.d.ts +6 -0
  99. package/dist/react/AnalyticsProvider.js.map +1 -1
  100. package/dist/react/useAnalytics.js +9 -5
  101. package/dist/react/useAnalytics.js.map +1 -1
  102. package/dist/site/AnalyticsScripts.d.ts +4 -3
  103. package/dist/site/AnalyticsScripts.js +18 -4
  104. package/dist/site/AnalyticsScripts.js.map +1 -1
  105. package/dist/surfacing/todaySplit.js +7 -1
  106. package/dist/surfacing/todaySplit.js.map +1 -1
  107. package/dist/tracker/config.d.ts +26 -1
  108. package/dist/tracker/config.js.map +1 -1
  109. package/dist/tracker/createTracker.d.ts +2 -1
  110. package/dist/tracker/createTracker.js +91 -59
  111. package/dist/tracker/createTracker.js.map +1 -1
  112. package/dist/tracker/gate.d.ts +8 -0
  113. package/dist/tracker/gate.js +61 -11
  114. package/dist/tracker/gate.js.map +1 -1
  115. package/dist/tracker/loadScript.js +2 -1
  116. package/dist/tracker/loadScript.js.map +1 -1
  117. package/dist/tracker/registry.js +14 -3
  118. package/dist/tracker/registry.js.map +1 -1
  119. package/dist/tracker/sinks/createSink.js +27 -8
  120. package/dist/tracker/sinks/createSink.js.map +1 -1
  121. package/dist/tracker/sinks/ga4.js +38 -6
  122. package/dist/tracker/sinks/ga4.js.map +1 -1
  123. package/dist/tracker/sinks/native.js +17 -3
  124. package/dist/tracker/sinks/native.js.map +1 -1
  125. package/dist/tracker/sinks/plausible.js +8 -2
  126. package/dist/tracker/sinks/plausible.js.map +1 -1
  127. package/dist/tracker/sinks/posthog.js +108 -16
  128. package/dist/tracker/sinks/posthog.js.map +1 -1
  129. package/dist/tracker/sinks/umami.js +2 -2
  130. package/dist/tracker/sinks/umami.js.map +1 -1
  131. package/dist/tracker/sinks/vendor.js +25 -11
  132. package/dist/tracker/sinks/vendor.js.map +1 -1
  133. package/dist/tracker/types.d.ts +10 -3
  134. package/dist/translations/ar.js +7 -0
  135. package/dist/translations/ar.js.map +1 -1
  136. package/dist/translations/de.js +7 -0
  137. package/dist/translations/de.js.map +1 -1
  138. package/dist/translations/en.js +7 -0
  139. package/dist/translations/en.js.map +1 -1
  140. package/dist/translations/es.js +7 -0
  141. package/dist/translations/es.js.map +1 -1
  142. package/dist/translations/fr.js +7 -0
  143. package/dist/translations/fr.js.map +1 -1
  144. package/dist/translations/id.js +7 -0
  145. package/dist/translations/id.js.map +1 -1
  146. package/dist/translations/keys.d.ts +7 -0
  147. package/dist/translations/keys.js +8 -1
  148. package/dist/translations/keys.js.map +1 -1
  149. package/dist/translations/ko.js +7 -0
  150. package/dist/translations/ko.js.map +1 -1
  151. package/dist/translations/pt.js +7 -0
  152. package/dist/translations/pt.js.map +1 -1
  153. package/dist/translations/ru.js +7 -0
  154. package/dist/translations/ru.js.map +1 -1
  155. package/dist/translations/uk.js +7 -0
  156. package/dist/translations/uk.js.map +1 -1
  157. package/dist/translations/zh.js +7 -0
  158. package/dist/translations/zh.js.map +1 -1
  159. package/dist/view/consentShare.js +15 -0
  160. package/dist/view/consentShare.js.map +1 -0
  161. package/dist/view/sections/OverviewCards.js +38 -28
  162. package/dist/view/sections/OverviewCards.js.map +1 -1
  163. package/dist/widgets/notices.js +6 -1
  164. package/dist/widgets/notices.js.map +1 -1
  165. package/dist/widgets/readMeta.d.ts +4 -0
  166. package/dist/widgets/readMeta.js +5 -0
  167. package/dist/widgets/readMeta.js.map +1 -1
  168. package/package.json +4 -4
@@ -8,6 +8,7 @@ import { DEFAULT_AUTO_CAPTURE } from "../tracker/config.js";
8
8
  import { DEFAULT_TRACKER_SKIP } from "../tracker/skip.js";
9
9
  import { withExclusionPrelude } from "./exclusionPrelude.js";
10
10
  import { normalizeMountPath } from "./mountPath.js";
11
+ import { fullSnippetArgs, slotWithoutConsent, snippetModeArgs } from "./withoutConsent.js";
11
12
  import { formatAdminURL } from "payload/shared";
12
13
  //#region src/capture/trackerConfig.ts
13
14
  /**
@@ -91,6 +92,14 @@ const warnSharedVendor = (payload, args) => {
91
92
  warnedSharedVendor.add(payload);
92
93
  payload.logger?.warn(`analytics: the ${args.slot} slot resolved to "${args.adapterId}", a second ${args.kind} slot beside "${args.first.adapterId}" on the ${args.first.slot} slot. ${args.kind} runs one client per page, so two slots of it would share that client: neither slot's gate could be answered alone and the ${args.slot} slot's events could land in the other slot's project. The ${args.slot} slot is left out of the tracker config; only PostHog runs a second client beside the first. Logged once.`);
93
94
  };
95
+ /** The Payload instances that already logged a `capture.withoutConsent` function failing. */
96
+ const warnedWithoutConsent = /* @__PURE__ */ new WeakSet();
97
+ /** A `capture.withoutConsent` function that threw or answered nonsense, logged once per instance. */
98
+ const warnWithoutConsent = (payload, slot, err) => {
99
+ if (!payload || warnedWithoutConsent.has(payload)) return;
100
+ warnedWithoutConsent.add(payload);
101
+ payload.logger?.warn(`analytics: capture.withoutConsent failed for the ${slot} slot, which therefore sends nothing without consent: ${err instanceof Error ? err.message : String(err)}. Logged once.`);
102
+ };
94
103
  /**
95
104
  * The per-request tracker config, one entry per capturing slot in slot order. Public and anonymous
96
105
  * (the visitor's request, no user or cookies), so any failure drops a slot instead of erroring.
@@ -132,20 +141,34 @@ const resolveTrackerConfig = async (args) => {
132
141
  adapterId: adapter.id,
133
142
  kind
134
143
  }, (err) => req.payload?.logger?.warn(`analytics: capture.gate threw for the ${slot} slot, which waits: ${String(err)}`));
144
+ const withoutConsent = gated ? slotWithoutConsent({
145
+ slot,
146
+ adapterId: adapter.id,
147
+ kind,
148
+ capture,
149
+ option: runtime.captureWithoutConsent
150
+ }, (err) => warnWithoutConsent(req.payload, slot, err)) : void 0;
135
151
  try {
152
+ const snippetFor = (args) => withExclusionPrelude(capture.snippet({
153
+ path,
154
+ scope,
155
+ ...instance ? { instance } : {},
156
+ ...args
157
+ }), exclusion?.param);
158
+ const snippet = snippetFor(snippetModeArgs(withoutConsent));
159
+ const fullArgs = fullSnippetArgs(withoutConsent);
160
+ const fullSnippet = fullArgs ? snippetFor(fullArgs) : void 0;
136
161
  slots.push({
137
162
  slot,
138
163
  kind,
139
164
  adapterId: adapter.id,
140
165
  path,
141
- snippet: withExclusionPrelude(capture.snippet({
142
- path,
143
- scope,
144
- ...instance ? { instance } : {}
145
- }), exclusion?.param),
166
+ snippet,
167
+ ...fullSnippet && JSON.stringify(fullSnippet) !== JSON.stringify(snippet) ? { fullSnippet } : {},
146
168
  client: capture.client,
147
169
  ...instance ? { instance } : {},
148
- gated
170
+ gated,
171
+ ...withoutConsent ? { withoutConsent } : {}
149
172
  });
150
173
  filled.add(adapter.id);
151
174
  } catch (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"trackerConfig.js","names":[],"sources":["../../src/capture/trackerConfig.ts"],"sourcesContent":["import type { Payload, PayloadRequest, SanitizedConfig } from 'payload'\nimport { formatAdminURL } from 'payload/shared'\nimport type { ResolvedGoal } from '../goals/resolver'\nimport { apiPath, appPath } from '../plugin/apiPath'\nimport { analyticsRoutes } from '../plugin/routes'\nimport {\n\ttype AnalyticsRuntime,\n\tresolveCaptureScopeFor,\n\tresolveGoalsDetailedFor,\n} from '../plugin/runtime'\nimport {\n\ttype AdminDigest,\n\ttype CaptureClientKind,\n\ttype CaptureSlot,\n\tDEFAULT_AUTO_CAPTURE,\n\ttype TrackerConfig,\n\ttype TrackerExclusion,\n\ttype TrackerGoal,\n\ttype TrackerSlotConfig,\n} from '../tracker/config'\nimport { DEFAULT_TRACKER_SKIP } from '../tracker/skip'\nimport { captureRequest } from './captureRequest'\nimport { withExclusionPrelude } from './exclusionPrelude'\nimport { exclusionToken, exclusionTokenHash, publicDigest } from './exclusionToken'\nimport { normalizeMountPath } from './mountPath'\nimport { CAPTURE_SLOTS, gateHolds, resolveSlotAdapterFor } from './slots'\n\n/**\n * The admin's address as a page reaches it, behind the Next basePath, as digests: its origin only\n * when `serverURL` puts it on one, its path without a trailing slash.\n */\nconst adminDigest = (config: Partial<SanitizedConfig>): AdminDigest => {\n\tconst address = formatAdminURL({\n\t\tadminRoute: config.routes?.admin ?? '/admin',\n\t\tpath: '',\n\t\tserverURL: config.serverURL,\n\t\tincludeBasePath: true,\n\t})\n\tlet origin: string | undefined\n\tlet path = address\n\tif (/^https?:\\/\\//i.test(address)) {\n\t\ttry {\n\t\t\tconst url = new URL(address)\n\t\t\torigin = url.origin\n\t\t\tpath = url.pathname\n\t\t} catch {\n\t\t\t// A serverURL that does not parse: its digest matches no window, so no page reads as a preview.\n\t\t}\n\t}\n\treturn {\n\t\t...(origin === undefined ? {} : { origin: publicDigest(origin) }),\n\t\tpath: publicDigest(path.replace(/\\/+$/, '') || '/'),\n\t}\n}\n\n/** What the config says about skipping: the install's choice when not the default, and the admin. */\nconst skipFields = (\n\truntime: AnalyticsRuntime,\n\tconfig: Partial<SanitizedConfig>,\n\tdraft: boolean\n): Pick<TrackerConfig, 'skip' | 'draft' | 'admin'> => {\n\tconst skip = runtime.captureSkip ?? DEFAULT_TRACKER_SKIP\n\tconst changed =\n\t\tskip.automation !== DEFAULT_TRACKER_SKIP.automation ||\n\t\tskip.previews !== DEFAULT_TRACKER_SKIP.previews\n\treturn {\n\t\t...(changed ? { skip: { ...skip } } : {}),\n\t\t...(draft ? { draft: true } : {}),\n\t\t...(skip.previews ? { admin: adminDigest(config) } : {}),\n\t}\n}\n\nconst trackerGoals = (goals: ResolvedGoal[]): TrackerGoal[] =>\n\tgoals\n\t\t.filter((entry) => entry.source !== 'builtin')\n\t\t.map(({ goal: { slug, match, value, currency } }) => ({\n\t\t\tslug,\n\t\t\tmatch,\n\t\t\t...(value ? { value } : {}),\n\t\t\t...(currency ? { currency } : {}),\n\t\t}))\n\n/** The visit's scope, or null when the host's resolver has none or throws. */\nconst scopeFor = async (runtime: AnalyticsRuntime, req: PayloadRequest): Promise<string | null> => {\n\ttry {\n\t\treturn await resolveCaptureScopeFor(runtime, req)\n\t} catch (err) {\n\t\treq.payload?.logger?.warn(`analytics: tracker config scope resolution failed: ${String(err)}`)\n\t\treturn null\n\t}\n}\n\n/** The scope's merged goals, falling back to the config goals when the merge fails. */\nconst goalsFor = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): Promise<ResolvedGoal[]> => {\n\ttry {\n\t\treturn await resolveGoalsDetailedFor(runtime, req, scope)\n\t} catch (err) {\n\t\treq.payload?.logger?.warn(\n\t\t\t`analytics: tracker config goals resolution failed, falling back to config goals: ${String(err)}`\n\t\t)\n\t\treturn (runtime.goals ?? []).map((goal) => ({ goal, source: 'config' as const }))\n\t}\n}\n\n/** The scope's exclusion link as the tracker sees it: the token's hash, never the token. */\nconst exclusionFor = (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): TrackerExclusion | undefined => {\n\tconst secret = req.payload?.secret\n\tif (!runtime.exclusion || typeof secret !== 'string' || secret === '') {\n\t\treturn undefined\n\t}\n\treturn {\n\t\tparam: runtime.exclusion.param,\n\t\ttokenHash: exclusionTokenHash(exclusionToken(secret, scope)),\n\t}\n}\n\n/** The Payload instances that already logged a vendor filling both slots, so a busy site hears it once. */\nconst warnedSharedVendor = new WeakSet<Payload>()\n\n/**\n * The vendors whose browser SDK runs a second client beside the first, each with its own project,\n * gate and storage: a second slot of one of these kinds captures through a client named after it.\n */\nconst NAMED_CLIENT_KINDS: ReadonlySet<CaptureClientKind> = new Set<CaptureClientKind>(['posthog'])\n\n/** Why the second slot of one vendor kind is left out, logged once per instance. */\nconst warnSharedVendor = (\n\tpayload: Payload | undefined,\n\targs: { slot: CaptureSlot; adapterId: string; kind: CaptureClientKind; first: TrackerSlotConfig }\n): void => {\n\tif (!payload || warnedSharedVendor.has(payload)) {\n\t\treturn\n\t}\n\twarnedSharedVendor.add(payload)\n\tpayload.logger?.warn(\n\t\t`analytics: the ${args.slot} slot resolved to \"${args.adapterId}\", a second ${args.kind} slot beside \"${args.first.adapterId}\" on the ${args.first.slot} slot. ${args.kind} runs one client per page, so two slots of it would share that client: neither slot's gate could be answered alone and the ${args.slot} slot's events could land in the other slot's project. The ${args.slot} slot is left out of the tracker config; only PostHog runs a second client beside the first. Logged once.`\n\t)\n}\n\n/**\n * The per-request tracker config, one entry per capturing slot in slot order. Public and anonymous\n * (the visitor's request, no user or cookies), so any failure drops a slot instead of erroring.\n */\nexport const resolveTrackerConfig = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The page is rendered in draft mode, which `capture.skip.previews` leaves uncounted. */\n\tdraft?: boolean\n}): Promise<TrackerConfig> => {\n\tconst { runtime } = args\n\tconst req = captureRequest(args.req)\n\tconst config = req.payload?.config ?? {}\n\tconst routes = analyticsRoutes(req.payload?.config)\n\t// One scope resolution for the whole config: the slots and the goals must agree on it,\n\t// and the host's resolver can be as expensive as a database read.\n\tconst scope = await scopeFor(runtime, req)\n\tconst exclusion = exclusionFor(runtime, req, scope)\n\tconst slots: TrackerSlotConfig[] = []\n\tconst filled = new Set<string>()\n\tfor (const slot of CAPTURE_SLOTS) {\n\t\tconst adapter = await resolveSlotAdapterFor({ runtime, req, slot, scope })\n\t\tconst capture = adapter?.capture\n\t\t// One adapter fills one slot: two sinks for it would send every event twice.\n\t\tif (!adapter || !capture || filled.has(adapter.id)) {\n\t\t\tcontinue\n\t\t}\n\t\tconst kind = capture.client.kind\n\t\tconst first = slots.find((entry) => entry.kind === kind)\n\t\tif (first && !NAMED_CLIENT_KINDS.has(kind)) {\n\t\t\twarnSharedVendor(req.payload, { slot, adapterId: adapter.id, kind, first })\n\t\t\tcontinue\n\t\t}\n\t\tconst instance = first ? slot : undefined\n\t\tconst override = runtime.capturePaths?.[slot]\n\t\tconst path = override\n\t\t\t? appPath(normalizeMountPath(override))\n\t\t\t: apiPath(config, `${routes.proxy}/${slot}`)\n\t\tconst gated = gateHolds(runtime, { slot, adapterId: adapter.id, kind }, (err) =>\n\t\t\treq.payload?.logger?.warn(\n\t\t\t\t`analytics: capture.gate threw for the ${slot} slot, which waits: ${String(err)}`\n\t\t\t)\n\t\t)\n\t\ttry {\n\t\t\tslots.push({\n\t\t\t\tslot,\n\t\t\t\tkind,\n\t\t\t\tadapterId: adapter.id,\n\t\t\t\tpath,\n\t\t\t\tsnippet: withExclusionPrelude(\n\t\t\t\t\tcapture.snippet({ path, scope, ...(instance ? { instance } : {}) }),\n\t\t\t\t\texclusion?.param\n\t\t\t\t),\n\t\t\t\tclient: capture.client,\n\t\t\t\t...(instance ? { instance } : {}),\n\t\t\t\tgated,\n\t\t\t})\n\t\t\tfilled.add(adapter.id)\n\t\t} catch (err) {\n\t\t\treq.payload?.logger?.warn(\n\t\t\t\t`analytics: capture snippet for \"${adapter.id}\" failed, dropping the ${slot} slot: ${String(err)}`\n\t\t\t)\n\t\t}\n\t}\n\treturn {\n\t\tslots,\n\t\tautoCapture: runtime.autoCapture ?? DEFAULT_AUTO_CAPTURE,\n\t\tgoals: trackerGoals(await goalsFor(runtime, req, scope)),\n\t\tingestPath: apiPath(config, runtime.ingestPath ?? routes.ingest),\n\t\t...(exclusion ? { exclusion } : {}),\n\t\t...skipFields(runtime, config, args.draft === true),\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AAY,QAAQ,QAAQ,QAAQ,cAAc,OAAO,MAAM;EAC/D,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;EACjC,GAAG,WAAW,SAAS,QAAQ,KAAK,UAAU,IAAI;CACnD;AACD"}
1
+ {"version":3,"file":"trackerConfig.js","names":[],"sources":["../../src/capture/trackerConfig.ts"],"sourcesContent":["import type { Payload, PayloadRequest, SanitizedConfig } from 'payload'\nimport { formatAdminURL } from 'payload/shared'\nimport type { SnippetArgs } from '../core/capture'\nimport type { ResolvedGoal } from '../goals/resolver'\nimport { apiPath, appPath } from '../plugin/apiPath'\nimport { analyticsRoutes } from '../plugin/routes'\nimport {\n\ttype AnalyticsRuntime,\n\tresolveCaptureScopeFor,\n\tresolveGoalsDetailedFor,\n} from '../plugin/runtime'\nimport {\n\ttype AdminDigest,\n\ttype CaptureClientKind,\n\ttype CaptureSlot,\n\ttype CaptureSnippet,\n\tDEFAULT_AUTO_CAPTURE,\n\ttype TrackerConfig,\n\ttype TrackerExclusion,\n\ttype TrackerGoal,\n\ttype TrackerSlotConfig,\n} from '../tracker/config'\nimport { DEFAULT_TRACKER_SKIP } from '../tracker/skip'\nimport { captureRequest } from './captureRequest'\nimport { withExclusionPrelude } from './exclusionPrelude'\nimport { exclusionToken, exclusionTokenHash, publicDigest } from './exclusionToken'\nimport { normalizeMountPath } from './mountPath'\nimport { CAPTURE_SLOTS, gateHolds, resolveSlotAdapterFor } from './slots'\nimport { fullSnippetArgs, slotWithoutConsent, snippetModeArgs } from './withoutConsent'\n\n/**\n * The admin's address as a page reaches it, behind the Next basePath, as digests: its origin only\n * when `serverURL` puts it on one, its path without a trailing slash.\n */\nconst adminDigest = (config: Partial<SanitizedConfig>): AdminDigest => {\n\tconst address = formatAdminURL({\n\t\tadminRoute: config.routes?.admin ?? '/admin',\n\t\tpath: '',\n\t\tserverURL: config.serverURL,\n\t\tincludeBasePath: true,\n\t})\n\tlet origin: string | undefined\n\tlet path = address\n\tif (/^https?:\\/\\//i.test(address)) {\n\t\ttry {\n\t\t\tconst url = new URL(address)\n\t\t\torigin = url.origin\n\t\t\tpath = url.pathname\n\t\t} catch {\n\t\t\t// A serverURL that does not parse: its digest matches no window, so no page reads as a preview.\n\t\t}\n\t}\n\treturn {\n\t\t...(origin === undefined ? {} : { origin: publicDigest(origin) }),\n\t\tpath: publicDigest(path.replace(/\\/+$/, '') || '/'),\n\t}\n}\n\n/** What the config says about skipping: the install's choice when not the default, and the admin. */\nconst skipFields = (\n\truntime: AnalyticsRuntime,\n\tconfig: Partial<SanitizedConfig>,\n\tdraft: boolean\n): Pick<TrackerConfig, 'skip' | 'draft' | 'admin'> => {\n\tconst skip = runtime.captureSkip ?? DEFAULT_TRACKER_SKIP\n\tconst changed =\n\t\tskip.automation !== DEFAULT_TRACKER_SKIP.automation ||\n\t\tskip.previews !== DEFAULT_TRACKER_SKIP.previews\n\treturn {\n\t\t...(changed ? { skip: { ...skip } } : {}),\n\t\t...(draft ? { draft: true } : {}),\n\t\t...(skip.previews ? { admin: adminDigest(config) } : {}),\n\t}\n}\n\nconst trackerGoals = (goals: ResolvedGoal[]): TrackerGoal[] =>\n\tgoals\n\t\t.filter((entry) => entry.source !== 'builtin')\n\t\t.map(({ goal: { slug, match, value, currency } }) => ({\n\t\t\tslug,\n\t\t\tmatch,\n\t\t\t...(value ? { value } : {}),\n\t\t\t...(currency ? { currency } : {}),\n\t\t}))\n\n/** The visit's scope, or null when the host's resolver has none or throws. */\nconst scopeFor = async (runtime: AnalyticsRuntime, req: PayloadRequest): Promise<string | null> => {\n\ttry {\n\t\treturn await resolveCaptureScopeFor(runtime, req)\n\t} catch (err) {\n\t\treq.payload?.logger?.warn(`analytics: tracker config scope resolution failed: ${String(err)}`)\n\t\treturn null\n\t}\n}\n\n/** The scope's merged goals, falling back to the config goals when the merge fails. */\nconst goalsFor = async (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): Promise<ResolvedGoal[]> => {\n\ttry {\n\t\treturn await resolveGoalsDetailedFor(runtime, req, scope)\n\t} catch (err) {\n\t\treq.payload?.logger?.warn(\n\t\t\t`analytics: tracker config goals resolution failed, falling back to config goals: ${String(err)}`\n\t\t)\n\t\treturn (runtime.goals ?? []).map((goal) => ({ goal, source: 'config' as const }))\n\t}\n}\n\n/** The scope's exclusion link as the tracker sees it: the token's hash, never the token. */\nconst exclusionFor = (\n\truntime: AnalyticsRuntime,\n\treq: PayloadRequest,\n\tscope: string | null\n): TrackerExclusion | undefined => {\n\tconst secret = req.payload?.secret\n\tif (!runtime.exclusion || typeof secret !== 'string' || secret === '') {\n\t\treturn undefined\n\t}\n\treturn {\n\t\tparam: runtime.exclusion.param,\n\t\ttokenHash: exclusionTokenHash(exclusionToken(secret, scope)),\n\t}\n}\n\n/** The Payload instances that already logged a vendor filling both slots, so a busy site hears it once. */\nconst warnedSharedVendor = new WeakSet<Payload>()\n\n/**\n * The vendors whose browser SDK runs a second client beside the first, each with its own project,\n * gate and storage: a second slot of one of these kinds captures through a client named after it.\n */\nconst NAMED_CLIENT_KINDS: ReadonlySet<CaptureClientKind> = new Set<CaptureClientKind>(['posthog'])\n\n/** Why the second slot of one vendor kind is left out, logged once per instance. */\nconst warnSharedVendor = (\n\tpayload: Payload | undefined,\n\targs: { slot: CaptureSlot; adapterId: string; kind: CaptureClientKind; first: TrackerSlotConfig }\n): void => {\n\tif (!payload || warnedSharedVendor.has(payload)) {\n\t\treturn\n\t}\n\twarnedSharedVendor.add(payload)\n\tpayload.logger?.warn(\n\t\t`analytics: the ${args.slot} slot resolved to \"${args.adapterId}\", a second ${args.kind} slot beside \"${args.first.adapterId}\" on the ${args.first.slot} slot. ${args.kind} runs one client per page, so two slots of it would share that client: neither slot's gate could be answered alone and the ${args.slot} slot's events could land in the other slot's project. The ${args.slot} slot is left out of the tracker config; only PostHog runs a second client beside the first. Logged once.`\n\t)\n}\n\n/** The Payload instances that already logged a `capture.withoutConsent` function failing. */\nconst warnedWithoutConsent = new WeakSet<Payload>()\n\n/** A `capture.withoutConsent` function that threw or answered nonsense, logged once per instance. */\nconst warnWithoutConsent = (\n\tpayload: Payload | undefined,\n\tslot: CaptureSlot,\n\terr: unknown\n): void => {\n\tif (!payload || warnedWithoutConsent.has(payload)) {\n\t\treturn\n\t}\n\twarnedWithoutConsent.add(payload)\n\tpayload.logger?.warn(\n\t\t`analytics: capture.withoutConsent failed for the ${slot} slot, which therefore sends nothing without consent: ${err instanceof Error ? err.message : String(err)}. Logged once.`\n\t)\n}\n\n/**\n * The per-request tracker config, one entry per capturing slot in slot order. Public and anonymous\n * (the visitor's request, no user or cookies), so any failure drops a slot instead of erroring.\n */\nexport const resolveTrackerConfig = async (args: {\n\truntime: AnalyticsRuntime\n\treq: PayloadRequest\n\t/** The page is rendered in draft mode, which `capture.skip.previews` leaves uncounted. */\n\tdraft?: boolean\n}): Promise<TrackerConfig> => {\n\tconst { runtime } = args\n\tconst req = captureRequest(args.req)\n\tconst config = req.payload?.config ?? {}\n\tconst routes = analyticsRoutes(req.payload?.config)\n\t// One scope resolution for the whole config: the slots and the goals must agree on it,\n\t// and the host's resolver can be as expensive as a database read.\n\tconst scope = await scopeFor(runtime, req)\n\tconst exclusion = exclusionFor(runtime, req, scope)\n\tconst slots: TrackerSlotConfig[] = []\n\tconst filled = new Set<string>()\n\tfor (const slot of CAPTURE_SLOTS) {\n\t\tconst adapter = await resolveSlotAdapterFor({ runtime, req, slot, scope })\n\t\tconst capture = adapter?.capture\n\t\t// One adapter fills one slot: two sinks for it would send every event twice.\n\t\tif (!adapter || !capture || filled.has(adapter.id)) {\n\t\t\tcontinue\n\t\t}\n\t\tconst kind = capture.client.kind\n\t\tconst first = slots.find((entry) => entry.kind === kind)\n\t\tif (first && !NAMED_CLIENT_KINDS.has(kind)) {\n\t\t\twarnSharedVendor(req.payload, { slot, adapterId: adapter.id, kind, first })\n\t\t\tcontinue\n\t\t}\n\t\tconst instance = first ? slot : undefined\n\t\tconst override = runtime.capturePaths?.[slot]\n\t\tconst path = override\n\t\t\t? appPath(normalizeMountPath(override))\n\t\t\t: apiPath(config, `${routes.proxy}/${slot}`)\n\t\tconst gated = gateHolds(runtime, { slot, adapterId: adapter.id, kind }, (err) =>\n\t\t\treq.payload?.logger?.warn(\n\t\t\t\t`analytics: capture.gate threw for the ${slot} slot, which waits: ${String(err)}`\n\t\t\t)\n\t\t)\n\t\t// A slot the gate does not hold runs in full from page load, whatever withoutConsent says.\n\t\tconst withoutConsent = gated\n\t\t\t? slotWithoutConsent(\n\t\t\t\t\t{\n\t\t\t\t\t\tslot,\n\t\t\t\t\t\tadapterId: adapter.id,\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tcapture,\n\t\t\t\t\t\toption: runtime.captureWithoutConsent,\n\t\t\t\t\t},\n\t\t\t\t\t(err) => warnWithoutConsent(req.payload, slot, err)\n\t\t\t\t)\n\t\t\t: undefined\n\t\ttry {\n\t\t\tconst snippetFor = (args: Pick<SnippetArgs, 'mode' | 'withoutConsent'>): CaptureSnippet =>\n\t\t\t\twithExclusionPrelude(\n\t\t\t\t\tcapture.snippet({ path, scope, ...(instance ? { instance } : {}), ...args }),\n\t\t\t\t\texclusion?.param\n\t\t\t\t)\n\t\t\tconst snippet = snippetFor(snippetModeArgs(withoutConsent))\n\t\t\tconst fullArgs = fullSnippetArgs(withoutConsent)\n\t\t\tconst fullSnippet = fullArgs ? snippetFor(fullArgs) : undefined\n\t\t\tslots.push({\n\t\t\t\tslot,\n\t\t\t\tkind,\n\t\t\t\tadapterId: adapter.id,\n\t\t\t\tpath,\n\t\t\t\tsnippet,\n\t\t\t\t// Only where it differs: a vendor that stores nothing renders one snippet in every mode.\n\t\t\t\t...(fullSnippet && JSON.stringify(fullSnippet) !== JSON.stringify(snippet)\n\t\t\t\t\t? { fullSnippet }\n\t\t\t\t\t: {}),\n\t\t\t\tclient: capture.client,\n\t\t\t\t...(instance ? { instance } : {}),\n\t\t\t\tgated,\n\t\t\t\t...(withoutConsent ? { withoutConsent } : {}),\n\t\t\t})\n\t\t\tfilled.add(adapter.id)\n\t\t} catch (err) {\n\t\t\treq.payload?.logger?.warn(\n\t\t\t\t`analytics: capture snippet for \"${adapter.id}\" failed, dropping the ${slot} slot: ${String(err)}`\n\t\t\t)\n\t\t}\n\t}\n\treturn {\n\t\tslots,\n\t\tautoCapture: runtime.autoCapture ?? DEFAULT_AUTO_CAPTURE,\n\t\tgoals: trackerGoals(await goalsFor(runtime, req, scope)),\n\t\tingestPath: apiPath(config, runtime.ingestPath ?? routes.ingest),\n\t\t...(exclusion ? { exclusion } : {}),\n\t\t...skipFields(runtime, config, args.draft === true),\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,MAAM,eAAe,WAAkD;CACtE,MAAM,UAAU,eAAe;EAC9B,YAAY,OAAO,QAAQ,SAAS;EACpC,MAAM;EACN,WAAW,OAAO;EAClB,iBAAiB;CAClB,CAAC;CACD,IAAI;CACJ,IAAI,OAAO;CACX,IAAI,gBAAgB,KAAK,OAAO,GAC/B,IAAI;EACH,MAAM,MAAM,IAAI,IAAI,OAAO;EAC3B,SAAS,IAAI;EACb,OAAO,IAAI;CACZ,QAAQ,CAER;CAED,OAAO;EACN,GAAI,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,aAAa,MAAM,EAAE;EAC/D,MAAM,aAAa,KAAK,QAAQ,QAAQ,EAAE,KAAK,GAAG;CACnD;AACD;;AAGA,MAAM,cACL,SACA,QACA,UACqD;CACrD,MAAM,OAAO,QAAQ,eAAe;CAIpC,OAAO;EACN,GAHA,KAAK,eAAe,qBAAqB,cACzC,KAAK,aAAa,qBAAqB,WAEzB,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,IAAI,CAAC;EACvC,GAAI,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;EAC/B,GAAI,KAAK,WAAW,EAAE,OAAO,YAAY,MAAM,EAAE,IAAI,CAAC;CACvD;AACD;AAEA,MAAM,gBAAgB,UACrB,MACE,QAAQ,UAAU,MA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1,91 @@
1
+ import { isOneOf, kindOf } from "../core/values.js";
2
+ //#region src/capture/withoutConsent.ts
3
+ const CONSENT_PHASES = ["pending", "refused"];
4
+ const WITHOUT_CONSENT_LEVELS = ["cookieless", "off"];
5
+ /** `capture.withoutConsent` left unset. */
6
+ const DEFAULT_WITHOUT_CONSENT = {
7
+ pending: "cookieless",
8
+ refused: "cookieless"
9
+ };
10
+ /**
11
+ * A held slot's mode in one phase: the adapter's own setting, else the host's function, else the
12
+ * install's level, where `'cookieless'` takes the adapter's declared default. A function that
13
+ * throws or answers anything else is `off`, reported to `onError`, failing closed like the gate.
14
+ */
15
+ const heldSlotMode = (args, onError) => {
16
+ const { capture, option, phase, slot, adapterId, kind } = args;
17
+ const support = capture.cookieless;
18
+ if (!support) return "off";
19
+ if (capture.withoutConsent !== void 0) return capture.withoutConsent;
20
+ if (typeof option === "function") {
21
+ try {
22
+ const answer = option({
23
+ slot,
24
+ adapterId,
25
+ kind,
26
+ phase
27
+ });
28
+ if (isOneOf(WITHOUT_CONSENT_LEVELS, answer)) return answer;
29
+ onError?.(/* @__PURE__ */ new Error(`it answered ${kindOf(answer)}, not 'cookieless' or 'off'`));
30
+ } catch (err) {
31
+ onError?.(err);
32
+ }
33
+ return "off";
34
+ }
35
+ return (option ?? DEFAULT_WITHOUT_CONSENT)[phase] === "off" ? "off" : support.default ?? "cookieless";
36
+ };
37
+ /**
38
+ * A held slot's modes without consent, or undefined when both are `off`: such a slot's config is
39
+ * exactly 1.0.0-beta.14's.
40
+ */
41
+ const slotWithoutConsent = (args, onError) => {
42
+ const pending = heldSlotMode({
43
+ ...args,
44
+ phase: "pending"
45
+ }, onError);
46
+ const refused = heldSlotMode({
47
+ ...args,
48
+ phase: "refused"
49
+ }, onError);
50
+ return pending === "off" && refused === "off" ? void 0 : {
51
+ pending,
52
+ refused
53
+ };
54
+ };
55
+ /**
56
+ * What a slot's snippet is rendered for: a held slot that may count without consent starts
57
+ * cookieless and switches up on consent; every other slot gets 1.0.0-beta.14's snippet.
58
+ */
59
+ const snippetModeArgs = (withoutConsent) => withoutConsent ? {
60
+ mode: "cookieless",
61
+ withoutConsent: true
62
+ } : {
63
+ mode: "full",
64
+ withoutConsent: false
65
+ };
66
+ /**
67
+ * What the full variant of a slot counting without consent is rendered for, which a server-known
68
+ * grant renders; undefined for every other slot, whose one snippet is already full.
69
+ */
70
+ const fullSnippetArgs = (withoutConsent) => withoutConsent ? {
71
+ mode: "full",
72
+ withoutConsent: true
73
+ } : void 0;
74
+ /**
75
+ * An adapter factory's `withoutConsent` (`at` names it, such as `plausible({ withoutConsent })`),
76
+ * refused at boot unless it is one of `allowed`.
77
+ */
78
+ const adapterWithoutConsent = (value, at, allowed) => {
79
+ if (value === void 0 || isOneOf(allowed, value)) return value;
80
+ const names = allowed.map((level) => `'${level}'`);
81
+ throw new Error(`analytics: ${at} must be ${names.slice(0, -1).join(", ")} or ${names.at(-1)}, got ${kindOf(value)}`);
82
+ };
83
+ /** The `capture` fields an adapter able to count without consent declares, its own setting included. */
84
+ const cookielessCapture = (cookieless, withoutConsent) => ({
85
+ cookieless,
86
+ ...withoutConsent === void 0 ? {} : { withoutConsent }
87
+ });
88
+ //#endregion
89
+ export { CONSENT_PHASES, WITHOUT_CONSENT_LEVELS, adapterWithoutConsent, cookielessCapture, fullSnippetArgs, slotWithoutConsent, snippetModeArgs };
90
+
91
+ //# sourceMappingURL=withoutConsent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withoutConsent.js","names":[],"sources":["../../src/capture/withoutConsent.ts"],"sourcesContent":["import type { CaptureSupport, CookielessSupport, SnippetArgs } from '../core/capture'\nimport type { CaptureGateArgs, ResolvedWithoutConsent } from '../core/options'\nimport { isOneOf, kindOf } from '../core/values'\nimport type {\n\tConsentPhase,\n\tHeldSlotMode,\n\tSlotWithoutConsent,\n\tWithoutConsentLevel,\n} from '../tracker/config'\n\nexport const CONSENT_PHASES: readonly ConsentPhase[] = ['pending', 'refused']\n\nexport const WITHOUT_CONSENT_LEVELS: readonly WithoutConsentLevel[] = ['cookieless', 'off']\n\n/** `capture.withoutConsent` left unset. */\nexport const DEFAULT_WITHOUT_CONSENT: Record<ConsentPhase, WithoutConsentLevel> = {\n\tpending: 'cookieless',\n\trefused: 'cookieless',\n}\n\nexport interface HeldSlotArgs extends CaptureGateArgs {\n\tcapture: Pick<CaptureSupport, 'cookieless' | 'withoutConsent'>\n\t/** `capture.withoutConsent` resolved; absent means unset. */\n\toption: ResolvedWithoutConsent | undefined\n}\n\n/**\n * A held slot's mode in one phase: the adapter's own setting, else the host's function, else the\n * install's level, where `'cookieless'` takes the adapter's declared default. A function that\n * throws or answers anything else is `off`, reported to `onError`, failing closed like the gate.\n */\nexport const heldSlotMode = (\n\targs: HeldSlotArgs & { phase: ConsentPhase },\n\tonError?: (err: unknown) => void\n): HeldSlotMode => {\n\tconst { capture, option, phase, slot, adapterId, kind } = args\n\tconst support = capture.cookieless\n\tif (!support) {\n\t\treturn 'off'\n\t}\n\tif (capture.withoutConsent !== undefined) {\n\t\treturn capture.withoutConsent\n\t}\n\tif (typeof option === 'function') {\n\t\ttry {\n\t\t\tconst answer: unknown = option({ slot, adapterId, kind, phase })\n\t\t\tif (isOneOf(WITHOUT_CONSENT_LEVELS, answer)) {\n\t\t\t\treturn answer\n\t\t\t}\n\t\t\tonError?.(new Error(`it answered ${kindOf(answer)}, not 'cookieless' or 'off'`))\n\t\t} catch (err) {\n\t\t\tonError?.(err)\n\t\t}\n\t\treturn 'off'\n\t}\n\tconst level = (option ?? DEFAULT_WITHOUT_CONSENT)[phase]\n\treturn level === 'off' ? 'off' : (support.default ?? 'cookieless')\n}\n\n/**\n * A held slot's modes without consent, or undefined when both are `off`: such a slot's config is\n * exactly 1.0.0-beta.14's.\n */\nexport const slotWithoutConsent = (\n\targs: HeldSlotArgs,\n\tonError?: (err: unknown) => void\n): SlotWithoutConsent | undefined => {\n\tconst pending = heldSlotMode({ ...args, phase: 'pending' }, onError)\n\tconst refused = heldSlotMode({ ...args, phase: 'refused' }, onError)\n\treturn pending === 'off' && refused === 'off' ? undefined : { pending, refused }\n}\n\n/**\n * What a slot's snippet is rendered for: a held slot that may count without consent starts\n * cookieless and switches up on consent; every other slot gets 1.0.0-beta.14's snippet.\n */\nexport const snippetModeArgs = (\n\twithoutConsent: SlotWithoutConsent | undefined\n): Pick<SnippetArgs, 'mode' | 'withoutConsent'> =>\n\twithoutConsent\n\t\t? { mode: 'cookieless', withoutConsent: true }\n\t\t: { mode: 'full', withoutConsent: false }\n\n/**\n * What the full variant of a slot counting without consent is rendered for, which a server-known\n * grant renders; undefined for every other slot, whose one snippet is already full.\n */\nexport const fullSnippetArgs = (\n\twithoutConsent: SlotWithoutConsent | undefined\n): Pick<SnippetArgs, 'mode' | 'withoutConsent'> | undefined =>\n\twithoutConsent ? { mode: 'full', withoutConsent: true } : undefined\n\n/**\n * An adapter factory's `withoutConsent` (`at` names it, such as `plausible({ withoutConsent })`),\n * refused at boot unless it is one of `allowed`.\n */\nexport const adapterWithoutConsent = <T extends HeldSlotMode>(\n\tvalue: unknown,\n\tat: string,\n\tallowed: readonly T[]\n): T | undefined => {\n\tif (value === undefined || isOneOf(allowed, value)) {\n\t\treturn value\n\t}\n\tconst names = allowed.map((level) => `'${level}'`)\n\tthrow new Error(\n\t\t`analytics: ${at} must be ${names.slice(0, -1).join(', ')} or ${names.at(-1)}, got ${kindOf(value)}`\n\t)\n}\n\n/** The `capture` fields an adapter able to count without consent declares, its own setting included. */\nexport const cookielessCapture = (\n\tcookieless: CookielessSupport,\n\twithoutConsent: HeldSlotMode | undefined\n): Pick<CaptureSupport, 'cookieless' | 'withoutConsent'> => ({\n\tcookieless,\n\t...(withoutConsent === undefined ? {} : { withoutConsent }),\n})\n"],"mappings":";;AAUA,MAAa,iBAA0C,CAAC,WAAW,SAAS;AAE5E,MAAa,yBAAyD,CAAC,cAAc,KAAK;;AAG1F,MAAa,0BAAqE;CACjF,SAAS;CACT,SAAS;AACV;;;;;;AAaA,MAAa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QAAQ,OAAO,KAAK,GAClG;AACD;;AAGA,MAAa,qBACZ,YACA,oBAC4D;CAC5D;CACA,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;AAC1D"}
@@ -1,4 +1,4 @@
1
- import { CaptureSnippet, TrackerSlotConfig } from "../tracker/config.js";
1
+ import { CaptureSnippet, HeldSlotMode, TrackerSlotConfig, WithoutConsentLevel } from "../tracker/config.js";
2
2
  import { FetchLike } from "./fetch.js";
3
3
 
4
4
  //#region src/core/capture.d.ts
@@ -29,24 +29,54 @@ interface ProxyDescriptor {
29
29
  */
30
30
  fetch?: FetchLike;
31
31
  }
32
+ /**
33
+ * How a vendor counts without consent. `inherent`: it never stores anything, so one snippet serves
34
+ * every phase. `switched`: its sink switches the vendor's client between cookieless and full.
35
+ * `default` is the level `capture.withoutConsent: 'cookieless'` gives it (GA4: `off`).
36
+ */
37
+ interface CookielessSupport {
38
+ kind: 'inherent' | 'switched';
39
+ default?: WithoutConsentLevel;
40
+ }
41
+ /** What a snippet starts in: `cookieless` for a held slot counting before an answer, else `full`. */
42
+ type SnippetMode = 'cookieless' | 'full';
43
+ interface SnippetArgs {
44
+ path: string;
45
+ /**
46
+ * The request's resolved scope, which a vendor able to carry it stamps on every event. Null when
47
+ * unscoped or unresolved.
48
+ */
49
+ scope?: string | null;
50
+ /**
51
+ * The client the snippet initialises, set only for a vendor that runs a second client beside the
52
+ * other slot's (PostHog).
53
+ */
54
+ instance?: string;
55
+ /** Absent (a caller from before 1.0.0-beta.15) means `full`. */
56
+ mode?: SnippetMode;
57
+ /**
58
+ * True when the slot drops to a cookieless level in some phase without consent, so the snippet
59
+ * boots a client able to switch (PostHog: `cookieless_mode: 'on_reject'`). False keeps the
60
+ * strict boot of 1.0.0-beta.14.
61
+ */
62
+ withoutConsent?: boolean;
63
+ }
32
64
  /**
33
65
  * How a vendor's browser tracker is proxied and booted. Carries only what the browser may see,
34
66
  * never a secret credential such as PostHog's Query API key.
35
67
  */
36
68
  interface CaptureSupport {
37
69
  proxy: ProxyDescriptor;
70
+ snippet(args: SnippetArgs): CaptureSnippet;
71
+ client: TrackerSlotConfig['client'];
72
+ /** Absent: the vendor cannot count without consent, so its held slot sends nothing until then. */
73
+ cookieless?: CookielessSupport;
38
74
  /**
39
- * `scope` is the request's resolved scope, which a vendor able to carry it stamps on every event.
40
- * Null when unscoped or unresolved. `instance` names the client the snippet initialises, set
41
- * only for a vendor that runs a second client beside the other slot's (PostHog).
75
+ * The adapter's own `withoutConsent` (factory option or provider document), which beats
76
+ * `capture.withoutConsent` for its slot in both phases. Ignored without `cookieless`.
42
77
  */
43
- snippet(args: {
44
- path: string;
45
- scope?: string | null;
46
- instance?: string;
47
- }): CaptureSnippet;
48
- client: TrackerSlotConfig['client'];
78
+ withoutConsent?: HeldSlotMode;
49
79
  }
50
80
  //#endregion
51
- export { CaptureSupport, ProxyDescriptor, ProxyRoute, ProxyRouteKind };
81
+ export { CaptureSupport, CookielessSupport, ProxyDescriptor, ProxyRoute, ProxyRouteKind, SnippetArgs, SnippetMode };
52
82
  //# sourceMappingURL=capture.d.ts.map
@@ -1,17 +1,19 @@
1
- import { kindOf } from "./values.js";
1
+ import { isOneOf, kindOf } from "./values.js";
2
2
  import { siteAddress } from "./siteAddress.js";
3
3
  import { isTrustedPlatform } from "../net/platform.js";
4
4
  import { DEFAULT_PROXY_MAX_BODY_BYTES, DEFAULT_PROXY_TIMEOUT_MS } from "../capture/relay.js";
5
5
  import { resolveAllowedOrigins } from "../capture/requestTrust.js";
6
- import { isCaptureSlot } from "../capture/slots.js";
6
+ import { CAPTURE_SLOTS, isCaptureSlot } from "../capture/slots.js";
7
7
  import { DEFAULT_AUTO_CAPTURE, DEFAULT_ITEM_CAPTURE, NO_ITEM_CAPTURE } from "../tracker/config.js";
8
8
  import { DEFAULT_TRACKER_SKIP } from "../tracker/skip.js";
9
9
  import { DEFAULT_EXCLUSION_PARAM } from "../tracker/exclusion.js";
10
+ import { CONSENT_PHASES, WITHOUT_CONSENT_LEVELS, slotWithoutConsent } from "../capture/withoutConsent.js";
10
11
  import { keysOf, optionalBoolean, optionsObject, positiveWhole } from "./optionChecks.js";
11
12
  import { assertNamesAdapter } from "./sourceOptions.js";
12
13
  //#region src/core/captureOptions.ts
13
14
  const CAPTURE_KEYS = keysOf({
14
15
  gate: true,
16
+ withoutConsent: true,
15
17
  allowedOrigins: true,
16
18
  exclusion: true,
17
19
  slots: true,
@@ -90,6 +92,69 @@ const resolveGate = (option, required) => {
90
92
  if (typeof option === "function") return (args) => option(args) !== false;
91
93
  throw new Error(`analytics: capture.gate must be 'all', 'off', a list of slots or a function, got ${kindOf(option)}`);
92
94
  };
95
+ const isLevel = (value) => isOneOf(WITHOUT_CONSENT_LEVELS, value);
96
+ const resolveWithoutConsent = (option) => {
97
+ if (option === void 0 || typeof option === "function") return option;
98
+ if (isLevel(option)) return {
99
+ pending: option,
100
+ refused: option
101
+ };
102
+ const phases = optionsObject(option, {
103
+ path: "capture.withoutConsent",
104
+ known: CONSENT_PHASES,
105
+ example: "'cookieless', 'off', an object such as { refused: 'off' } or a function"
106
+ });
107
+ const level = (phase) => {
108
+ const value = phases[phase];
109
+ if (value === void 0) return "cookieless";
110
+ if (!isLevel(value)) throw new Error(`analytics: capture.withoutConsent.${phase} must be 'cookieless' or 'off', got ${kindOf(value)}`);
111
+ return value;
112
+ };
113
+ return {
114
+ pending: level("pending"),
115
+ refused: level("refused")
116
+ };
117
+ };
118
+ /** Slots the gate may hold, judged without calling host code: a function may hold either. */
119
+ const heldAtBoot = (gate) => new Set(gate === "off" ? [] : Array.isArray(gate) ? gate : CAPTURE_SLOTS);
120
+ /**
121
+ * Whether a source following `capture.withoutConsent` may count without consent: unless the option
122
+ * is `'off'` in both phases, since a function may answer `'cookieless'`.
123
+ */
124
+ const followingCountsWithoutConsent = (option) => typeof option === "function" || CONSENT_PHASES.some((phase) => (option?.[phase] ?? "cookieless") !== "off");
125
+ /** Whether a config adapter may fill `slot`, as far as the boot can tell without a request. */
126
+ const fillsAtBoot = (fill, slot, adapterId) => {
127
+ const configured = fill.capture.slots[slot];
128
+ if (configured === false) return false;
129
+ if (slot === "tenant") return fill.scoped && (configured === void 0 || configured === adapterId);
130
+ const only = fill.adapters.length === 1 ? fill.adapters[0]?.id : void 0;
131
+ return (configured || fill.platformAdapter || only) === adapterId;
132
+ };
133
+ /**
134
+ * Whether a config adapter may count without consent in a slot the gate holds, judged at boot
135
+ * without calling a host function: a `capture.withoutConsent` function may answer `'cookieless'`.
136
+ */
137
+ const adapterCountsWithoutConsent = (fill, adapter) => {
138
+ const capture = adapter.capture;
139
+ if (!capture) return false;
140
+ const option = fill.capture.withoutConsent;
141
+ const answered = typeof option === "function" ? () => "cookieless" : option;
142
+ return CAPTURE_SLOTS.some((slot) => fill.capture.heldSlots.has(slot) && fillsAtBoot(fill, slot, adapter.id) && slotWithoutConsent({
143
+ slot,
144
+ adapterId: adapter.id,
145
+ kind: capture.client.kind,
146
+ capture,
147
+ option: answered
148
+ }) !== void 0);
149
+ };
150
+ /**
151
+ * Whether a held tenant slot may fall to a runtime provider document's adapter: with providers on,
152
+ * unless the slot names a config adapter.
153
+ */
154
+ const documentsFillHeldTenant = (fill, providersOn) => {
155
+ const configured = fill.capture.slots.tenant;
156
+ return providersOn && fill.scoped && configured !== false && fill.capture.heldSlots.has("tenant") && !fill.adapters.some((adapter) => adapter.id === configured);
157
+ };
93
158
  const resolveItemCapture = (option) => option === false ? { ...NO_ITEM_CAPTURE } : {
94
159
  impressions: option?.impressions ?? DEFAULT_ITEM_CAPTURE.impressions,
95
160
  clicks: option?.clicks ?? DEFAULT_ITEM_CAPTURE.clicks,
@@ -212,16 +277,30 @@ const resolveCapture = (options, scoped) => {
212
277
  assertCaptureShape(option);
213
278
  const globalSlot = option?.slots?.global;
214
279
  if (typeof globalSlot === "string") assertNamesAdapter(globalSlot, "capture.slots.global", options.adapters ?? []);
280
+ const gate = resolveGate(option?.gate, fillableSlots(options, scoped).length > 0);
281
+ const withoutConsent = resolveWithoutConsent(option?.withoutConsent);
282
+ const fill = {
283
+ adapters: options.adapters ?? [],
284
+ ...options.platformAdapter ? { platformAdapter: options.platformAdapter } : {},
285
+ scoped,
286
+ capture: {
287
+ slots: {
288
+ global: globalSlot,
289
+ tenant: option?.slots?.tenant
290
+ },
291
+ heldSlots: heldAtBoot(option?.gate),
292
+ ...withoutConsent === void 0 ? {} : { withoutConsent }
293
+ }
294
+ };
295
+ const providersOn = Boolean(options.providers?.collection) || options.providers?.resolve !== void 0;
215
296
  return {
216
- slots: {
217
- global: globalSlot,
218
- tenant: option?.slots?.tenant
219
- },
297
+ ...fill.capture,
220
298
  paths: {
221
299
  global: option?.paths?.global,
222
300
  tenant: option?.paths?.tenant
223
301
  },
224
- gate: resolveGate(option?.gate, fillableSlots(options, scoped).length > 0),
302
+ gate,
303
+ installCountsWithoutConsent: fill.adapters.some((adapter) => adapterCountsWithoutConsent(fill, adapter)) || documentsFillHeldTenant(fill, providersOn) && followingCountsWithoutConsent(withoutConsent),
225
304
  autoCapture: resolveAutoCapture(option?.autoCapture),
226
305
  proxy: {
227
306
  timeoutMs: positiveWhole(option?.proxy?.timeoutMs, "capture.proxy.timeoutMs", DEFAULT_PROXY_TIMEOUT_MS),
@@ -252,7 +331,17 @@ const untrustedAddressNotice = (resolved, production) => {
252
331
  if (!production || resolved.trustedProxyHops !== void 0 || resolved.trustedPlatform !== void 0) return null;
253
332
  return resolved.providers.collection.enabled || resolved.providers.resolve !== void 0 || resolved.adapters.some((adapter) => adapter.ingest !== void 0 || (adapter.capture?.proxy.routes.length ?? 0) > 0) ? "analytics: visitor IP addresses and countries can be spoofed on this install. Neither trustedProxyHops nor trustedPlatform is set, so the plugin reads them from request headers a visitor can write. Set trustedPlatform to 'vercel' or 'cloudflare' when the app runs behind one, or trustedProxyHops to the number of proxies in front of it." : null;
254
333
  };
334
+ /**
335
+ * The boot line for an install leaving `capture.withoutConsent` unset while a held slot may count
336
+ * without consent, naming the default in effect; null otherwise.
337
+ */
338
+ const withoutConsentUnsetNotice = (resolved) => resolved.capture.withoutConsent === void 0 && resolved.capture.installCountsWithoutConsent ? "analytics: capture.withoutConsent is unset, so held slots measure cookielessly before consent and after a refusal. Set it to 'off' to send nothing without consent." : null;
339
+ /**
340
+ * The production boot warning for a held slot counting without consent while nothing says where
341
+ * the client address comes from, or null: cookieless counting tells visitors apart by its hash.
342
+ */
343
+ const cookielessTrustNotice = (resolved, production) => production && resolved.capture.installCountsWithoutConsent && resolved.trustedProxyHops === void 0 && resolved.trustedPlatform === void 0 ? "analytics: a held capture slot counts visitors cookielessly, telling them apart by a hash of the client IP address, yet neither trustedProxyHops nor trustedPlatform is set. Behind a proxy, a missing or wrong hop count hashes the proxy's address instead and collapses every visitor into one. Set trustedPlatform to 'vercel' or 'cloudflare', or trustedProxyHops to the number of proxies in front of the app." : null;
255
344
  //#endregion
256
- export { fillableSlots, resolveCapture, resolveTrust, trackerAutoCapture, untrustedAddressNotice };
345
+ export { adapterCountsWithoutConsent, cookielessTrustNotice, documentsFillHeldTenant, fillableSlots, followingCountsWithoutConsent, resolveCapture, resolveTrust, trackerAutoCapture, untrustedAddressNotice, withoutConsentUnsetNotice };
257
346
 
258
347
  //# sourceMappingURL=captureOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"captureOptions.js","names":[],"sources":["../../src/core/captureOptions.ts"],"sourcesContent":["import { DEFAULT_PROXY_MAX_BODY_BYTES, DEFAULT_PROXY_TIMEOUT_MS } from '../capture/proxyEndpoint'\nimport { resolveAllowedOrigins } from '../capture/requestTrust'\nimport { isCaptureSlot } from '../capture/slots'\nimport { isTrustedPlatform } from '../net/platform'\nimport type { CaptureSlot, TrackerSkip } from '../tracker/config'\nimport {\n\tDEFAULT_AUTO_CAPTURE,\n\tDEFAULT_ITEM_CAPTURE,\n\tNO_ITEM_CAPTURE,\n\ttype ResolvedAutoCapture,\n\ttype ResolvedItemCapture,\n} from '../tracker/config'\nimport { DEFAULT_EXCLUSION_PARAM } from '../tracker/exclusion'\nimport { DEFAULT_TRACKER_SKIP } from '../tracker/skip'\nimport { keysOf, optionalBoolean, optionsObject, positiveWhole } from './optionChecks'\nimport type {\n\tAnalyticsCaptureOptions,\n\tAnalyticsExclusionOptions,\n\tAnalyticsPluginOptions,\n\tAutoCaptureOptions,\n\tCaptureGatePolicy,\n\tExclusionSitesResolver,\n\tItemCaptureOptions,\n\tResolvedCapture,\n\tResolvedOptions,\n} from './options'\nimport { siteAddress } from './siteAddress'\nimport { assertNamesAdapter } from './sourceOptions'\nimport { kindOf } from './values'\n\nconst CAPTURE_KEYS = keysOf<AnalyticsCaptureOptions>({\n\tgate: true,\n\tallowedOrigins: true,\n\texclusion: true,\n\tslots: true,\n\tpaths: true,\n\tautoCapture: true,\n\tskip: true,\n\tproxy: true,\n})\nconst SLOT_KEYS = keysOf<NonNullable<AnalyticsCaptureOptions['slots']>>({\n\tglobal: true,\n\ttenant: true,\n})\nconst PROXY_KEYS = keysOf<NonNullable<AnalyticsCaptureOptions['proxy']>>({\n\ttimeoutMs: true,\n\tmaxBodyBytes: true,\n})\nconst AUTO_CAPTURE_FLAGS = [\n\t'scrollDepth',\n\t'outboundLinks',\n\t'fileDownloads',\n\t'goalAttribute',\n\t'query',\n] as const\nconst AUTO_CAPTURE_KEYS = keysOf<AutoCaptureOptions>({\n\tscrollDepth: true,\n\toutboundLinks: true,\n\tfileDownloads: true,\n\tgoalAttribute: true,\n\tquery: true,\n\titems: true,\n})\nconst ITEM_CAPTURE_KEYS = keysOf<ItemCaptureOptions>({\n\timpressions: true,\n\tclicks: true,\n\tpages: true,\n})\nconst EXCLUSION_KEYS = keysOf<AnalyticsExclusionOptions>({ param: true, sites: true })\n\n/** Unreserved URL characters, so the copied link needs no escaping. */\nconst EXCLUSION_PARAM_PATTERN = /^[A-Za-z0-9._~-]{1,64}$/\n\nconst GATE_REQUIRED =\n\t\"analytics: capture.gate is required: 'all' holds every slot until your consent manager calls setGate, 'off' captures without a gate, or list the slots that wait. The plugin does not decide which tracking needs consent.\"\n\n/**\n * The capture slots that can fill on this config, as far as config time can see; a scoped install's\n * tenant slot counts whenever runtime providers could bring a capture adapter.\n */\nexport const fillableSlots = (options: AnalyticsPluginOptions, scoped: boolean): CaptureSlot[] => {\n\tconst slots = options.capture?.slots\n\tconst adapters = options.adapters\n\tconst fillable: CaptureSlot[] = []\n\tif (slots?.global !== false) {\n\t\tconst id =\n\t\t\tslots?.global ??\n\t\t\toptions.platformAdapter ??\n\t\t\t(adapters.length === 1 ? adapters[0]?.id : undefined)\n\t\tif (adapters.some((adapter) => adapter.id === id && adapter.capture !== undefined)) {\n\t\t\tfillable.push('global')\n\t\t}\n\t}\n\tconst providers =\n\t\tBoolean(options.providers?.collection) || options.providers?.resolve !== undefined\n\tif (\n\t\tscoped &&\n\t\tslots?.tenant !== false &&\n\t\t(providers || adapters.some((adapter) => adapter.capture !== undefined))\n\t) {\n\t\tfillable.push('tenant')\n\t}\n\treturn fillable\n}\n\n/**\n * A function's answer gates its slot unless it is exactly `false`, so a gate that forgets to\n * return holds the slot rather than capturing without consent.\n */\nconst resolveGate = (\n\toption: AnalyticsCaptureOptions['gate'],\n\trequired: boolean\n): CaptureGatePolicy => {\n\tif (option === undefined) {\n\t\tif (required) {\n\t\t\tthrow new Error(GATE_REQUIRED)\n\t\t}\n\t\treturn () => true\n\t}\n\tif (option === 'all') {\n\t\treturn () => true\n\t}\n\tif (option === 'off') {\n\t\treturn () => false\n\t}\n\tif (Array.isArray(option)) {\n\t\tfor (const slot of option) {\n\t\t\tif (typeof slot !== 'string' || !isCaptureSlot(slot)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`analytics: capture.gate lists ${kindOf(slot)}, which is not a capture slot ('global' or 'tenant')`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tconst gated = new Set<CaptureSlot>(option)\n\t\treturn ({ slot }) => gated.has(slot)\n\t}\n\tif (typeof option === 'function') {\n\t\treturn (args) => option(args) !== false\n\t}\n\tthrow new Error(\n\t\t`analytics: capture.gate must be 'all', 'off', a list of slots or a function, got ${kindOf(option)}`\n\t)\n}\n\nconst resolveItemCapture = (option: AutoCaptureOptions['items']): ResolvedItemCapture =>\n\toption === false\n\t\t? { ...NO_ITEM_CAPTURE }\n\t\t: {\n\t\t\t\timpressions: option?.impressions ?? DEFAULT_ITEM_CAPTURE.impressions,\n\t\t\t\tclicks: option?.clicks ?? DEFAULT_ITEM_CAPTURE.clicks,\n\t\t\t\tpages: option?.pages ?? DEFAULT_ITEM_CAPTURE.pages,\n\t\t\t}\n\nconst resolveAutoCapture = (option: AutoCaptureOptions | undefined): ResolvedAutoCapture => ({\n\tscrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,\n\toutboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,\n\tfileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,\n\tgoalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute,\n\tquery: option?.query ?? DEFAULT_AUTO_CAPTURE.query,\n\titems: resolveItemCapture(option?.items),\n})\n\n/**\n * The auto-capture the tracker is handed: item capture off while no collection is bound as items,\n * since ingest would drop every ref it sent, so no page runs an observer for them.\n */\nexport const trackerAutoCapture = (\n\tautoCapture: ResolvedAutoCapture,\n\titemsBound: boolean\n): ResolvedAutoCapture => (itemsBound ? autoCapture : { ...autoCapture, items: NO_ITEM_CAPTURE })\n\n/** A list checked once at boot; a function's answer is checked per request, by the endpoint. */\nconst resolveExclusionSites = (\n\toption: AnalyticsExclusionOptions['sites']\n): ExclusionSitesResolver | undefined => {\n\tif (option === undefined) {\n\t\treturn undefined\n\t}\n\tif (typeof option === 'function') {\n\t\treturn option\n\t}\n\tconst invalid: unknown = Array.isArray(option)\n\t\t? option.find((site) => siteAddress(site) === null)\n\t\t: option\n\tif (!Array.isArray(option) || invalid !== undefined) {\n\t\tthrow new Error(\n\t\t\t`analytics: capture.exclusion.sites must be a function or a list of http(s) addresses such as 'https://shop.example.com', got ${kindOf(invalid)}`\n\t\t)\n\t}\n\tconst sites = option.flatMap((site) => {\n\t\tconst address = siteAddress(site)\n\t\treturn address === null ? [] : [address]\n\t})\n\treturn () => sites\n}\n\nconst resolveExclusion = (\n\toption: AnalyticsCaptureOptions['exclusion']\n): ResolvedCapture['exclusion'] => {\n\tif (option === undefined || option === false) {\n\t\treturn false\n\t}\n\tif (option === true) {\n\t\treturn { param: DEFAULT_EXCLUSION_PARAM }\n\t}\n\toptionsObject(option, {\n\t\tpath: 'capture.exclusion',\n\t\tknown: EXCLUSION_KEYS,\n\t\texample: \"true, false or an object such as { param: 'staff' }\",\n\t})\n\tconst param = option.param ?? DEFAULT_EXCLUSION_PARAM\n\tif (typeof param !== 'string' || !EXCLUSION_PARAM_PATTERN.test(param)) {\n\t\tthrow new Error(\n\t\t\t`analytics: capture.exclusion.param must be 1 to 64 letters, digits, \".\", \"_\", \"~\" or \"-\", got ${kindOf(param)}`\n\t\t)\n\t}\n\tconst sites = resolveExclusionSites(option.sites)\n\treturn sites ? { param, sites } : { param }\n}\n\nconst resolveSkip = (option: AnalyticsCaptureOptions['skip']): TrackerSkip => {\n\tif (option === undefined) {\n\t\treturn { ...DEFAULT_TRACKER_SKIP }\n\t}\n\tconst shaped = optionsObject(option, {\n\t\tpath: 'capture.skip',\n\t\tknown: Object.keys(DEFAULT_TRACKER_SKIP),\n\t\texample: 'an object such as { automation: false }',\n\t})\n\tconst flag = (key: keyof TrackerSkip): boolean =>\n\t\toptionalBoolean(shaped[key], `capture.skip.${key}`) ?? DEFAULT_TRACKER_SKIP[key]\n\treturn { automation: flag('automation'), previews: flag('previews') }\n}\n\n/** Each of `capture.slots` or `capture.paths`, checked by `valid` and refused with `expected`. */\nconst assertPerSlot = (\n\tvalue: unknown,\n\tat: { path: string; example: string; expected: string; valid: (entry: unknown) => boolean }\n): void => {\n\tif (value === undefined) {\n\t\treturn\n\t}\n\tconst perSlot = optionsObject(value, { path: at.path, known: SLOT_KEYS, example: at.example })\n\tfor (const [slot, entry] of Object.entries(perSlot)) {\n\t\tif (entry !== undefined && !at.valid(entry)) {\n\t\t\tthrow new Error(`analytics: ${at.path}.${slot} must be ${at.expected}, got ${kindOf(entry)}`)\n\t\t}\n\t}\n}\n\n/** `capture` and the objects inside it whose values are read as they are. */\nconst assertCaptureShape = (option: AnalyticsCaptureOptions | undefined): void => {\n\tif (option === undefined) {\n\t\treturn\n\t}\n\toptionsObject(option, {\n\t\tpath: 'capture',\n\t\tknown: CAPTURE_KEYS,\n\t\texample: \"an object such as { gate: 'off' }\",\n\t})\n\tassertPerSlot(option.slots, {\n\t\tpath: 'capture.slots',\n\t\texample: \"an object such as { global: 'native' }\",\n\t\texpected: 'an adapter id or false',\n\t\tvalid: (entry) => entry === false || typeof entry === 'string',\n\t})\n\tassertPerSlot(option.paths, {\n\t\tpath: 'capture.paths',\n\t\texample: \"an object such as { global: '/stats' }\",\n\t\texpected: 'a path starting with \"/\", such as \"/stats\"',\n\t\tvalid: (entry) => typeof entry === 'string' && entry.startsWith('/'),\n\t})\n\tif (option.proxy !== undefined) {\n\t\toptionsObject(option.proxy, {\n\t\t\tpath: 'capture.proxy',\n\t\t\tknown: PROXY_KEYS,\n\t\t\texample: 'an object such as { timeoutMs: 10000 }',\n\t\t})\n\t}\n\tif (option.autoCapture === undefined) {\n\t\treturn\n\t}\n\tconst auto = optionsObject(option.autoCapture, {\n\t\tpath: 'capture.autoCapture',\n\t\tknown: AUTO_CAPTURE_KEYS,\n\t\texample: 'an object such as { scrollDepth: true }',\n\t})\n\tfor (const flag of AUTO_CAPTURE_FLAGS) {\n\t\toptionalBoolean(auto[flag], `capture.autoCapture.${flag}`)\n\t}\n\tif (auto.items !== undefined && auto.items !== false) {\n\t\tconst items = optionsObject(auto.items, {\n\t\t\tpath: 'capture.autoCapture.items',\n\t\t\tknown: ITEM_CAPTURE_KEYS,\n\t\t\texample: 'false, or an object such as { clicks: false }',\n\t\t})\n\t\tfor (const flag of ITEM_CAPTURE_KEYS) {\n\t\t\toptionalBoolean(items[flag], `capture.autoCapture.items.${flag}`)\n\t\t}\n\t}\n}\n\n/**\n * `capture` checked and filled. A global slot's adapter id is checked against `adapters` here; a\n * tenant one may name a runtime provider instance, which only exists once a scope resolves.\n */\nexport const resolveCapture = (\n\toptions: AnalyticsPluginOptions,\n\tscoped: boolean\n): ResolvedCapture => {\n\tconst option = options.capture\n\tassertCaptureShape(option)\n\tconst globalSlot = option?.slots?.global\n\tif (typeof globalSlot === 'string') {\n\t\tassertNamesAdapter(globalSlot, 'capture.slots.global', options.adapters ?? [])\n\t}\n\treturn {\n\t\tslots: { global: globalSlot, tenant: option?.slots?.tenant },\n\t\tpaths: { global: option?.paths?.global, tenant: option?.paths?.tenant },\n\t\tgate: resolveGate(option?.gate, fillableSlots(options, scoped).length > 0),\n\t\tautoCapture: resolveAutoCapture(option?.autoCapture),\n\t\tproxy: {\n\t\t\ttimeoutMs: positiveWhole(\n\t\t\t\toption?.proxy?.timeoutMs,\n\t\t\t\t'capture.proxy.timeoutMs',\n\t\t\t\tDEFAULT_PROXY_TIMEOUT_MS\n\t\t\t),\n\t\t\tmaxBodyBytes: positiveWhole(\n\t\t\t\toption?.proxy?.maxBodyBytes,\n\t\t\t\t'capture.proxy.maxBodyBytes',\n\t\t\t\tDEFAULT_PROXY_MAX_BODY_BYTES\n\t\t\t),\n\t\t},\n\t\tallowedOrigins: resolveAllowedOrigins(option?.allowedOrigins),\n\t\texclusion: resolveExclusion(option?.exclusion),\n\t\tskip: resolveSkip(option?.skip),\n\t}\n}\n\n/** Where the client address and location come from: a proxy count, a platform, or neither. */\nexport const resolveTrust = (\n\toptions: AnalyticsPluginOptions\n): Pick<ResolvedOptions, 'trustedProxyHops' | 'trustedPlatform'> => {\n\tconst hops = options.trustedProxyHops\n\tif (hops !== undefined && (!Number.isInteger(hops) || hops < 0)) {\n\t\tthrow new Error(\n\t\t\t`analytics: trustedProxyHops must be a non-negative integer, got ${String(hops)}`\n\t\t)\n\t}\n\tconst platform: unknown = options.trustedPlatform\n\tif (platform !== undefined && !isTrustedPlatform(platform)) {\n\t\tthrow new Error(\n\t\t\t`analytics: trustedPlatform must be 'vercel' or 'cloudflare', got ${kindOf(platform)}`\n\t\t)\n\t}\n\tif (hops !== undefined && platform !== undefined) {\n\t\tthrow new Error(\n\t\t\t'analytics: trustedProxyHops and trustedPlatform cannot both be set. trustedPlatform reads the visitor address from the platform header, trustedProxyHops from x-forwarded-for: keep the one that describes what sits in front of the app.'\n\t\t)\n\t}\n\treturn {\n\t\t...(hops === undefined ? {} : { trustedProxyHops: hops }),\n\t\t...(platform === undefined ? {} : { trustedPlatform: platform }),\n\t}\n}\n\n/**\n * The production boot notice for an install reading visitor addresses and countries from headers\n * nothing vouches for, or null.\n */\nexport const untrustedAddressNotice = (\n\tresolved: Pick<\n\t\tResolvedOptions,\n\t\t'trustedProxyHops' | 'trustedPlatform' | 'adapters' | 'providers'\n\t>,\n\tproduction: boolean\n): string | null => {\n\tif (\n\t\t!production ||\n\t\tresolved.trustedProxyHops !== undefined ||\n\t\tresolved.trustedPlatform !== undefined\n\t) {\n\t\treturn null\n\t}\n\tconst reads =\n\t\tresolved.providers.collection.enabled ||\n\t\tresolved.providers.resolve !== undefined ||\n\t\tresolved.adapters.some(\n\t\t\t(adapter) => adapter.ingest !== undefined || (adapter.capture?.proxy.routes.length ?? 0) > 0\n\t\t)\n\treturn reads\n\t\t? \"analytics: visitor IP addresses and countries can be spoofed on this install. Neither trustedProxyHops nor trustedPlatform is set, so the plugin reads them from request headers a visitor can write. Set trustedPlatform to 'vercel' or 'cloudflare' when the app runs behind one, or trustedProxyHops to the number of proxies in front of it.\"\n\t\t: null\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,eAAe,OAAgC;CACpD,MAAM;CACN,gBAAgB;CAChB,WAAW;CACX,OAAO;CACP,OAAO;CACP,aAAa;CACb,MAAM;CACN,OAAO;AACR,CAAC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BACA,wBACD;GACA,cAAc,cACb,QAAQ,OAAO,cACf,8BACA,4BACD;EACD;EACA,gBAAgB,sBAAsB,QAAQ,cAAc;EAC5D,WAAW,iBAAiB,QAAQ,SAAS;EAC7C,MAAM,YAAY,QAAQ,IAAI;CAC/B;AACD;;AAGA,MAAa,gBACZ,YACmE;CACnE,MAAM,OAAO,QAAQ;CACrB,IAAI,SAAS,KAAA,MAAc,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,IAC5D,MAAM,IAAI,MACT,mEAAmE,OAAO,IAAI,GAC/E;CAED,MAAM,WAAoB,QAAQ;CAClC,IAAI,aAAa,KAAA,KAAa,CAAC,kBAAkB,QAAQ,GACxD,MAAM,IAAI,MACT,oEAAoE,OAAO,QAAQ,GACpF;CAED,IAAI,SAAS,KAAA,KAAa,aAAa,KAAA,GACtC,MAAM,IAAI,MACT,2OACD;CAED,OAAO;EACN,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB,KAAK;EACvD,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB,SAAS;CAC/D;AACD;;;;;AAMA,MAAa,0BACZ,UAIA,eACmB;CACnB,IACC,CAAC,cACD,SAAS,qBAAqB,KAAA,KAC9B,SAAS,oBAAoB,KAAA,GAE7B,OAAO;CAQR,OALC,SAAS,UAAU,WAAW,WAC9B,SAAS,UAAU,YAAY,KAAA,KAC/B,SAAS,SAAS,MAChB,YAAY,QAAQ,WAAW,KAAA,MAAc,QAAQ,SAAS,MAAM,OAAO,UAAU,KAAK,CAC5F,IAEE,qVACA;AACJ"}
1
+ {"version":3,"file":"captureOptions.js","names":[],"sources":["../../src/core/captureOptions.ts"],"sourcesContent":["import { DEFAULT_PROXY_MAX_BODY_BYTES, DEFAULT_PROXY_TIMEOUT_MS } from '../capture/proxyEndpoint'\nimport { resolveAllowedOrigins } from '../capture/requestTrust'\nimport { CAPTURE_SLOTS, isCaptureSlot } from '../capture/slots'\nimport {\n\tCONSENT_PHASES,\n\tslotWithoutConsent,\n\tWITHOUT_CONSENT_LEVELS,\n} from '../capture/withoutConsent'\nimport { isTrustedPlatform } from '../net/platform'\nimport type { CaptureSlot, ConsentPhase, TrackerSkip, WithoutConsentLevel } from '../tracker/config'\nimport {\n\tDEFAULT_AUTO_CAPTURE,\n\tDEFAULT_ITEM_CAPTURE,\n\tNO_ITEM_CAPTURE,\n\ttype ResolvedAutoCapture,\n\ttype ResolvedItemCapture,\n} from '../tracker/config'\nimport { DEFAULT_EXCLUSION_PARAM } from '../tracker/exclusion'\nimport { DEFAULT_TRACKER_SKIP } from '../tracker/skip'\nimport type { AnalyticsAdapter } from './contract'\nimport { keysOf, optionalBoolean, optionsObject, positiveWhole } from './optionChecks'\nimport type {\n\tAnalyticsCaptureOptions,\n\tAnalyticsExclusionOptions,\n\tAnalyticsPluginOptions,\n\tAutoCaptureOptions,\n\tCaptureGatePolicy,\n\tExclusionSitesResolver,\n\tItemCaptureOptions,\n\tResolvedCapture,\n\tResolvedOptions,\n\tResolvedWithoutConsent,\n} from './options'\nimport { siteAddress } from './siteAddress'\nimport { assertNamesAdapter } from './sourceOptions'\nimport { isOneOf, kindOf } from './values'\n\nconst CAPTURE_KEYS = keysOf<AnalyticsCaptureOptions>({\n\tgate: true,\n\twithoutConsent: true,\n\tallowedOrigins: true,\n\texclusion: true,\n\tslots: true,\n\tpaths: true,\n\tautoCapture: true,\n\tskip: true,\n\tproxy: true,\n})\nconst SLOT_KEYS = keysOf<NonNullable<AnalyticsCaptureOptions['slots']>>({\n\tglobal: true,\n\ttenant: true,\n})\nconst PROXY_KEYS = keysOf<NonNullable<AnalyticsCaptureOptions['proxy']>>({\n\ttimeoutMs: true,\n\tmaxBodyBytes: true,\n})\nconst AUTO_CAPTURE_FLAGS = [\n\t'scrollDepth',\n\t'outboundLinks',\n\t'fileDownloads',\n\t'goalAttribute',\n\t'query',\n] as const\nconst AUTO_CAPTURE_KEYS = keysOf<AutoCaptureOptions>({\n\tscrollDepth: true,\n\toutboundLinks: true,\n\tfileDownloads: true,\n\tgoalAttribute: true,\n\tquery: true,\n\titems: true,\n})\nconst ITEM_CAPTURE_KEYS = keysOf<ItemCaptureOptions>({\n\timpressions: true,\n\tclicks: true,\n\tpages: true,\n})\nconst EXCLUSION_KEYS = keysOf<AnalyticsExclusionOptions>({ param: true, sites: true })\n\n/** Unreserved URL characters, so the copied link needs no escaping. */\nconst EXCLUSION_PARAM_PATTERN = /^[A-Za-z0-9._~-]{1,64}$/\n\nconst GATE_REQUIRED =\n\t\"analytics: capture.gate is required: 'all' holds every slot until your consent manager calls setGate, 'off' captures without a gate, or list the slots that wait. The plugin does not decide which tracking needs consent.\"\n\n/**\n * The capture slots that can fill on this config, as far as config time can see; a scoped install's\n * tenant slot counts whenever runtime providers could bring a capture adapter.\n */\nexport const fillableSlots = (options: AnalyticsPluginOptions, scoped: boolean): CaptureSlot[] => {\n\tconst slots = options.capture?.slots\n\tconst adapters = options.adapters\n\tconst fillable: CaptureSlot[] = []\n\tif (slots?.global !== false) {\n\t\tconst id =\n\t\t\tslots?.global ??\n\t\t\toptions.platformAdapter ??\n\t\t\t(adapters.length === 1 ? adapters[0]?.id : undefined)\n\t\tif (adapters.some((adapter) => adapter.id === id && adapter.capture !== undefined)) {\n\t\t\tfillable.push('global')\n\t\t}\n\t}\n\tconst providers =\n\t\tBoolean(options.providers?.collection) || options.providers?.resolve !== undefined\n\tif (\n\t\tscoped &&\n\t\tslots?.tenant !== false &&\n\t\t(providers || adapters.some((adapter) => adapter.capture !== undefined))\n\t) {\n\t\tfillable.push('tenant')\n\t}\n\treturn fillable\n}\n\n/**\n * A function's answer gates its slot unless it is exactly `false`, so a gate that forgets to\n * return holds the slot rather than capturing without consent.\n */\nconst resolveGate = (\n\toption: AnalyticsCaptureOptions['gate'],\n\trequired: boolean\n): CaptureGatePolicy => {\n\tif (option === undefined) {\n\t\tif (required) {\n\t\t\tthrow new Error(GATE_REQUIRED)\n\t\t}\n\t\treturn () => true\n\t}\n\tif (option === 'all') {\n\t\treturn () => true\n\t}\n\tif (option === 'off') {\n\t\treturn () => false\n\t}\n\tif (Array.isArray(option)) {\n\t\tfor (const slot of option) {\n\t\t\tif (typeof slot !== 'string' || !isCaptureSlot(slot)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`analytics: capture.gate lists ${kindOf(slot)}, which is not a capture slot ('global' or 'tenant')`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tconst gated = new Set<CaptureSlot>(option)\n\t\treturn ({ slot }) => gated.has(slot)\n\t}\n\tif (typeof option === 'function') {\n\t\treturn (args) => option(args) !== false\n\t}\n\tthrow new Error(\n\t\t`analytics: capture.gate must be 'all', 'off', a list of slots or a function, got ${kindOf(option)}`\n\t)\n}\n\nconst isLevel = (value: unknown): value is WithoutConsentLevel =>\n\tisOneOf(WITHOUT_CONSENT_LEVELS, value)\n\nconst resolveWithoutConsent = (\n\toption: AnalyticsCaptureOptions['withoutConsent']\n): ResolvedWithoutConsent | undefined => {\n\tif (option === undefined || typeof option === 'function') {\n\t\treturn option\n\t}\n\tif (isLevel(option)) {\n\t\treturn { pending: option, refused: option }\n\t}\n\tconst phases = optionsObject(option, {\n\t\tpath: 'capture.withoutConsent',\n\t\tknown: CONSENT_PHASES,\n\t\texample: \"'cookieless', 'off', an object such as { refused: 'off' } or a function\",\n\t})\n\tconst level = (phase: ConsentPhase): WithoutConsentLevel => {\n\t\tconst value = phases[phase]\n\t\tif (value === undefined) {\n\t\t\treturn 'cookieless'\n\t\t}\n\t\tif (!isLevel(value)) {\n\t\t\tthrow new Error(\n\t\t\t\t`analytics: capture.withoutConsent.${phase} must be 'cookieless' or 'off', got ${kindOf(value)}`\n\t\t\t)\n\t\t}\n\t\treturn value\n\t}\n\treturn { pending: level('pending'), refused: level('refused') }\n}\n\n/** Slots the gate may hold, judged without calling host code: a function may hold either. */\nconst heldAtBoot = (gate: AnalyticsCaptureOptions['gate']): ReadonlySet<CaptureSlot> =>\n\tnew Set(gate === 'off' ? [] : Array.isArray(gate) ? gate : CAPTURE_SLOTS)\n\n/**\n * Whether a source following `capture.withoutConsent` may count without consent: unless the option\n * is `'off'` in both phases, since a function may answer `'cookieless'`.\n */\nexport const followingCountsWithoutConsent = (\n\toption: ResolvedWithoutConsent | undefined\n): boolean =>\n\ttypeof option === 'function' ||\n\tCONSENT_PHASES.some((phase) => (option?.[phase] ?? 'cookieless') !== 'off')\n\n/** What the boot knows about which config adapter fills which slot; a resolved install is one. */\nexport interface BootFill {\n\tadapters: readonly AnalyticsAdapter[]\n\tplatformAdapter?: string\n\tscoped: boolean\n\tcapture: Pick<ResolvedCapture, 'slots' | 'heldSlots' | 'withoutConsent'>\n}\n\n/** Whether a config adapter may fill `slot`, as far as the boot can tell without a request. */\nconst fillsAtBoot = (fill: BootFill, slot: CaptureSlot, adapterId: string): boolean => {\n\tconst configured = fill.capture.slots[slot]\n\tif (configured === false) {\n\t\treturn false\n\t}\n\tif (slot === 'tenant') {\n\t\treturn fill.scoped && (configured === undefined || configured === adapterId)\n\t}\n\tconst only = fill.adapters.length === 1 ? fill.adapters[0]?.id : undefined\n\treturn (configured || fill.platformAdapter || only) === adapterId\n}\n\n/**\n * Whether a config adapter may count without consent in a slot the gate holds, judged at boot\n * without calling a host function: a `capture.withoutConsent` function may answer `'cookieless'`.\n */\nexport const adapterCountsWithoutConsent = (fill: BootFill, adapter: AnalyticsAdapter): boolean => {\n\tconst capture = adapter.capture\n\tif (!capture) {\n\t\treturn false\n\t}\n\tconst option = fill.capture.withoutConsent\n\tconst answered = typeof option === 'function' ? () => 'cookieless' as const : option\n\treturn CAPTURE_SLOTS.some(\n\t\t(slot) =>\n\t\t\tfill.capture.heldSlots.has(slot) &&\n\t\t\tfillsAtBoot(fill, slot, adapter.id) &&\n\t\t\tslotWithoutConsent({\n\t\t\t\tslot,\n\t\t\t\tadapterId: adapter.id,\n\t\t\t\tkind: capture.client.kind,\n\t\t\t\tcapture,\n\t\t\t\toption: answered,\n\t\t\t}) !== undefined\n\t)\n}\n\n/**\n * Whether a held tenant slot may fall to a runtime provider document's adapter: with providers on,\n * unless the slot names a config adapter.\n */\nexport const documentsFillHeldTenant = (\n\tfill: Pick<BootFill, 'adapters' | 'scoped' | 'capture'>,\n\tprovidersOn: boolean\n): boolean => {\n\tconst configured = fill.capture.slots.tenant\n\treturn (\n\t\tprovidersOn &&\n\t\tfill.scoped &&\n\t\tconfigured !== false &&\n\t\tfill.capture.heldSlots.has('tenant') &&\n\t\t!fill.adapters.some((adapter) => adapter.id === configured)\n\t)\n}\n\nconst resolveItemCapture = (option: AutoCaptureOptions['items']): ResolvedItemCapture =>\n\toption === false\n\t\t? { ...NO_ITEM_CAPTURE }\n\t\t: {\n\t\t\t\timpressions: option?.impressions ?? DEFAULT_ITEM_CAPTURE.impressions,\n\t\t\t\tclicks: option?.clicks ?? DEFAULT_ITEM_CAPTURE.clicks,\n\t\t\t\tpages: option?.pages ?? DEFAULT_ITEM_CAPTURE.pages,\n\t\t\t}\n\nconst resolveAutoCapture = (option: AutoCaptureOptions | undefined): ResolvedAutoCapture => ({\n\tscrollDepth: option?.scrollDepth ?? DEFAULT_AUTO_CAPTURE.scrollDepth,\n\toutboundLinks: option?.outboundLinks ?? DEFAULT_AUTO_CAPTURE.outboundLinks,\n\tfileDownloads: option?.fileDownloads ?? DEFAULT_AUTO_CAPTURE.fileDownloads,\n\tgoalAttribute: option?.goalAttribute ?? DEFAULT_AUTO_CAPTURE.goalAttribute,\n\tquery: option?.query ?? DEFAULT_AUTO_CAPTURE.query,\n\titems: resolveItemCapture(option?.items),\n})\n\n/**\n * The auto-capture the tracker is handed: item capture off while no collection is bound as items,\n * since ingest would drop every ref it sent, so no page runs an observer for them.\n */\nexport const trackerAutoCapture = (\n\tautoCapture: ResolvedAutoCapture,\n\titemsBound: boolean\n): ResolvedAutoCapture => (itemsBound ? autoCapture : { ...autoCapture, items: NO_ITEM_CAPTURE })\n\n/** A list checked once at boot; a function's answer is checked per request, by the endpoint. */\nconst resolveExclusionSites = (\n\toption: AnalyticsExclusionOptions['sites']\n): ExclusionSitesResolver | undefined => {\n\tif (option === undefined) {\n\t\treturn undefined\n\t}\n\tif (typeof option === 'function') {\n\t\treturn option\n\t}\n\tconst invalid: unknown = Array.isArray(option)\n\t\t? option.find((site) => siteAddress(site) === null)\n\t\t: option\n\tif (!Array.isArray(option) || invalid !== undefined) {\n\t\tthrow new Error(\n\t\t\t`analytics: capture.exclusion.sites must be a function or a list of http(s) addresses such as 'https://shop.example.com', got ${kindOf(invalid)}`\n\t\t)\n\t}\n\tconst sites = option.flatMap((site) => {\n\t\tconst address = siteAddress(site)\n\t\treturn address === null ? [] : [address]\n\t})\n\treturn () => sites\n}\n\nconst resolveExclusion = (\n\toption: AnalyticsCaptureOptions['exclusion']\n): ResolvedCapture['exclusion'] => {\n\tif (option === undefined || option === false) {\n\t\treturn false\n\t}\n\tif (option === true) {\n\t\treturn { param: DEFAULT_EXCLUSION_PARAM }\n\t}\n\toptionsObject(option, {\n\t\tpath: 'capture.exclusion',\n\t\tknown: EXCLUSION_KEYS,\n\t\texample: \"true, false or an object such as { param: 'staff' }\",\n\t})\n\tconst param = option.param ?? DEFAULT_EXCLUSION_PARAM\n\tif (typeof param !== 'string' || !EXCLUSION_PARAM_PATTERN.test(param)) {\n\t\tthrow new Error(\n\t\t\t`analytics: capture.exclusion.param must be 1 to 64 letters, digits, \".\", \"_\", \"~\" or \"-\", got ${kindOf(param)}`\n\t\t)\n\t}\n\tconst sites = resolveExclusionSites(option.sites)\n\treturn sites ? { param, sites } : { param }\n}\n\nconst resolveSkip = (option: AnalyticsCaptureOptions['skip']): TrackerSkip => {\n\tif (option === undefined) {\n\t\treturn { ...DEFAULT_TRACKER_SKIP }\n\t}\n\tconst shaped = optionsObject(option, {\n\t\tpath: 'capture.skip',\n\t\tknown: Object.keys(DEFAULT_TRACKER_SKIP),\n\t\texample: 'an object such as { automation: false }',\n\t})\n\tconst flag = (key: keyof TrackerSkip): boolean =>\n\t\toptionalBoolean(shaped[key], `capture.skip.${key}`) ?? DEFAULT_TRACKER_SKIP[key]\n\treturn { automation: flag('automation'), previews: flag('previews') }\n}\n\n/** Each of `capture.slots` or `capture.paths`, checked by `valid` and refused with `expected`. */\nconst assertPerSlot = (\n\tvalue: unknown,\n\tat: { path: string; example: string; expected: string; valid: (entry: unknown) => boolean }\n): void => {\n\tif (value === undefined) {\n\t\treturn\n\t}\n\tconst perSlot = optionsObject(value, { path: at.path, known: SLOT_KEYS, example: at.example })\n\tfor (const [slot, entry] of Object.entries(perSlot)) {\n\t\tif (entry !== undefined && !at.valid(entry)) {\n\t\t\tthrow new Error(`analytics: ${at.path}.${slot} must be ${at.expected}, got ${kindOf(entry)}`)\n\t\t}\n\t}\n}\n\n/** `capture` and the objects inside it whose values are read as they are. */\nconst assertCaptureShape = (option: AnalyticsCaptureOptions | undefined): void => {\n\tif (option === undefined) {\n\t\treturn\n\t}\n\toptionsObject(option, {\n\t\tpath: 'capture',\n\t\tknown: CAPTURE_KEYS,\n\t\texample: \"an object such as { gate: 'off' }\",\n\t})\n\tassertPerSlot(option.slots, {\n\t\tpath: 'capture.slots',\n\t\texample: \"an object such as { global: 'native' }\",\n\t\texpected: 'an adapter id or false',\n\t\tvalid: (entry) => entry === false || typeof entry === 'string',\n\t})\n\tassertPerSlot(option.paths, {\n\t\tpath: 'capture.paths',\n\t\texample: \"an object such as { global: '/stats' }\",\n\t\texpected: 'a path starting with \"/\", such as \"/stats\"',\n\t\tvalid: (entry) => typeof entry === 'string' && entry.startsWith('/'),\n\t})\n\tif (option.proxy !== undefined) {\n\t\toptionsObject(option.proxy, {\n\t\t\tpath: 'capture.proxy',\n\t\t\tknown: PROXY_KEYS,\n\t\t\texample: 'an object such as { timeoutMs: 10000 }',\n\t\t})\n\t}\n\tif (option.autoCapture === undefined) {\n\t\treturn\n\t}\n\tconst auto = optionsObject(option.autoCapture, {\n\t\tpath: 'capture.autoCapture',\n\t\tknown: AUTO_CAPTURE_KEYS,\n\t\texample: 'an object such as { scrollDepth: true }',\n\t})\n\tfor (const flag of AUTO_CAPTURE_FLAGS) {\n\t\toptionalBoolean(auto[flag], `capture.autoCapture.${flag}`)\n\t}\n\tif (auto.items !== undefined && auto.items !== false) {\n\t\tconst items = optionsObject(auto.items, {\n\t\t\tpath: 'capture.autoCapture.items',\n\t\t\tknown: ITEM_CAPTURE_KEYS,\n\t\t\texample: 'false, or an object such as { clicks: false }',\n\t\t})\n\t\tfor (const flag of ITEM_CAPTURE_KEYS) {\n\t\t\toptionalBoolean(items[flag], `capture.autoCapture.items.${flag}`)\n\t\t}\n\t}\n}\n\n/**\n * `capture` checked and filled. A global slot's adapter id is checked against `adapters` here; a\n * tenant one may name a runtime provider instance, which only exists once a scope resolves.\n */\nexport const resolveCapture = (\n\toptions: AnalyticsPluginOptions,\n\tscoped: boolean\n): ResolvedCapture => {\n\tconst option = options.capture\n\tassertCaptureShape(option)\n\tconst globalSlot = option?.slots?.global\n\tif (typeof globalSlot === 'string') {\n\t\tassertNamesAdapter(globalSlot, 'capture.slots.global', options.adapters ?? [])\n\t}\n\tconst gate = resolveGate(option?.gate, fillableSlots(options, scoped).length > 0)\n\tconst withoutConsent = resolveWithoutConsent(option?.withoutConsent)\n\tconst fill: BootFill = {\n\t\tadapters: options.adapters ?? [],\n\t\t...(options.platformAdapter ? { platformAdapter: options.platformAdapter } : {}),\n\t\tscoped,\n\t\tcapture: {\n\t\t\tslots: { global: globalSlot, tenant: option?.slots?.tenant },\n\t\t\theldSlots: heldAtBoot(option?.gate),\n\t\t\t...(withoutConsent === undefined ? {} : { withoutConsent }),\n\t\t},\n\t}\n\tconst providersOn =\n\t\tBoolean(options.providers?.collection) || options.providers?.resolve !== undefined\n\treturn {\n\t\t...fill.capture,\n\t\tpaths: { global: option?.paths?.global, tenant: option?.paths?.tenant },\n\t\tgate,\n\t\tinstallCountsWithoutConsent:\n\t\t\tfill.adapters.some((adapter) => adapterCountsWithoutConsent(fill, adapter)) ||\n\t\t\t(documentsFillHeldTenant(fill, providersOn) && followingCountsWithoutConsent(withoutConsent)),\n\t\tautoCapture: resolveAutoCapture(option?.autoCapture),\n\t\tproxy: {\n\t\t\ttimeoutMs: positiveWhole(\n\t\t\t\toption?.proxy?.timeoutMs,\n\t\t\t\t'capture.proxy.timeoutMs',\n\t\t\t\tDEFAULT_PROXY_TIMEOUT_MS\n\t\t\t),\n\t\t\tmaxBodyBytes: positiveWhole(\n\t\t\t\toption?.proxy?.maxBodyBytes,\n\t\t\t\t'capture.proxy.maxBodyBytes',\n\t\t\t\tDEFAULT_PROXY_MAX_BODY_BYTES\n\t\t\t),\n\t\t},\n\t\tallowedOrigins: resolveAllowedOrigins(option?.allowedOrigins),\n\t\texclusion: resolveExclusion(option?.exclusion),\n\t\tskip: resolveSkip(option?.skip),\n\t}\n}\n\n/** Where the client address and location come from: a proxy count, a platform, or neither. */\nexport const resolveTrust = (\n\toptions: AnalyticsPluginOptions\n): Pick<ResolvedOptions, 'trustedProxyHops' | 'trustedPlatform'> => {\n\tconst hops = options.trustedProxyHops\n\tif (hops !== undefined && (!Number.isInteger(hops) || hops < 0)) {\n\t\tthrow new Error(\n\t\t\t`analytics: trustedProxyHops must be a non-negative integer, got ${String(hops)}`\n\t\t)\n\t}\n\tconst platform: unknown = options.trustedPlatform\n\tif (platform !== undefined && !isTrustedPlatform(platform)) {\n\t\tthrow new Error(\n\t\t\t`analytics: trustedPlatform must be 'vercel' or 'cloudflare', got ${kindOf(platform)}`\n\t\t)\n\t}\n\tif (hops !== undefined && platform !== undefined) {\n\t\tthrow new Error(\n\t\t\t'analytics: trustedProxyHops and trustedPlatform cannot both be set. trustedPlatform reads the visitor address from the platform header, trustedProxyHops from x-forwarded-for: keep the one that describes what sits in front of the app.'\n\t\t)\n\t}\n\treturn {\n\t\t...(hops === undefined ? {} : { trustedProxyHops: hops }),\n\t\t...(platform === undefined ? {} : { trustedPlatform: platform }),\n\t}\n}\n\n/**\n * The production boot notice for an install reading visitor addresses and countries from headers\n * nothing vouches for, or null.\n */\nexport const untrustedAddressNotice = (\n\tresolved: Pick<\n\t\tResolvedOptions,\n\t\t'trustedProxyHops' | 'trustedPlatform' | 'adapters' | 'providers'\n\t>,\n\tproduction: boolean\n): string | null => {\n\tif (\n\t\t!production ||\n\t\tresolved.trustedProxyHops !== undefined ||\n\t\tresolved.trustedPlatform !== undefined\n\t) {\n\t\treturn null\n\t}\n\tconst reads =\n\t\tresolved.providers.collection.enabled ||\n\t\tresolved.providers.resolve !== undefined ||\n\t\tresolved.adapters.some(\n\t\t\t(adapter) => adapter.ingest !== undefined || (adapter.capture?.proxy.routes.length ?? 0) > 0\n\t\t)\n\treturn reads\n\t\t? \"analytics: visitor IP addresses and countries can be spoofed on this install. Neither trustedProxyHops nor trustedPlatform is set, so the plugin reads them from request headers a visitor can write. Set trustedPlatform to 'vercel' or 'cloudflare' when the app runs behind one, or trustedProxyHops to the number of proxies in front of it.\"\n\t\t: null\n}\n\n/**\n * The boot line for an install leaving `capture.withoutConsent` unset while a held slot may count\n * without consent, naming the default in effect; null otherwise.\n */\nexport const withoutConsentUnsetNotice = (\n\tresolved: Pick<ResolvedOptions, 'capture'>\n): string | null =>\n\tresolved.capture.withoutConsent === undefined && resolved.capture.installCountsWithoutConsent\n\t\t? \"analytics: capture.withoutConsent is unset, so held slots measure cookielessly before consent and after a refusal. Set it to 'off' to send nothing without consent.\"\n\t\t: null\n\n/**\n * The production boot warning for a held slot counting without consent while nothing says where\n * the client address comes from, or null: cookieless counting tells visitors apart by its hash.\n */\nexport const cookielessTrustNotice = (\n\tresolved: Pick<ResolvedOptions, 'trustedProxyHops' | 'trustedPlatform' | 'capture'>,\n\tproduction: boolean\n): string | null =>\n\tproduction &&\n\tresolved.capture.installCountsWithoutConsent &&\n\tresolved.trustedProxyHops === undefined &&\n\tresolved.trustedPlatform === undefined\n\t\t? \"analytics: a held capture slot counts visitors cookielessly, telling them apart by a hash of the client IP address, yet neither trustedProxyHops nor trustedPlatform is set. Behind a proxy, a missing or wrong hop count hashes the proxy's address instead and collapses every visitor into one. Set trustedPlatform to 'vercel' or 'cloudflare', or trustedProxyHops to the number of proxies in front of the app.\"\n\t\t: null\n"],"mappings":";;;;;;;;;;;;;AAqCA,MAAM,eAAe,OAAgC;CACpD,MAAM;CACN,gBAAgB;CAChB,gBAAgB;CAChB,WAAW;CACX,OAAO;CACP,OAAO;CACP,aAAa;CACb,MAAM;CACN,OAAO;AACR,CAAC;AACD,MAAM,YAAY,OAAsD;CACvE,QAAQ;CACR,QAAQ;AACT,CAAC;AACD,MAAM,aAAa,OAAsD;CACxE,WAAW;CACX,cAAc;AACf,CAAC;AACD,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;AACD;AACA,MAAM,oBAAoB,OAA2B;CACpD,aAAa;CACb,eAAe;CACf,eAAe;CACf,eAAe;CACf,OAAO;CACP,OAAO;AACR,CAAC;AACD,MAAM,oBAAoB,OAA2B;CACpD,aAAa;CACb,QAAQ;CACR,OAAO;AACR,CAAC;AACD,MAAM,iBAAiB,OAAkC;CAAE,OAAO;CAAM,OAAO;AAAK,CAAC;;AAGrF,MAAM,0BAA0B;AAEhC,MAAM,gBACL;;;;;AAMD,MAAa,iBAAiB,SAAiC,WAAmC;CACjG,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,WAAW,QAAQ;CACzB,MAAM,WAA0B,CAAC;CACjC,IAAI,OAAO,WAAW,OAAO;EAC5B,MAAM,KACL,OAAO,UACP,QAAQ,oBACP,SAAS,WAAW,IAAI,SAAS,IAAI,KAAK,KAAA;EAC5C,IAAI,SAAS,MAAM,YAAY,QAAQ,OAAO,MAAM,QAAQ,YAAY,KAAA,CAAS,GAChF,SAAS,KAAK,QAAQ;CAExB;CACA,MAAM,YACL,QAAQ,QAAQ,WAAW,UAAU,KAAK,QAAQ,WAAW,YAAY,KAAA;CAC1E,IACC,UACA,OAAO,WAAW,UACjB,aAAa,SAAS,MAAM,YAAY,QAAQ,YAAY,KAAA,CAAS,IAEtE,S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AAQ,cAAc;EAC5D,WAAW,iBAAiB,QAAQ,SAAS;EAC7C,MAAM,YAAY,QAAQ,IAAI;CAC/B;AACD;;AAGA,MAAa,gBACZ,YACmE;CACnE,MAAM,OAAO,QAAQ;CACrB,IAAI,SAAS,KAAA,MAAc,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,IAC5D,MAAM,IAAI,MACT,mEAAmE,OAAO,IAAI,GAC/E;CAED,MAAM,WAAoB,QAAQ;CAClC,IAAI,aAAa,KAAA,KAAa,CAAC,kBAAkB,QAAQ,GACxD,MAAM,IAAI,MACT,oEAAoE,OAAO,QAAQ,GACpF;CAED,IAAI,SAAS,KAAA,KAAa,aAAa,KAAA,GACtC,MAAM,IAAI,MACT,2OACD;CAED,OAAO;EACN,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB,KAAK;EACvD,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB,SAAS;CAC/D;AACD;;;;;AAMA,MAAa,0BACZ,UAIA,eACmB;CACnB,IACC,CAAC,cACD,SAAS,qBAAqB,KAAA,KAC9B,SAAS,oBAAoB,KAAA,GAE7B,OAAO;CAQR,OALC,SAAS,UAAU,WAAW,WAC9B,SAAS,UAAU,YAAY,KAAA,KAC/B,SAAS,SAAS,MAChB,YAAY,QAAQ,WAAW,KAAA,MAAc,QAAQ,SAAS,MAAM,OAAO,UAAU,KAAK,CAC5F,IAEE,qVACA;AACJ;;;;;AAMA,MAAa,6BACZ,aAEA,SAAS,QAAQ,mBAAmB,KAAA,KAAa,SAAS,QAAQ,8BAC/D,wKACA;;;;;AAMJ,MAAa,yBACZ,UACA,eAEA,cACA,SAAS,QAAQ,+BACjB,SAAS,qBAAqB,KAAA,KAC9B,SAAS,oBAAoB,KAAA,IAC1B,0ZACA"}
@@ -167,6 +167,25 @@ interface AnalyticsResult {
167
167
  * an empty result instead, not this flag.
168
168
  */
169
169
  goalsUnresolved?: true;
170
+ /**
171
+ * Pageviews of the read counted without consent, at a cookieless or anonymous level, which
172
+ * the view shows as a share of all pageviews. Absent when the source cannot tell or found none.
173
+ */
174
+ withoutConsent?: {
175
+ pageviews: number;
176
+ };
177
+ /**
178
+ * Pageviews of the read recorded without a visitor (native's anonymous level): they count as
179
+ * pageviews, and toward no visitor, visit, bounce rate or time.
180
+ */
181
+ withoutVisitor?: {
182
+ pageviews: number;
183
+ };
184
+ /**
185
+ * The vendor drops what a slot counts without consent, so those visits are missing from every
186
+ * number: PostHog with its project's cookieless tracking setting off.
187
+ */
188
+ withoutConsentDropped?: true;
170
189
  };
171
190
  }
172
191
  /**
@@ -339,6 +358,12 @@ interface AdapterRegisterContext {
339
358
  * only other sites whose pages may send to it from a visitor's browser.
340
359
  */
341
360
  allowedOrigins?: ReadonlySet<string>;
361
+ /**
362
+ * False when this adapter fills no slot `capture.gate` holds that can count without consent, as
363
+ * far as the boot can tell, so it need not check its vendor accepts such events. Absent reads as
364
+ * true.
365
+ */
366
+ adapterCountsWithoutConsent?: boolean;
342
367
  /**
343
368
  * The collections bound as content items, the only ones whose refs ingest keeps, and whether
344
369
  * an item is also counted per page it appeared on. Absent means no item is bound.