@aglyn/aglyn 1.0.0-beta.264 → 1.0.0-beta.268

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 (45) hide show
  1. package/package.json +12 -12
  2. package/src/lib/app-utils/account-acquisition.d.ts +13 -0
  3. package/src/lib/app-utils/account-acquisition.js +84 -0
  4. package/src/lib/app-utils/account-acquisition.js.map +1 -1
  5. package/src/lib/app-utils/analytics-events.d.ts +70 -0
  6. package/src/lib/app-utils/analytics-events.js +8 -0
  7. package/src/lib/app-utils/analytics-events.js.map +1 -1
  8. package/src/lib/app-utils/docs-help-sections.generated.js +4 -1
  9. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  10. package/src/lib/app-utils/docs-help.generated.d.ts +2 -2
  11. package/src/lib/app-utils/docs-help.generated.js +8 -1
  12. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  13. package/src/lib/app-utils/docs-index.generated.js +31 -10
  14. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  15. package/src/lib/app-utils/expand-repeatables.js +14 -7
  16. package/src/lib/app-utils/expand-repeatables.js.map +1 -1
  17. package/src/lib/app-utils/health-report.d.ts +120 -8
  18. package/src/lib/app-utils/health-report.js +138 -3
  19. package/src/lib/app-utils/health-report.js.map +1 -1
  20. package/src/lib/app-utils/live-document-count.client.d.ts +28 -0
  21. package/src/lib/app-utils/live-document-count.client.js +35 -0
  22. package/src/lib/app-utils/live-document-count.client.js.map +1 -0
  23. package/src/lib/app-utils/live-document-count.d.ts +91 -0
  24. package/src/lib/app-utils/live-document-count.js +81 -0
  25. package/src/lib/app-utils/live-document-count.js.map +1 -0
  26. package/src/lib/app-utils/notification-sounds.d.ts +49 -0
  27. package/src/lib/app-utils/notification-sounds.js +54 -0
  28. package/src/lib/app-utils/notification-sounds.js.map +1 -0
  29. package/src/lib/app-utils/notifications.d.ts +2 -0
  30. package/src/lib/app-utils/notifications.js +38 -10
  31. package/src/lib/app-utils/notifications.js.map +1 -1
  32. package/src/lib/app-utils/screen-analytics-aggregate.d.ts +10 -0
  33. package/src/lib/app-utils/screen-analytics-aggregate.js +11 -0
  34. package/src/lib/app-utils/screen-analytics-aggregate.js.map +1 -1
  35. package/src/lib/app-utils/upload-inspection.d.ts +9 -0
  36. package/src/lib/app-utils/upload-inspection.js +27 -0
  37. package/src/lib/app-utils/upload-inspection.js.map +1 -1
  38. package/src/lib/plugin-manager/first-party-plugins.generated.js +6 -0
  39. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  40. package/src/lib/plugin-manager/plugin-activity-actions.d.ts +14 -0
  41. package/src/lib/plugin-manager/plugin-activity-actions.js +30 -3
  42. package/src/lib/plugin-manager/plugin-activity-actions.js.map +1 -1
  43. package/src/lib/plugin-manager/plugin-site-erase.d.ts +81 -0
  44. package/src/lib/plugin-manager/plugin-site-erase.js +56 -0
  45. package/src/lib/plugin-manager/plugin-site-erase.js.map +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/aglyn",
3
- "version": "1.0.0-beta.264",
3
+ "version": "1.0.0-beta.268",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -37,16 +37,16 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "dependencies": {
40
- "@aglyn/shared-data-enums": "1.0.0-beta.264",
41
- "@aglyn/shared-data-mdi": "1.0.0-beta.264",
42
- "@aglyn/shared-data-types": "1.0.0-beta.264",
43
- "@aglyn/shared-util-email": "1.0.0-beta.264",
44
- "@aglyn/shared-util-first-touch": "1.0.0-beta.264",
45
- "@aglyn/shared-util-http": "1.0.0-beta.264",
46
- "@aglyn/shared-util-logger": "1.0.0-beta.264",
47
- "@aglyn/shared-util-timestamp": "1.0.0-beta.264",
48
- "@aglyn/shared-util-tools": "1.0.0-beta.264",
49
- "@aglyn/shared-util-vendor": "1.0.0-beta.264",
40
+ "@aglyn/shared-data-enums": "1.0.0-beta.268",
41
+ "@aglyn/shared-data-mdi": "1.0.0-beta.268",
42
+ "@aglyn/shared-data-types": "1.0.0-beta.268",
43
+ "@aglyn/shared-util-email": "1.0.0-beta.268",
44
+ "@aglyn/shared-util-first-touch": "1.0.0-beta.268",
45
+ "@aglyn/shared-util-http": "1.0.0-beta.268",
46
+ "@aglyn/shared-util-logger": "1.0.0-beta.268",
47
+ "@aglyn/shared-util-timestamp": "1.0.0-beta.268",
48
+ "@aglyn/shared-util-tools": "1.0.0-beta.268",
49
+ "@aglyn/shared-util-vendor": "1.0.0-beta.268",
50
50
  "@data-driven-forms/react-form-renderer": "^4.2.0",
51
51
  "@msgpack/msgpack": "^3.1.3",
52
52
  "@types/unist": "^3.0.3",
@@ -61,7 +61,7 @@
61
61
  "peerDependencies": {
62
62
  "@mui/material": "^9.3.1",
63
63
  "@mui/system": "^9.2.0",
64
- "firebase": "^12.18.0",
64
+ "firebase": "^13.0.0",
65
65
  "next": "^16.3.3",
66
66
  "react": "^19.2.8"
67
67
  },
@@ -182,3 +182,16 @@ export declare function providerLabel(provider: string | null | undefined): stri
182
182
  export declare function describeAccountAcquisition(record: AccountAcquisition | null | undefined, options?: {
183
183
  primaryHost?: string | null;
184
184
  }): string;
185
+ /**
186
+ * The record as rows a staff email or card lays out label beside value
187
+ * (AGL-3897): how the person found the platform, where they landed, what
188
+ * the visit carried, how and where they signed up. A row the record has no
189
+ * value for is left out, so an account with nothing captured reads as one
190
+ * honest row rather than a column of blanks.
191
+ */
192
+ export declare function accountAcquisitionDetails(record: AccountAcquisition | null | undefined, options?: {
193
+ primaryHost?: string | null;
194
+ }): Array<{
195
+ label: string;
196
+ value: string;
197
+ }>;
@@ -323,5 +323,89 @@ function doorPhrase(record) {
323
323
  parts.push(doorPhrase(record));
324
324
  return parts.join(' → ');
325
325
  }
326
+ /** A UTC instant as a staff reader writes it: "Oct 16, 2026, 14:03 UTC". */ function acquisitionTime(ms) {
327
+ if (!ms || !Number.isFinite(ms)) return null;
328
+ return `${new Date(ms).toLocaleString('en-US', {
329
+ month: 'short',
330
+ day: 'numeric',
331
+ year: 'numeric',
332
+ hour: '2-digit',
333
+ minute: '2-digit',
334
+ hour12: false,
335
+ timeZone: 'UTC'
336
+ })} UTC`;
337
+ }
338
+ /**
339
+ * The record as rows a staff email or card lays out label beside value
340
+ * (AGL-3897): how the person found the platform, where they landed, what
341
+ * the visit carried, how and where they signed up. A row the record has no
342
+ * value for is left out, so an account with nothing captured reads as one
343
+ * honest row rather than a column of blanks.
344
+ */ export function accountAcquisitionDetails(record, options = {}) {
345
+ var _record_utm, _record_utm1;
346
+ if (!record) return [
347
+ {
348
+ label: 'How they found us',
349
+ value: 'No acquisition record'
350
+ }
351
+ ];
352
+ const rows = [
353
+ {
354
+ label: 'How they found us',
355
+ value: channelPhrase(record)
356
+ },
357
+ {
358
+ label: 'Landing page',
359
+ value: record.landing ? options.primaryHost && displayHost(record.landing.host) === displayHost(options.primaryHost) ? record.landing.path : `${displayHost(record.landing.host)}${record.landing.path}` : null
360
+ },
361
+ {
362
+ label: 'Referrer',
363
+ value: record.referrerHost ? displayHost(record.referrerHost) : null
364
+ },
365
+ {
366
+ label: 'Source / medium',
367
+ value: record.source && record.source !== 'unknown' ? [
368
+ record.source,
369
+ record.medium
370
+ ].filter(Boolean).join(' / ') : null
371
+ },
372
+ {
373
+ label: 'Campaign',
374
+ value: record.campaign
375
+ },
376
+ {
377
+ label: 'Google Ads campaign',
378
+ value: record.adCampaignId
379
+ },
380
+ {
381
+ label: 'Ad click',
382
+ value: record.clickIds.length ? record.clickIds.join(', ') : null
383
+ },
384
+ {
385
+ label: 'UTM content / term',
386
+ value: [
387
+ (_record_utm = record.utm) == null ? void 0 : _record_utm.content,
388
+ (_record_utm1 = record.utm) == null ? void 0 : _record_utm1.term
389
+ ].filter(Boolean).join(' / ') || null
390
+ },
391
+ {
392
+ label: 'First visit',
393
+ value: acquisitionTime(record.capturedAt)
394
+ },
395
+ {
396
+ label: 'Signed up',
397
+ value: doorPhrase(record).replace(/^\w/, (first)=>first.toUpperCase())
398
+ },
399
+ {
400
+ label: 'From',
401
+ value: record.geo ? [
402
+ record.geo.city,
403
+ record.geo.region,
404
+ record.geo.country
405
+ ].filter(Boolean).join(', ') || null : null
406
+ }
407
+ ];
408
+ return rows.filter((row)=>Boolean(row.value));
409
+ }
326
410
 
327
411
  //# sourceMappingURL=account-acquisition.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/account-acquisition.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n classifyChannel,\n displayHost,\n sanitizeFirstTouch,\n sourceAndMedium,\n type AcquisitionChannel,\n type FirstTouchClickId,\n type FirstTouchUtm,\n} from '@aglyn/shared-util-first-touch'\n\n/**\n * Where an account came from, written ONCE on the account when it is created\n * (AGL-3289) — `users/{uid}.acquisition`, and on the organization created in\n * the same flow as `orgs/{orgId}.acquisition`.\n *\n * ## Why this exists\n *\n * Answering \"where did this person come from?\" for one new workspace took a\n * sales session twenty-five minutes across five tools: the staff user page\n * had no source, Firestore held nothing beyond names, and the answer — a\n * review site's referral — was finally found in an analytics property and in\n * the marketing host's daily referrer counts. The platform never stored the\n * fact on the account it was about. This record is that fact, read from one\n * card on the staff user and organization pages.\n *\n * ## What writes it, and what never may\n *\n * The capture library keeps the first touch on the visitor's device; the\n * platform turns it into this record at account creation, server-side, and\n * the rules refuse the field to every client — owner and staff alike. A\n * record the account holder could restate would be a record nobody could\n * trust. It is never overwritten: a later touch, if one is ever kept, goes\n * BESIDE it as its own field.\n *\n * Every field here is built from the untrusted touch by re-scrubbing it, the\n * same way the capture scrubbed it on the device, and nothing the record says\n * grants anything: it is a label for a staff reader.\n */\n\n/** The field on `users/{uid}` and `orgs/{orgId}`. */\nexport const ACCOUNT_ACQUISITION_FIELD = 'acquisition'\n\n/**\n * How an account was created: the signup form with a password, the signup\n * form through Google — in a popup, or by the full-page redirect phones use —\n * accepting an invitation, or single sign-on.\n */\nexport const ACQUISITION_DOORS = [\n 'signup-password',\n 'signup-google',\n 'signup-google-redirect',\n 'invite',\n 'sso',\n] as const\nexport type AcquisitionDoor = (typeof ACQUISITION_DOORS)[number] | 'unknown'\n\n/** The sign-up form's doors: the ones a person reaches by signing up themselves. */\nexport type SignUpAcquisitionDoor = Extract<\n AcquisitionDoor,\n 'signup-password' | 'signup-google' | 'signup-google-redirect'\n>\n\n/**\n * The sign-up door an account took, from the provider its VERIFIED token\n * names, or null when that provider is not one the sign-up form offers.\n *\n * The provider decides; the page's `hint` only says which of a provider's\n * doors it was, so a Google account can say \"redirect\" and nothing else — it\n * can never claim the password door, and a password account can never claim\n * a Google one.\n */\nexport function signUpDoorFor(\n provider: string | null | undefined,\n hint?: unknown,\n): SignUpAcquisitionDoor | null {\n if (provider === 'password') return 'signup-password'\n if (provider === 'google.com') {\n return hint === 'signup-google-redirect' ? 'signup-google-redirect' : 'signup-google'\n }\n return null\n}\n\n/** What wrote a record: a door at creation, an organization copying its creator's, or the backfill. */\nexport type AcquisitionRecordedBy = 'signup' | 'sso' | 'org-creation' | 'backfill'\n\n/** Where the account-creating request came from, as the edge reported it. */\nexport interface AcquisitionGeo {\n country: string | null\n region: string | null\n city: string | null\n}\n\n/** The stored record. */\nexport interface AccountAcquisition {\n v: 1\n /**\n * Where the visit came from, spelled the way reports spell it — a\n * `utm_source`, a referring host, `(direct)` — or `unknown` when nothing was\n * captured.\n */\n source: string\n /** `utm_medium`, or what the channel implies; null when unknown. */\n medium: string | null\n /** `utm_campaign`, when the landing URL named one. */\n campaign: string | null\n /** The channel, from the platform's own rule table. */\n channel: AcquisitionChannel\n /** When the first visit landed; null when it was never captured. */\n capturedAt: number | null\n /** The first page the visitor landed on. */\n landing: { host: string; path: string } | null\n /** The external host that sent them. */\n referrerHost: string | null\n /** One of the platform's own hosts they came from before anything captured them. */\n viaHost: string | null\n /** Every `utm_*` the landing URL carried. */\n utm: FirstTouchUtm | null\n /** Which ad click ids the landing URL carried — presence only. */\n clickIds: FirstTouchClickId[]\n /**\n * The Google Ads campaign the click came from (`gad_campaignid`), which\n * auto-tagging appends whether or not the ad carries a `utm_campaign`.\n */\n adCampaignId: string | null\n /** How the account was created. */\n door: AcquisitionDoor\n /** The sign-in provider it was created with: `password`, `google.com`, `saml.…`. */\n provider: string | null\n /** The organization whose invitation the person signed up to accept. */\n invitedToOrgId: string | null\n /** Where the account-creating request came from. */\n geo: AcquisitionGeo | null\n /** When the auth record says the account was created. */\n accountCreatedAt: number | null\n /** When this record was written. */\n recordedAt: number\n recordedBy: AcquisitionRecordedBy\n /** On an organization's copy: the account it was copied from. */\n copiedFromUid?: string\n}\n\nconst MAX_LABEL = 100\nconst PROVIDER_SHAPE = /^[a-z0-9][a-z0-9._-]{0,63}$/i\nconst RECORDED_BY: readonly AcquisitionRecordedBy[] = [\n 'signup',\n 'sso',\n 'org-creation',\n 'backfill',\n]\n\nfunction label(value: unknown, max = MAX_LABEL): string | null {\n if (typeof value !== 'string') return null\n const clean = value.replace(/[\\u0000-\\u001f\\u007f]/g, '').trim() // eslint-disable-line no-control-regex\n return clean ? clean.slice(0, max) : null\n}\n\nfunction doorOf(value: unknown): AcquisitionDoor {\n return (ACQUISITION_DOORS as readonly string[]).includes(value as string)\n ? (value as AcquisitionDoor)\n : 'unknown'\n}\n\nfunction providerOf(value: unknown): string | null {\n return typeof value === 'string' && PROVIDER_SHAPE.test(value.trim())\n ? value.trim().toLowerCase()\n : null\n}\n\nfunction geoOf(value: unknown): AcquisitionGeo | null {\n if (!value || typeof value !== 'object') return null\n const raw = value as Record<string, unknown>\n const geo: AcquisitionGeo = {\n country: label(raw['country'], 8)?.toUpperCase() ?? null,\n region: label(raw['region'], 64),\n city: label(raw['city'], 64),\n }\n return geo.country || geo.region || geo.city ? geo : null\n}\n\nfunction millisOf(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null\n}\n\nfunction uidOf(value: unknown): string | null {\n return typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(value) ? value : null\n}\n\n/** What a door knows when it records an account. */\nexport interface AccountAcquisitionInput {\n /** The first touch the capture kept — untrusted, from the device. */\n touch: unknown\n door: unknown\n provider?: unknown\n geo?: unknown\n invitedToOrgId?: unknown\n /** When the auth record says the account was created. */\n accountCreatedAtMs?: number | null\n recordedBy: AcquisitionRecordedBy\n nowMs: number\n}\n\n/**\n * The record for an account being created now.\n *\n * A missing or unusable touch still produces a record — `source: 'unknown'`\n * with whatever the door knows — because \"we asked and nothing came back\" is\n * a fact about the account too, and a card that renders blank would read as\n * \"never asked\".\n */\nexport function buildAccountAcquisition(input: AccountAcquisitionInput): AccountAcquisition {\n const touch = sanitizeFirstTouch(input.touch, input.nowMs)\n const base = {\n door: doorOf(input.door),\n provider: providerOf(input.provider),\n invitedToOrgId: uidOf(input.invitedToOrgId),\n geo: geoOf(input.geo),\n accountCreatedAt: millisOf(input.accountCreatedAtMs),\n recordedAt: input.nowMs,\n recordedBy: input.recordedBy,\n }\n if (!touch) return unknownAccountAcquisition(base)\n const { source, medium } = sourceAndMedium(touch)\n return {\n v: 1,\n source,\n medium,\n campaign: touch.utm?.campaign ?? null,\n channel: classifyChannel(touch),\n capturedAt: touch.at,\n landing: { host: touch.host, path: touch.path },\n referrerHost: touch.ref,\n viaHost: touch.via ?? null,\n utm: touch.utm ?? null,\n clickIds: touch.click ?? [],\n adCampaignId: touch.adCampaign ?? null,\n ...base,\n }\n}\n\n/** A record for an account nothing was captured for. */\nexport function unknownAccountAcquisition(input: {\n recordedAt: number\n recordedBy: AcquisitionRecordedBy\n door?: AcquisitionDoor\n provider?: string | null\n invitedToOrgId?: string | null\n geo?: AcquisitionGeo | null\n accountCreatedAt?: number | null\n}): AccountAcquisition {\n return {\n v: 1,\n source: 'unknown',\n medium: null,\n campaign: null,\n channel: 'unknown',\n capturedAt: null,\n landing: null,\n referrerHost: null,\n viaHost: null,\n utm: null,\n clickIds: [],\n adCampaignId: null,\n door: input.door ?? 'unknown',\n provider: input.provider ?? null,\n invitedToOrgId: input.invitedToOrgId ?? null,\n geo: input.geo ?? null,\n accountCreatedAt: input.accountCreatedAt ?? null,\n recordedAt: input.recordedAt,\n recordedBy: input.recordedBy,\n }\n}\n\n/**\n * The organization's copy of its creator's record, or an `unknown` one naming\n * the creator when the account has none — so an organization's card is never\n * blank either, and always says whose record it is.\n */\nexport function organizationAcquisition(\n creatorRecord: unknown,\n creatorUid: string,\n nowMs: number,\n): AccountAcquisition {\n const record = readAccountAcquisition(creatorRecord)\n const copied = record\n ? { ...record }\n : unknownAccountAcquisition({ recordedAt: nowMs, recordedBy: 'org-creation' })\n delete copied.copiedFromUid\n return { ...copied, copiedFromUid: creatorUid }\n}\n\n/**\n * A stored record as a reader should trust it: re-validated field by field,\n * so a document written by an older version, a backfill or a hand edit still\n * renders, and renders nothing it should not. Null when the value is not a\n * record at all.\n */\nexport function readAccountAcquisition(value: unknown): AccountAcquisition | null {\n if (!value || typeof value !== 'object') return null\n const raw = value as Record<string, unknown>\n const source = label(raw['source'])\n if (!source) return null\n const channel = raw['channel']\n const landing = raw['landing'] as Record<string, unknown> | null\n const utmRaw = raw['utm'] as Record<string, unknown> | null\n const utm: FirstTouchUtm = {}\n for (const key of ['source', 'medium', 'campaign', 'content', 'term'] as const) {\n const cleaned = label(utmRaw?.[key])\n if (cleaned) utm[key] = cleaned\n }\n const clickIds = Array.isArray(raw['clickIds'])\n ? (['gclid', 'fbclid', 'msclkid'] as const).filter((id) =>\n (raw['clickIds'] as unknown[]).includes(id),\n )\n : []\n const recordedBy = RECORDED_BY.includes(raw['recordedBy'] as AcquisitionRecordedBy)\n ? (raw['recordedBy'] as AcquisitionRecordedBy)\n : 'backfill'\n const record: AccountAcquisition = {\n v: 1,\n source,\n medium: label(raw['medium']),\n campaign: label(raw['campaign']),\n channel:\n typeof channel === 'string' &&\n [\n 'organic-search',\n 'paid-search',\n 'social',\n 'referral',\n 'email',\n 'direct',\n 'unknown',\n ].includes(channel)\n ? (channel as AcquisitionChannel)\n : 'unknown',\n capturedAt:\n typeof raw['capturedAt'] === 'number' && raw['capturedAt'] > 0\n ? (raw['capturedAt'] as number)\n : null,\n landing:\n landing && label(landing['host'], 253)\n ? { host: label(landing['host'], 253) as string, path: label(landing['path'], 200) ?? '/' }\n : null,\n referrerHost: label(raw['referrerHost'], 253),\n viaHost: label(raw['viaHost'], 253),\n utm: Object.keys(utm).length ? utm : null,\n clickIds,\n adCampaignId:\n typeof raw['adCampaignId'] === 'string' && /^\\d{1,20}$/.test(raw['adCampaignId'])\n ? raw['adCampaignId']\n : null,\n door: doorOf(raw['door']),\n provider: providerOf(raw['provider']),\n invitedToOrgId: uidOf(raw['invitedToOrgId']),\n geo: geoOf(raw['geo']),\n accountCreatedAt: millisOf(raw['accountCreatedAt']),\n recordedAt:\n typeof raw['recordedAt'] === 'number' ? (raw['recordedAt'] as number) : 0,\n recordedBy,\n }\n const copiedFrom = uidOf(raw['copiedFromUid'])\n if (copiedFrom) record.copiedFromUid = copiedFrom\n return record\n}\n\n/** The Google Ads page for a campaign id, opened in whichever account is signed in. */\nexport function googleAdsCampaignUrl(campaignId: string): string {\n return `https://ads.google.com/aw/campaigns?campaignId=${encodeURIComponent(campaignId)}`\n}\n\n/** A sign-in provider id as a person reads it. */\nexport function providerLabel(provider: string | null | undefined): string | null {\n if (!provider) return null\n if (provider === 'password') return 'password'\n if (provider === 'google.com') return 'Google'\n if (provider === 'apple.com') return 'Apple'\n if (provider === 'microsoft.com') return 'Microsoft'\n if (provider === 'github.com') return 'GitHub'\n if (provider.startsWith('saml.') || provider.startsWith('oidc.')) return 'single sign-on'\n return provider\n}\n\nfunction channelPhrase(record: AccountAcquisition): string {\n const from = displayHost(record.referrerHost) || record.source\n const named = record.campaign ?? (record.adCampaignId ? `campaign ${record.adCampaignId}` : null)\n const campaign = named ? `, ${named}` : ''\n switch (record.channel) {\n case 'referral':\n return `Referral from ${from}${campaign}`\n case 'organic-search':\n return `Organic search from ${from}`\n case 'paid-search':\n return `Paid search (${record.source}${campaign})`\n case 'social':\n return `Social from ${from}${campaign}`\n case 'email':\n return `Email (${record.source}${campaign})`\n case 'direct':\n return record.viaHost\n ? `Direct, first seen arriving from ${record.viaHost}`\n : 'Direct'\n default:\n return record.recordedBy === 'backfill'\n ? 'Source unknown — the account predates capture'\n : 'Source unknown — nothing was captured'\n }\n}\n\nfunction doorPhrase(record: AccountAcquisition): string {\n const provider = providerLabel(record.provider)\n switch (record.door) {\n case 'signup-password':\n return 'signed up with password'\n case 'signup-google':\n return 'signed up with Google'\n case 'signup-google-redirect':\n return 'signed up with Google, by redirect'\n case 'invite':\n return provider\n ? `signed up from an invitation, with ${provider}`\n : 'signed up from an invitation'\n case 'sso':\n return 'signed in with single sign-on'\n default:\n return provider ? `created with ${provider}` : 'created'\n }\n}\n\n/**\n * The record as one sentence a staff member reads at a glance:\n * \"Referral from g2.com → /pricing → signed up with password\".\n *\n * The landing is a bare path when it was on `primaryHost` — the platform's own\n * home — and host-and-path anywhere else, so a docs landing says so.\n */\nexport function describeAccountAcquisition(\n record: AccountAcquisition | null | undefined,\n options: { primaryHost?: string | null } = {},\n): string {\n if (!record) return 'No acquisition record'\n const parts = [channelPhrase(record)]\n if (record.landing) {\n const onPrimary =\n options.primaryHost &&\n displayHost(record.landing.host) === displayHost(options.primaryHost)\n parts.push(\n onPrimary ? record.landing.path : `${displayHost(record.landing.host)}${record.landing.path}`,\n )\n }\n parts.push(doorPhrase(record))\n return parts.join(' → ')\n}\n"],"names":["classifyChannel","displayHost","sanitizeFirstTouch","sourceAndMedium","ACCOUNT_ACQUISITION_FIELD","ACQUISITION_DOORS","signUpDoorFor","provider","hint","MAX_LABEL","PROVIDER_SHAPE","RECORDED_BY","label","value","max","clean","replace","trim","slice","doorOf","includes","providerOf","test","toLowerCase","geoOf","raw","geo","country","toUpperCase","region","city","millisOf","Number","isFinite","uidOf","buildAccountAcquisition","input","touch","nowMs","base","door","invitedToOrgId","accountCreatedAt","accountCreatedAtMs","recordedAt","recordedBy","unknownAccountAcquisition","source","medium","v","campaign","utm","channel","capturedAt","at","landing","host","path","referrerHost","ref","viaHost","via","clickIds","click","adCampaignId","adCampaign","organizationAcquisition","creatorRecord","creatorUid","record","readAccountAcquisition","copied","copiedFromUid","utmRaw","key","cleaned","Array","isArray","filter","id","Object","keys","length","copiedFrom","googleAdsCampaignUrl","campaignId","encodeURIComponent","providerLabel","startsWith","channelPhrase","from","named","doorPhrase","describeAccountAcquisition","options","parts","onPrimary","primaryHost","push","join"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,eAAe,EACfC,WAAW,EACXC,kBAAkB,EAClBC,eAAe,QAIV,iCAAgC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GAED,mDAAmD,GACnD,OAAO,MAAMC,4BAA4B,cAAa;AAEtD;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;CACD,CAAS;AASV;;;;;;;;CAQC,GACD,OAAO,SAASC,cACdC,QAAmC,EACnCC,IAAc;IAEd,IAAID,aAAa,YAAY,OAAO;IACpC,IAAIA,aAAa,cAAc;QAC7B,OAAOC,SAAS,2BAA2B,2BAA2B;IACxE;IACA,OAAO;AACT;AA6DA,MAAMC,YAAY;AAClB,MAAMC,iBAAiB;AACvB,MAAMC,cAAgD;IACpD;IACA;IACA;IACA;CACD;AAED,SAASC,MAAMC,KAAc,EAAEC,MAAML,SAAS;IAC5C,IAAI,OAAOI,UAAU,UAAU,OAAO;IACtC,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N;YACE,OAAOS,OAAOxB,UAAU,KAAK,aACzB,kDACA;IACR;AACF;AAEA,SAAS+C,WAAWvB,MAA0B;IAC5C,MAAM9D,WAAWgF,cAAclB,OAAO9D,QAAQ;IAC9C,OAAQ8D,OAAO7B,IAAI;QACjB,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAOjC,WACH,CAAC,mCAAmC,EAAEA,UAAU,GAChD;QACN,KAAK;YACH,OAAO;QACT;YACE,OAAOA,WAAW,CAAC,aAAa,EAAEA,UAAU,GAAG;IACnD;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASsF,2BACdxB,MAA6C,EAC7CyB,UAA2C,CAAC,CAAC;IAE7C,IAAI,CAACzB,QAAQ,OAAO;IACpB,MAAM0B,QAAQ;QAACN,cAAcpB;KAAQ;IACrC,IAAIA,OAAOd,OAAO,EAAE;QAClB,MAAMyC,YACJF,QAAQG,WAAW,IACnBhG,YAAYoE,OAAOd,OAAO,CAACC,IAAI,MAAMvD,YAAY6F,QAAQG,WAAW;QACtEF,MAAMG,IAAI,CACRF,YAAY3B,OAAOd,OAAO,CAACE,IAAI,GAAG,GAAGxD,YAAYoE,OAAOd,OAAO,CAACC,IAAI,IAAIa,OAAOd,OAAO,CAACE,IAAI,EAAE;IAEjG;IACAsC,MAAMG,IAAI,CAACN,WAAWvB;IACtB,OAAO0B,MAAMI,IAAI,CAAC;AACpB"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/account-acquisition.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n classifyChannel,\n displayHost,\n sanitizeFirstTouch,\n sourceAndMedium,\n type AcquisitionChannel,\n type FirstTouchClickId,\n type FirstTouchUtm,\n} from '@aglyn/shared-util-first-touch'\n\n/**\n * Where an account came from, written ONCE on the account when it is created\n * (AGL-3289) — `users/{uid}.acquisition`, and on the organization created in\n * the same flow as `orgs/{orgId}.acquisition`.\n *\n * ## Why this exists\n *\n * Answering \"where did this person come from?\" for one new workspace took a\n * sales session twenty-five minutes across five tools: the staff user page\n * had no source, Firestore held nothing beyond names, and the answer — a\n * review site's referral — was finally found in an analytics property and in\n * the marketing host's daily referrer counts. The platform never stored the\n * fact on the account it was about. This record is that fact, read from one\n * card on the staff user and organization pages.\n *\n * ## What writes it, and what never may\n *\n * The capture library keeps the first touch on the visitor's device; the\n * platform turns it into this record at account creation, server-side, and\n * the rules refuse the field to every client — owner and staff alike. A\n * record the account holder could restate would be a record nobody could\n * trust. It is never overwritten: a later touch, if one is ever kept, goes\n * BESIDE it as its own field.\n *\n * Every field here is built from the untrusted touch by re-scrubbing it, the\n * same way the capture scrubbed it on the device, and nothing the record says\n * grants anything: it is a label for a staff reader.\n */\n\n/** The field on `users/{uid}` and `orgs/{orgId}`. */\nexport const ACCOUNT_ACQUISITION_FIELD = 'acquisition'\n\n/**\n * How an account was created: the signup form with a password, the signup\n * form through Google — in a popup, or by the full-page redirect phones use —\n * accepting an invitation, or single sign-on.\n */\nexport const ACQUISITION_DOORS = [\n 'signup-password',\n 'signup-google',\n 'signup-google-redirect',\n 'invite',\n 'sso',\n] as const\nexport type AcquisitionDoor = (typeof ACQUISITION_DOORS)[number] | 'unknown'\n\n/** The sign-up form's doors: the ones a person reaches by signing up themselves. */\nexport type SignUpAcquisitionDoor = Extract<\n AcquisitionDoor,\n 'signup-password' | 'signup-google' | 'signup-google-redirect'\n>\n\n/**\n * The sign-up door an account took, from the provider its VERIFIED token\n * names, or null when that provider is not one the sign-up form offers.\n *\n * The provider decides; the page's `hint` only says which of a provider's\n * doors it was, so a Google account can say \"redirect\" and nothing else — it\n * can never claim the password door, and a password account can never claim\n * a Google one.\n */\nexport function signUpDoorFor(\n provider: string | null | undefined,\n hint?: unknown,\n): SignUpAcquisitionDoor | null {\n if (provider === 'password') return 'signup-password'\n if (provider === 'google.com') {\n return hint === 'signup-google-redirect' ? 'signup-google-redirect' : 'signup-google'\n }\n return null\n}\n\n/** What wrote a record: a door at creation, an organization copying its creator's, or the backfill. */\nexport type AcquisitionRecordedBy = 'signup' | 'sso' | 'org-creation' | 'backfill'\n\n/** Where the account-creating request came from, as the edge reported it. */\nexport interface AcquisitionGeo {\n country: string | null\n region: string | null\n city: string | null\n}\n\n/** The stored record. */\nexport interface AccountAcquisition {\n v: 1\n /**\n * Where the visit came from, spelled the way reports spell it — a\n * `utm_source`, a referring host, `(direct)` — or `unknown` when nothing was\n * captured.\n */\n source: string\n /** `utm_medium`, or what the channel implies; null when unknown. */\n medium: string | null\n /** `utm_campaign`, when the landing URL named one. */\n campaign: string | null\n /** The channel, from the platform's own rule table. */\n channel: AcquisitionChannel\n /** When the first visit landed; null when it was never captured. */\n capturedAt: number | null\n /** The first page the visitor landed on. */\n landing: { host: string; path: string } | null\n /** The external host that sent them. */\n referrerHost: string | null\n /** One of the platform's own hosts they came from before anything captured them. */\n viaHost: string | null\n /** Every `utm_*` the landing URL carried. */\n utm: FirstTouchUtm | null\n /** Which ad click ids the landing URL carried — presence only. */\n clickIds: FirstTouchClickId[]\n /**\n * The Google Ads campaign the click came from (`gad_campaignid`), which\n * auto-tagging appends whether or not the ad carries a `utm_campaign`.\n */\n adCampaignId: string | null\n /** How the account was created. */\n door: AcquisitionDoor\n /** The sign-in provider it was created with: `password`, `google.com`, `saml.…`. */\n provider: string | null\n /** The organization whose invitation the person signed up to accept. */\n invitedToOrgId: string | null\n /** Where the account-creating request came from. */\n geo: AcquisitionGeo | null\n /** When the auth record says the account was created. */\n accountCreatedAt: number | null\n /** When this record was written. */\n recordedAt: number\n recordedBy: AcquisitionRecordedBy\n /** On an organization's copy: the account it was copied from. */\n copiedFromUid?: string\n}\n\nconst MAX_LABEL = 100\nconst PROVIDER_SHAPE = /^[a-z0-9][a-z0-9._-]{0,63}$/i\nconst RECORDED_BY: readonly AcquisitionRecordedBy[] = [\n 'signup',\n 'sso',\n 'org-creation',\n 'backfill',\n]\n\nfunction label(value: unknown, max = MAX_LABEL): string | null {\n if (typeof value !== 'string') return null\n const clean = value.replace(/[\\u0000-\\u001f\\u007f]/g, '').trim() // eslint-disable-line no-control-regex\n return clean ? clean.slice(0, max) : null\n}\n\nfunction doorOf(value: unknown): AcquisitionDoor {\n return (ACQUISITION_DOORS as readonly string[]).includes(value as string)\n ? (value as AcquisitionDoor)\n : 'unknown'\n}\n\nfunction providerOf(value: unknown): string | null {\n return typeof value === 'string' && PROVIDER_SHAPE.test(value.trim())\n ? value.trim().toLowerCase()\n : null\n}\n\nfunction geoOf(value: unknown): AcquisitionGeo | null {\n if (!value || typeof value !== 'object') return null\n const raw = value as Record<string, unknown>\n const geo: AcquisitionGeo = {\n country: label(raw['country'], 8)?.toUpperCase() ?? null,\n region: label(raw['region'], 64),\n city: label(raw['city'], 64),\n }\n return geo.country || geo.region || geo.city ? geo : null\n}\n\nfunction millisOf(value: unknown): number | null {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null\n}\n\nfunction uidOf(value: unknown): string | null {\n return typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(value) ? value : null\n}\n\n/** What a door knows when it records an account. */\nexport interface AccountAcquisitionInput {\n /** The first touch the capture kept — untrusted, from the device. */\n touch: unknown\n door: unknown\n provider?: unknown\n geo?: unknown\n invitedToOrgId?: unknown\n /** When the auth record says the account was created. */\n accountCreatedAtMs?: number | null\n recordedBy: AcquisitionRecordedBy\n nowMs: number\n}\n\n/**\n * The record for an account being created now.\n *\n * A missing or unusable touch still produces a record — `source: 'unknown'`\n * with whatever the door knows — because \"we asked and nothing came back\" is\n * a fact about the account too, and a card that renders blank would read as\n * \"never asked\".\n */\nexport function buildAccountAcquisition(input: AccountAcquisitionInput): AccountAcquisition {\n const touch = sanitizeFirstTouch(input.touch, input.nowMs)\n const base = {\n door: doorOf(input.door),\n provider: providerOf(input.provider),\n invitedToOrgId: uidOf(input.invitedToOrgId),\n geo: geoOf(input.geo),\n accountCreatedAt: millisOf(input.accountCreatedAtMs),\n recordedAt: input.nowMs,\n recordedBy: input.recordedBy,\n }\n if (!touch) return unknownAccountAcquisition(base)\n const { source, medium } = sourceAndMedium(touch)\n return {\n v: 1,\n source,\n medium,\n campaign: touch.utm?.campaign ?? null,\n channel: classifyChannel(touch),\n capturedAt: touch.at,\n landing: { host: touch.host, path: touch.path },\n referrerHost: touch.ref,\n viaHost: touch.via ?? null,\n utm: touch.utm ?? null,\n clickIds: touch.click ?? [],\n adCampaignId: touch.adCampaign ?? null,\n ...base,\n }\n}\n\n/** A record for an account nothing was captured for. */\nexport function unknownAccountAcquisition(input: {\n recordedAt: number\n recordedBy: AcquisitionRecordedBy\n door?: AcquisitionDoor\n provider?: string | null\n invitedToOrgId?: string | null\n geo?: AcquisitionGeo | null\n accountCreatedAt?: number | null\n}): AccountAcquisition {\n return {\n v: 1,\n source: 'unknown',\n medium: null,\n campaign: null,\n channel: 'unknown',\n capturedAt: null,\n landing: null,\n referrerHost: null,\n viaHost: null,\n utm: null,\n clickIds: [],\n adCampaignId: null,\n door: input.door ?? 'unknown',\n provider: input.provider ?? null,\n invitedToOrgId: input.invitedToOrgId ?? null,\n geo: input.geo ?? null,\n accountCreatedAt: input.accountCreatedAt ?? null,\n recordedAt: input.recordedAt,\n recordedBy: input.recordedBy,\n }\n}\n\n/**\n * The organization's copy of its creator's record, or an `unknown` one naming\n * the creator when the account has none — so an organization's card is never\n * blank either, and always says whose record it is.\n */\nexport function organizationAcquisition(\n creatorRecord: unknown,\n creatorUid: string,\n nowMs: number,\n): AccountAcquisition {\n const record = readAccountAcquisition(creatorRecord)\n const copied = record\n ? { ...record }\n : unknownAccountAcquisition({ recordedAt: nowMs, recordedBy: 'org-creation' })\n delete copied.copiedFromUid\n return { ...copied, copiedFromUid: creatorUid }\n}\n\n/**\n * A stored record as a reader should trust it: re-validated field by field,\n * so a document written by an older version, a backfill or a hand edit still\n * renders, and renders nothing it should not. Null when the value is not a\n * record at all.\n */\nexport function readAccountAcquisition(value: unknown): AccountAcquisition | null {\n if (!value || typeof value !== 'object') return null\n const raw = value as Record<string, unknown>\n const source = label(raw['source'])\n if (!source) return null\n const channel = raw['channel']\n const landing = raw['landing'] as Record<string, unknown> | null\n const utmRaw = raw['utm'] as Record<string, unknown> | null\n const utm: FirstTouchUtm = {}\n for (const key of ['source', 'medium', 'campaign', 'content', 'term'] as const) {\n const cleaned = label(utmRaw?.[key])\n if (cleaned) utm[key] = cleaned\n }\n const clickIds = Array.isArray(raw['clickIds'])\n ? (['gclid', 'fbclid', 'msclkid'] as const).filter((id) =>\n (raw['clickIds'] as unknown[]).includes(id),\n )\n : []\n const recordedBy = RECORDED_BY.includes(raw['recordedBy'] as AcquisitionRecordedBy)\n ? (raw['recordedBy'] as AcquisitionRecordedBy)\n : 'backfill'\n const record: AccountAcquisition = {\n v: 1,\n source,\n medium: label(raw['medium']),\n campaign: label(raw['campaign']),\n channel:\n typeof channel === 'string' &&\n [\n 'organic-search',\n 'paid-search',\n 'social',\n 'referral',\n 'email',\n 'direct',\n 'unknown',\n ].includes(channel)\n ? (channel as AcquisitionChannel)\n : 'unknown',\n capturedAt:\n typeof raw['capturedAt'] === 'number' && raw['capturedAt'] > 0\n ? (raw['capturedAt'] as number)\n : null,\n landing:\n landing && label(landing['host'], 253)\n ? { host: label(landing['host'], 253) as string, path: label(landing['path'], 200) ?? '/' }\n : null,\n referrerHost: label(raw['referrerHost'], 253),\n viaHost: label(raw['viaHost'], 253),\n utm: Object.keys(utm).length ? utm : null,\n clickIds,\n adCampaignId:\n typeof raw['adCampaignId'] === 'string' && /^\\d{1,20}$/.test(raw['adCampaignId'])\n ? raw['adCampaignId']\n : null,\n door: doorOf(raw['door']),\n provider: providerOf(raw['provider']),\n invitedToOrgId: uidOf(raw['invitedToOrgId']),\n geo: geoOf(raw['geo']),\n accountCreatedAt: millisOf(raw['accountCreatedAt']),\n recordedAt:\n typeof raw['recordedAt'] === 'number' ? (raw['recordedAt'] as number) : 0,\n recordedBy,\n }\n const copiedFrom = uidOf(raw['copiedFromUid'])\n if (copiedFrom) record.copiedFromUid = copiedFrom\n return record\n}\n\n/** The Google Ads page for a campaign id, opened in whichever account is signed in. */\nexport function googleAdsCampaignUrl(campaignId: string): string {\n return `https://ads.google.com/aw/campaigns?campaignId=${encodeURIComponent(campaignId)}`\n}\n\n/** A sign-in provider id as a person reads it. */\nexport function providerLabel(provider: string | null | undefined): string | null {\n if (!provider) return null\n if (provider === 'password') return 'password'\n if (provider === 'google.com') return 'Google'\n if (provider === 'apple.com') return 'Apple'\n if (provider === 'microsoft.com') return 'Microsoft'\n if (provider === 'github.com') return 'GitHub'\n if (provider.startsWith('saml.') || provider.startsWith('oidc.')) return 'single sign-on'\n return provider\n}\n\nfunction channelPhrase(record: AccountAcquisition): string {\n const from = displayHost(record.referrerHost) || record.source\n const named = record.campaign ?? (record.adCampaignId ? `campaign ${record.adCampaignId}` : null)\n const campaign = named ? `, ${named}` : ''\n switch (record.channel) {\n case 'referral':\n return `Referral from ${from}${campaign}`\n case 'organic-search':\n return `Organic search from ${from}`\n case 'paid-search':\n return `Paid search (${record.source}${campaign})`\n case 'social':\n return `Social from ${from}${campaign}`\n case 'email':\n return `Email (${record.source}${campaign})`\n case 'direct':\n return record.viaHost\n ? `Direct, first seen arriving from ${record.viaHost}`\n : 'Direct'\n default:\n return record.recordedBy === 'backfill'\n ? 'Source unknown — the account predates capture'\n : 'Source unknown — nothing was captured'\n }\n}\n\nfunction doorPhrase(record: AccountAcquisition): string {\n const provider = providerLabel(record.provider)\n switch (record.door) {\n case 'signup-password':\n return 'signed up with password'\n case 'signup-google':\n return 'signed up with Google'\n case 'signup-google-redirect':\n return 'signed up with Google, by redirect'\n case 'invite':\n return provider\n ? `signed up from an invitation, with ${provider}`\n : 'signed up from an invitation'\n case 'sso':\n return 'signed in with single sign-on'\n default:\n return provider ? `created with ${provider}` : 'created'\n }\n}\n\n/**\n * The record as one sentence a staff member reads at a glance:\n * \"Referral from g2.com → /pricing → signed up with password\".\n *\n * The landing is a bare path when it was on `primaryHost` — the platform's own\n * home — and host-and-path anywhere else, so a docs landing says so.\n */\nexport function describeAccountAcquisition(\n record: AccountAcquisition | null | undefined,\n options: { primaryHost?: string | null } = {},\n): string {\n if (!record) return 'No acquisition record'\n const parts = [channelPhrase(record)]\n if (record.landing) {\n const onPrimary =\n options.primaryHost &&\n displayHost(record.landing.host) === displayHost(options.primaryHost)\n parts.push(\n onPrimary ? record.landing.path : `${displayHost(record.landing.host)}${record.landing.path}`,\n )\n }\n parts.push(doorPhrase(record))\n return parts.join(' → ')\n}\n\n/** A UTC instant as a staff reader writes it: \"Oct 16, 2026, 14:03 UTC\". */\nfunction acquisitionTime(ms: number | null): string | null {\n if (!ms || !Number.isFinite(ms)) return null\n return `${new Date(ms).toLocaleString('en-US', {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n hour12: false,\n timeZone: 'UTC',\n })} UTC`\n}\n\n/**\n * The record as rows a staff email or card lays out label beside value\n * (AGL-3897): how the person found the platform, where they landed, what\n * the visit carried, how and where they signed up. A row the record has no\n * value for is left out, so an account with nothing captured reads as one\n * honest row rather than a column of blanks.\n */\nexport function accountAcquisitionDetails(\n record: AccountAcquisition | null | undefined,\n options: { primaryHost?: string | null } = {},\n): Array<{ label: string; value: string }> {\n if (!record) return [{ label: 'How they found us', value: 'No acquisition record' }]\n const rows: Array<{ label: string; value: string | null }> = [\n { label: 'How they found us', value: channelPhrase(record) },\n {\n label: 'Landing page',\n value: record.landing\n ? options.primaryHost && displayHost(record.landing.host) === displayHost(options.primaryHost)\n ? record.landing.path\n : `${displayHost(record.landing.host)}${record.landing.path}`\n : null,\n },\n { label: 'Referrer', value: record.referrerHost ? displayHost(record.referrerHost) : null },\n {\n label: 'Source / medium',\n value: record.source && record.source !== 'unknown' ? [record.source, record.medium].filter(Boolean).join(' / ') : null,\n },\n { label: 'Campaign', value: record.campaign },\n { label: 'Google Ads campaign', value: record.adCampaignId },\n {\n label: 'Ad click',\n value: record.clickIds.length ? record.clickIds.join(', ') : null,\n },\n {\n label: 'UTM content / term',\n value: [record.utm?.content, record.utm?.term].filter(Boolean).join(' / ') || null,\n },\n { label: 'First visit', value: acquisitionTime(record.capturedAt) },\n { label: 'Signed up', value: doorPhrase(record).replace(/^\\w/, (first) => first.toUpperCase()) },\n {\n label: 'From',\n value: record.geo ? [record.geo.city, record.geo.region, record.geo.country].filter(Boolean).join(', ') || null : null,\n },\n ]\n return rows.filter((row): row is { label: string; value: string } => Boolean(row.value))\n}\n"],"names":["classifyChannel","displayHost","sanitizeFirstTouch","sourceAndMedium","ACCOUNT_ACQUISITION_FIELD","ACQUISITION_DOORS","signUpDoorFor","provider","hint","MAX_LABEL","PROVIDER_SHAPE","RECORDED_BY","label","value","max","clean","replace","trim","slice","doorOf","includes","providerOf","test","toLowerCase","geoOf","raw","geo","country","toUpperCase","region","city","millisOf","Number","isFinite","uidOf","buildAccountAcquisition","input","touch","nowMs","base","door","invitedToOrgId","accountCreatedAt","accountCreatedAtMs","recordedAt","recordedBy","unknownAccountAcquisition","source","medium","v","campaign","utm","channel","capturedAt","at","landing","host","path","referrerHost","ref","viaHost","via","clickIds","click","adCampaignId","adCampaign","organizationAcquisition","creatorRecord","creatorUid","record","readAccountAcquisition","copied","copiedFromUid","utmRaw","key","cleaned","Array","isArray","filter","id","Object","keys","length","copiedFrom","googleAdsCampaignUrl","campaignId","encodeURIComponent","providerLabel","startsWith","channelPhrase","from","named","doorPhrase","describeAccountAcquisition","options","parts","onPrimary","primaryHost","push","join","acquisitionTime","ms","Date","toLocaleString","month","day","year","hour","minute","hour12","timeZone","accountAcquisitionDetails","rows","Boolean","content","term","first","row"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,eAAe,EACfC,WAAW,EACXC,kBAAkB,EAClBC,eAAe,QAIV,iCAAgC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GAED,mDAAmD,GACnD,OAAO,MAAMC,4BAA4B,cAAa;AAEtD;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;CACD,CAAS;AASV;;;;;;;;CAQC,GACD,OAAO,SAASC,cACdC,QAAmC,EACnCC,IAAc;IAEd,IAAID,aAAa,YAAY,OAAO;IACpC,IAAIA,aAAa,cAAc;QAC7B,OAAOC,SAAS,2BAA2B,2BAA2B;IACxE;IACA,OAAO;AACT;AA6DA,MAAMC,YAAY;AAClB,MAAMC,iBAAiB;AACvB,MAAMC,cAAgD;IACpD;IACA;IACA;IACA;CACD;AAED,SAASC,MAAMC,KAAc,EAAEC,MAAML,SAAS;IAC5C,IAAI,OAAOI,UAAU,UAAU,OAAO;IACtC,MAAME,QAAQF,MAAMG,OAAO,CAAC,0BAA0B,IAAIC,IAAI,GAAG,uCAAuC;;IACxG,OAAOF,QAAQA,MAAMG,KAAK,CAAC,GAAGJ,OAAO;AACvC;AAEA,SAASK,OAAON,KAAc;IAC5B,OAAO,AAACR,kBAAwCe,QAAQ,CAACP,SACpDA,QACD;AACN;AAEA,SAASQ,WAAWR,KAAc;IAChC,OAAO,OAAOA,UAAU,YAAYH,eAAeY,IAAI,CAACT,MAAMI,IAAI,MAC9DJ,MAAMI,IAAI,GAAGM,WAAW,KACxB;AACN;AAEA,SAASC,MAAMX,KAAc;;QAIhBD;IAHX,IAAI,CAACC,SAAS,OAAOA,UAAU,UAAU,OAAO;IAChD,MAAMY,MAAMZ;IACZ,MAAMa,MAAsB;QAC1BC,OAAO,WAAEf,SAAAA,MAAMa,GAAG,CAAC,UAAU,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
121
+ /**
122
+ * Custom: no GA4 equivalent (AGL-3898). The guided start's steps, as a
123
+ * funnel: a step was drawn. `step` is the closed step id (`choose`,
124
+ * `kind`, `audience`, `style`, `details`, `review`), `step_index` its
125
+ * place from 0 and `step_count` how many there are. Never an answer: the
126
+ * guided start's params carry step and field ids, counts and durations.
127
+ */
128
+ site_start_step_viewed: {
129
+ step: string;
130
+ step_index: number;
131
+ step_count: number;
132
+ };
133
+ /** Custom (AGL-3898). The person went forward from a step; `duration_ms` is the time spent on it. */
134
+ site_start_step_completed: {
135
+ step: string;
136
+ step_index: number;
137
+ duration_ms: number;
138
+ };
139
+ /** Custom (AGL-3898). The person went back from a step, by Back or an Edit on the review. */
140
+ site_start_step_back: {
141
+ step: string;
142
+ step_index: number;
143
+ duration_ms: number;
144
+ };
145
+ /**
146
+ * Custom (AGL-3898). The guided start was left without a site being started:
147
+ * `reason` is `skip`, `close` (the close control or Escape), `unload` (the
148
+ * tab closed or reloaded) or `route` (the page changed under it). `step` is
149
+ * the last one reached; `total_ms` the time since it opened.
150
+ */
151
+ site_start_abandoned: {
152
+ step: string;
153
+ step_index: number;
154
+ reason: string;
155
+ duration_ms: number;
156
+ total_ms: number;
157
+ };
158
+ /**
159
+ * Custom (AGL-3898). A step refused to go forward on a field: `field` is
160
+ * the answer's id (`siteType`, `audience`, `pages`, `submissions`) and
161
+ * `error` a closed code (`required`, `too_long`, `out_of_range`, `invalid`).
162
+ */
163
+ site_start_field_error: {
164
+ step: string;
165
+ field: string;
166
+ error: string;
167
+ };
168
+ /**
169
+ * Custom (AGL-3898). A sign the person is stuck: `signal` is `edits` (one
170
+ * field changed `count` times) or `idle` (no input on the step for
171
+ * `duration_ms`).
172
+ */
173
+ site_start_struggle: {
174
+ step: string;
175
+ signal: string;
176
+ field?: string;
177
+ count?: number;
178
+ duration_ms?: number;
179
+ };
180
+ /** Custom (AGL-3898). Several fast clicks on one spot; `area` is the closed id of the part of the form clicked. */
181
+ site_start_rage_click: {
182
+ step: string;
183
+ area: string;
184
+ clicks: number;
185
+ };
186
+ /** Custom (AGL-3898). A click on a part of the form that does nothing; `area` as above. */
187
+ site_start_dead_click: {
188
+ step: string;
189
+ area: string;
190
+ };
121
191
  /** Custom: no GA4 equivalent. Stripe Connect onboarding completed. */
122
192
  stripe_connected: Record<string, never>;
123
193
  /** GA4 recommended. A plan checkout started. */
@@ -494,6 +494,14 @@ function scrubValue(value) {
494
494
  host_created: true,
495
495
  site_published: true,
496
496
  site_start_choice: true,
497
+ site_start_step_viewed: true,
498
+ site_start_step_completed: true,
499
+ site_start_step_back: true,
500
+ site_start_abandoned: true,
501
+ site_start_field_error: true,
502
+ site_start_struggle: true,
503
+ site_start_rage_click: true,
504
+ site_start_dead_click: true,
497
505
  stripe_connected: true,
498
506
  begin_checkout: true,
499
507
  purchase: true,