@aglyn/plugins-marketing 1.0.0-beta.231 → 1.0.0-beta.233

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 (54) hide show
  1. package/package.json +16 -16
  2. package/src/lib/components/announcement-bar-card.component.js +1 -0
  3. package/src/lib/components/announcement-bar-card.component.js.map +1 -1
  4. package/src/lib/components/campaign-composer.js +1 -0
  5. package/src/lib/components/campaign-composer.js.map +1 -1
  6. package/src/lib/components/campaign-conversions-card.js +58 -15
  7. package/src/lib/components/campaign-conversions-card.js.map +1 -1
  8. package/src/lib/components/campaign-detail-card.js +51 -5
  9. package/src/lib/components/campaign-detail-card.js.map +1 -1
  10. package/src/lib/components/campaign-edit-drawer.js +2 -0
  11. package/src/lib/components/campaign-edit-drawer.js.map +1 -1
  12. package/src/lib/components/campaign-members-section.js +37 -8
  13. package/src/lib/components/campaign-members-section.js.map +1 -1
  14. package/src/lib/components/campaign-reach-sections.js +3 -0
  15. package/src/lib/components/campaign-reach-sections.js.map +1 -1
  16. package/src/lib/components/campaigns-card.js +64 -10
  17. package/src/lib/components/campaigns-card.js.map +1 -1
  18. package/src/lib/components/email-detail.js +3 -1
  19. package/src/lib/components/email-detail.js.map +1 -1
  20. package/src/lib/components/email-recipients-card.js +37 -2
  21. package/src/lib/components/email-recipients-card.js.map +1 -1
  22. package/src/lib/components/emails-list-card.js +59 -6
  23. package/src/lib/components/emails-list-card.js.map +1 -1
  24. package/src/lib/components/host-experiments-card.component.js +33 -6
  25. package/src/lib/components/host-experiments-card.component.js.map +1 -1
  26. package/src/lib/components/host-marketing-summary-card.component.js +1 -0
  27. package/src/lib/components/host-marketing-summary-card.component.js.map +1 -1
  28. package/src/lib/components/org-experiments-card.js +1 -0
  29. package/src/lib/components/org-experiments-card.js.map +1 -1
  30. package/src/lib/components/org-marketing-overview-card.js +11 -0
  31. package/src/lib/components/org-marketing-overview-card.js.map +1 -1
  32. package/src/lib/components/org-overlays-card.js +1 -0
  33. package/src/lib/components/org-overlays-card.js.map +1 -1
  34. package/src/lib/components/popup-card.component.js +4 -0
  35. package/src/lib/components/popup-card.component.js.map +1 -1
  36. package/src/lib/components/staff-org-email-card.component.js +85 -6
  37. package/src/lib/components/staff-org-email-card.component.js.map +1 -1
  38. package/src/lib/model/campaign-conversions.d.ts +2 -0
  39. package/src/lib/model/campaign-conversions.js +32 -0
  40. package/src/lib/model/campaign-conversions.js.map +1 -1
  41. package/src/lib/model/campaign-list-query.d.ts +6 -2
  42. package/src/lib/model/campaign-list-query.js +64 -9
  43. package/src/lib/model/campaign-list-query.js.map +1 -1
  44. package/src/lib/model/campaign-members-query.d.ts +2 -1
  45. package/src/lib/model/campaign-members-query.js +23 -1
  46. package/src/lib/model/campaign-members-query.js.map +1 -1
  47. package/src/lib/model/experiment-list-query.js +30 -2
  48. package/src/lib/model/experiment-list-query.js.map +1 -1
  49. package/src/lib/model/native-vocabulary.d.ts +26 -0
  50. package/src/lib/model/native-vocabulary.js +31 -0
  51. package/src/lib/model/native-vocabulary.js.map +1 -0
  52. package/src/lib/server/campaign-manage.d.ts +1 -1
  53. package/src/lib/server/campaign-manage.js +1 -0
  54. package/src/lib/server/campaign-manage.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/campaign-reach-sections.tsx"],"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'use client'\n\nimport { AppLink } from '@aglyn/shared-ui-jsx'\nimport {\n Figure,\n MoneyFigure,\n Section,\n} from '@aglyn/shared-ui-jsx/components/measured-figures.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { ScrollTable } from '@aglyn/shared-ui-jsx/components/scroll-table.component'\nimport {\n Alert,\n Button,\n Stack,\n TableBody,\n TableCell,\n TableHead,\n TableRow,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n getCountFromServer,\n getDoc,\n query,\n where,\n} from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { useFirestore } from '@aglyn/tenant-feature-instance'\nimport { type SendLinkRollup } from '@aglyn/shared-ui-email-campaigns/model/send-report'\nimport {\n campaignSequencesReport,\n type CampaignSequencesRollup,\n} from '../model/campaign-report'\nimport { EMAIL_ATTRIBUTION_WINDOW_DAYS } from '@aglyn/shared-util-email'\nimport {\n CAMPAIGN_CONVERSION_KINDS,\n CAMPAIGN_CONVERSION_KIND_COPY,\n type CampaignConversionKind,\n} from '../model/campaign-conversions'\nimport {\n campaignRevenueAcrossSends,\n type CampaignRevenueAcrossSends,\n type CampaignRevenueRollup,\n} from '../model/campaign-revenue'\nimport {\n campaignVisitsReport,\n type CampaignVisitRollup,\n} from '../model/campaign-visits'\nimport {\n campaignSendReportDoc,\n campaignSequenceReportDoc,\n campaignVisitReportDoc,\n} from './campaign-queries'\n\n/**\n * A CAMPAIGN BEYOND ITS MAIL — what it caused, what it earned, and where it\n * sent people.\n *\n * ## Attribution is the mechanism, and there is no other one\n *\n * A campaign owns no screen, no form and no overlay. Nothing in the stored\n * model connects `emailCampaigns/{id}` to a page a visitor lands on:\n * `HostExperiment` names a screen and never a campaign, `HostOverlay` names\n * neither, and a form document carries no campaign field. So a section\n * claiming a campaign CONTAINS a landing page would be inventing an edge, and\n * the containment would be a claim nothing in the data supports.\n *\n * What the data does support is EVIDENCE, of two kinds, and both are already\n * being written:\n *\n * - **Where it sent people.** `campaigns/{sendId}/reports/links` counts\n * clicks per destination URL, so the union across a campaign's emails is\n * the set of pages that campaign drove traffic to — observed rather than\n * declared, which is also why it stays true when a marketer re-points a\n * link.\n * - **What it caused there.** `campaignAttributions` records one row per\n * identify moment — a form submission, a lead, a contact, a booking —\n * carrying the SEND whose link the visitor followed.\n * - **What it earned there.** `campaigns/{sendId}/reports/revenue` buckets\n * the orders credited to that send by currency, so the merge across a\n * campaign's emails is what the campaign was credited with — per currency,\n * because the buckets have units and a total across them would not.\n *\n * All three sections below therefore hang off the campaign's own send ids,\n * which is the only handle any of those collections offers.\n *\n * ## What neither section can say, and says so instead\n *\n * A conversion credited to a WEB touch carries `utm_` labels and no send id.\n * A campaign container has no `utm_` label of its own — a marketer types\n * those into a URL — so there is no join to make, and no amount of matching\n * on the campaign's NAME would be one: two campaigns may share a name, and a\n * label is a string anybody who can vary a query string can mint. The\n * site-wide Conversions section is where the web channel is read, and the\n * copy below points at it rather than quietly leaving it out.\n *\n * A conversion with no touch at all is credited to nobody and is in neither\n * collection. The same holds for an order: one placed by somebody who never\n * clicked is credited to no campaign. That makes a page showing only credited\n * outcomes a partial account by construction, which is why the figures are\n * labelled \"credited to this campaign\" everywhere they appear.\n */\n\n/** Firestore's cap on the values in one `in` filter. */\nconst ID_CHUNK = 30\n\nexport interface CampaignReachProps {\n /**\n * The org whose sends the rollups sit under, `orgs/{orgId}/campaigns/{id}/\n * reports/*`; nothing is read until it is known.\n */\n orgId: string | null\n /**\n * The campaign's emails, by send id — the handle both collections join on.\n *\n * A stable array is not required: both sections key their reads on the\n * joined string, so a caller rebuilding the array every render pays for one\n * set of reads rather than one per render.\n */\n sendIds: readonly string[]\n /** The campaign holds more emails than `sendIds` names. */\n truncated: boolean\n}\n\n/** The ids as one primitive, so an effect depends on the VALUE not the array. */\nconst idsKey = (sendIds: readonly string[]): string => sendIds.join(',')\n\n/** `['a','b','c']` in runs of at most {@link ID_CHUNK}. */\nfunction chunked(ids: readonly string[]): string[][] {\n const out: string[][] = []\n for (let index = 0; index < ids.length; index += ID_CHUNK) {\n out.push(ids.slice(index, index + ID_CHUNK))\n }\n return out\n}\n\n/**\n * WHAT THE CAMPAIGN CAUSED, counted rather than listed.\n *\n * Four aggregation counts over `campaignAttributions`, one per kind, each\n * narrowed to this campaign's own sends. An aggregation is billed per\n * thousand index entries rather than per document, so the honest figure costs\n * about as much as a single row — which is what lets this run on mount\n * instead of behind a button. Listing the records would not: that is the\n * per-record read every figure on this page is arranged to avoid, and the\n * site-wide Conversions section already lists them.\n *\n * The composite index the query needs — `kind` then `campaignId` — is already\n * declared for the conversions list's own campaign-scoped view, and an `in`\n * runs as a disjunction of equalities against that same index.\n *\n * ## The kinds are never added together\n *\n * One form submission by a new person writes a submission, a contact AND a\n * lead: three true statements about one visit. A total would count that visit\n * three times and would look exactly like a bigger number, so there is no\n * total here and the note under the figures says why.\n */\nexport function CampaignConversionsSection(\n props: Omit<CampaignReachProps, 'orgId'> & {\n /**\n * The site whose conversions are counted. Conversions are a site's\n * visitors and are recorded under it, so on the org hub the caller picks\n * one.\n */\n hostId: string\n /**\n * The campaign CONTAINER's own id (AGL-3461). A conversion credited to a\n * page filed under the campaign, to a link labeled for it, or to one of\n * its sequences carries the container's id rather than a send's, so it\n * is counted beside the sends' — and a campaign that never sent an email\n * still has figures.\n */\n campaignId?: string\n /**\n * That site's marketing hub URL, for its conversions list; `null` hides\n * the link rather than pointing it nowhere.\n */\n basePath: string | null\n },\n) {\n const { hostId, sendIds, truncated, basePath, campaignId } = props\n const firestore = useFirestore()\n const key = idsKey(\n campaignId ? [campaignId, ...sendIds.filter((id) => id !== campaignId)] : sendIds,\n )\n const [counts, setCounts] = useState<Record<string, number> | null>(null)\n const [failed, setFailed] = useState(false)\n\n useEffect(() => {\n const ids = key ? key.split(',') : []\n setCounts(null)\n setFailed(false)\n if (!ids.length) return\n let active = true\n const attributions = collection(\n firestore,\n 'hosts',\n hostId,\n 'campaignAttributions',\n )\n /*\n * Summed ACROSS chunks, which is safe because a record carries exactly\n * one `campaignId`: the chunks partition the send ids, so no record can\n * be counted by two of them.\n */\n void Promise.all(\n CAMPAIGN_CONVERSION_KINDS.map(async (kind) => {\n const perChunk = await Promise.all(\n chunked(ids).map((chunk) =>\n getCountFromServer(\n query(\n attributions,\n where('kind', '==', kind),\n where('campaignId', 'in', chunk),\n ),\n ).then((snapshot) => Number(snapshot.data().count ?? 0)),\n ),\n )\n return [kind, perChunk.reduce((sum, value) => sum + value, 0)] as const\n }),\n )\n .then((entries) => {\n if (active) setCounts(Object.fromEntries(entries))\n })\n .catch(() => {\n /*\n * WITHHELD, never zeroed. A count that failed and a campaign that\n * caused nothing are opposite facts, and rendering the first as the\n * second is the most flattering wrong answer available here.\n */\n if (active) setFailed(true)\n })\n return () => {\n active = false\n }\n }, [firestore, hostId, key])\n\n return (\n <Section title=\"What it caused\">\n {!key ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No emails have gone out under this campaign, so nothing can be ' +\n 'credited to it yet.'}\n </Typography>\n ) : failed ? (\n <Alert severity=\"warning\">\n {'The conversions credited to this campaign could not be counted.'}\n </Alert>\n ) : !counts ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Counting what this campaign is credited with…'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n {CAMPAIGN_CONVERSION_KINDS.map((kind: CampaignConversionKind) => (\n <Figure\n key={kind}\n label={CAMPAIGN_CONVERSION_KIND_COPY[kind].label}\n value={counts[kind] ?? 0}\n note={CAMPAIGN_CONVERSION_KIND_COPY[kind].note}\n />\n ))}\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'These count different things about the same visits and are ' +\n 'deliberately not added together — one person filling in one ' +\n 'form appears as a submission, a contact and a lead.'}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {(campaignId\n ? 'Credited to this campaign — a click on one of its emails or ' +\n 'sequences, a link carrying a utm_campaign label it declares, ' +\n 'or a page filed under it, whichever touched the visitor last. '\n : 'Credited to this email. ') +\n 'Somebody who arrived from a utm_ label no campaign declares is ' +\n 'credited to that label instead, and somebody who arrived ' +\n 'directly is credited to nobody — both are counted on the ' +\n 'site’s conversions list.'}\n </Typography>\n {truncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Over the emails listed below. This campaign has sent more ' +\n 'than the page holds, and their conversions are not in these ' +\n 'figures.'}\n </Typography>\n ) : null}\n </Stack>\n )}\n {basePath ? (\n <Stack direction=\"row\">\n <Button\n component={AppLink as any}\n {...({ componentVariant: 'naked', nativeButton: false } as any)}\n href={`${basePath}/conversions`}\n size=\"small\"\n color=\"primary\"\n >\n {'All conversions'}\n </Button>\n </Stack>\n ) : null}\n </Section>\n )\n}\nCampaignConversionsSection.displayName = 'CampaignConversionsSection'\n\n/**\n * The rule the amounts were credited under, in the sentence a reader can\n * check them against.\n *\n * Plural where the campaign is plural. A container can hold emails credited\n * under different models or windows, and printing one of them as though it\n * governed all of them would be the same lie as printing one currency symbol\n * over two currencies.\n */\nfunction creditedUnder(report: CampaignRevenueAcrossSends): string {\n const model = report.models.length === 1 ? report.models[0] : ''\n const rule =\n model === 'last-click'\n ? 'to the last campaign whose link the buyer clicked'\n : model\n ? `under the ${model} model`\n : 'under more than one attribution model'\n const window =\n report.windowDays.length === 1\n ? `within ${report.windowDays[0]} days of that click`\n : `within ${report.windowDays.join(' or ')} days of that click, ` +\n 'depending on the email'\n return `Credited ${rule}, ${window}.`\n}\n\n/**\n * WHAT THE CAMPAIGN EARNED — per currency, and never across them.\n *\n * The same question a campaign of one email answers, answered the same way by\n * a campaign of several: how many messages a container happens to hold is not\n * a fact about whether its revenue is knowable. So this is the same section\n * the single-send report carries — `Revenue`, in the same place in the page's\n * order, drawn by the same money components — over a merge rather than over\n * one document.\n *\n * ## Why it takes a merge, and what the merge may not do\n *\n * `reports/revenue` is written per SEND. There is no container-level rollup\n * and there should not be one: it would have to be kept true against every\n * order and every refund of every email in the campaign, duplicating figures\n * that are already correct one level down. So the campaign's figure is one\n * document per email and an addition — and the addition is the danger.\n *\n * **Currency is to money what kind is to a conversion.** The section above\n * refuses to total form submissions with leads because one visit writes both;\n * this refuses to total USD with EUR because the sum has no unit. Both\n * refusals are structural rather than remembered:\n * {@link campaignRevenueAcrossSends} keys its accumulator on the currency, so\n * amounts in different currencies never reach the same addition, and the\n * result carries no combined field for a screen to print.\n *\n * ## One currency reads as one figure; several read as several\n *\n * The common case is one currency, and it is drawn exactly as a single\n * email's report draws it — net, gross, refunded, orders — with no currency\n * heading, because a label saying `USD` over a page that only ever shows\n * dollars is noise. The moment a second currency appears every block gets its\n * code as a heading and its own email count, and a caveat says in words what\n * the headings say in layout: these do not add up, and nothing here converts\n * between them. The rare case pays for itself; the common one does not pay\n * for the rare one.\n *\n * ## Behind a button, and the button says the price\n *\n * One document per email — the per-record read the conversions section above\n * is shaped to avoid. That section can run on mount because an aggregation is\n * billed per thousand index entries, so its four honest figures cost about as\n * much as a single row however large the campaign is. This cannot: fifty\n * emails is fifty document reads, every time the page opens, for a section\n * most readers of a campaign are not opening the page for. So it is asked\n * for, at the same control and in the same words as the destinations section\n * below, which buys its rows the same way.\n *\n * ## Nothing, and nothing readable, are different sentences\n *\n * The rollup is created by the writer on the first order it credits, so an\n * email with no record has never earned. A campaign where NO email has one\n * has not been shown to have earned nothing — it is also every campaign sent\n * before the join existed and every campaign on a site with no store, which\n * is the distinction the single-send report draws in the same two sentences.\n * A read that is REFUSED shows neither: the figures are withheld behind a\n * warning, and any figures already on screen are dropped rather than left\n * standing beside it, because a stale total under a fresh error is the one\n * arrangement that looks authoritative and is not.\n */\nexport function CampaignRevenueSection(props: CampaignReachProps) {\n const { orgId, sendIds, truncated } = props\n const firestore = useFirestore()\n const key = idsKey(sendIds)\n const [busy, setBusy] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const [report, setReport] = useState<CampaignRevenueAcrossSends | null>(null)\n\n // A merge over one set of emails describes that set. Leaving it on screen\n // after the campaign's emails change labels it as something it is not.\n useEffect(() => {\n setReport(null)\n setError(null)\n }, [key])\n\n const load = useCallback(async () => {\n if (busy) return\n const ids = key ? key.split(',') : []\n if (!ids.length || !orgId) return\n setBusy(true)\n setError(null)\n try {\n const snapshots = await Promise.all(\n ids.map((id) =>\n getDoc(campaignSendReportDoc(firestore, orgId, id, 'revenue')),\n ),\n )\n /*\n * `data()` is `undefined` on a document that does not exist, and it is\n * handed on as `undefined` rather than as an empty rollup: the merge\n * counts the records that EXIST to tell a campaign that earned nothing\n * from one whose revenue was never recorded at all.\n */\n setReport(\n campaignRevenueAcrossSends(\n snapshots.map(\n (snapshot) => snapshot.data() as CampaignRevenueRollup | undefined,\n ),\n ),\n )\n } catch (caught) {\n console.error(caught)\n /*\n * WITHHELD, never zeroed and never left stale. A refused read and a\n * campaign that earned nothing are opposite facts, and the second is\n * the more flattering of the two.\n */\n setReport(null)\n setError('The revenue credited to this campaign could not be read')\n } finally {\n setBusy(false)\n }\n }, [busy, firestore, orgId, key])\n\n const count = key ? key.split(',').length : 0\n\n return (\n <Section title=\"Revenue\">\n {!count ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No emails have gone out under this campaign, so nothing can be ' +\n 'credited to it yet.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'What this campaign’s emails were credited with, read from each ' +\n 'email’s own revenue record and merged by currency.'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Button size=\"small\" onClick={() => void load()} disabled={busy}>\n {busy ? 'Reading…' : report ? 'Read again' : 'Show revenue'}\n </Button>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Reads one record per email — ${count.toLocaleString()} of them.`}\n </Typography>\n </Stack>\n {error ? <Alert severity=\"warning\">{error}</Alert> : null}\n {report ? (\n report.currencies.length ? (\n <Stack spacing={3}>\n {report.caveats.map((caveat) => (\n <Alert key={caveat.id} severity=\"info\">\n {caveat.message}\n </Alert>\n ))}\n {report.currencies.map((entry) => (\n <Stack key={entry.currency} spacing={1}>\n {/*\n * The currency is a HEADING when there is more than one\n * and absent when there is one — the single-send report's\n * rule, so the two shapes of campaign page read alike.\n */}\n {report.multiCurrency ? (\n <Typography variant=\"subtitle2\">\n {entry.currency.toUpperCase()}\n </Typography>\n ) : null}\n <Stack\n direction=\"row\"\n spacing={4}\n useFlexGap\n sx={{ flexWrap: 'wrap' }}\n >\n <MoneyFigure\n label=\"Net revenue\"\n cents={entry.netCents}\n currency={entry.currency}\n note=\"after refunds\"\n />\n <MoneyFigure\n label=\"Gross revenue\"\n cents={entry.grossCents}\n currency={entry.currency}\n note=\"as charged\"\n />\n <MoneyFigure\n label=\"Refunded\"\n cents={entry.refundedCents}\n currency={entry.currency}\n note=\"handed back\"\n />\n <Figure\n label=\"Orders\"\n value={entry.orders}\n note=\"credited to this campaign\"\n />\n <Figure\n label=\"Fully refunded\"\n value={entry.refundedOrders}\n note=\"of those orders\"\n />\n {/*\n * Only where it says something. With one currency this\n * repeats the coverage line under the figures; with\n * two it is what shows the blocks are disjoint parts of\n * the campaign rather than two views of all of it.\n */}\n {report.multiCurrency ? (\n <Figure\n label=\"Emails\"\n value={entry.emails}\n note={`earned in ${entry.currency.toUpperCase()}`}\n />\n ) : null}\n </Stack>\n </Stack>\n ))}\n {/*\n * NO PER-MESSAGE AVERAGE, and this is where a reader of the\n * single-send report would look for one. That page divides by\n * the send's own delivered count, read from the same document\n * at the same instant. A campaign has no such pair — its\n * revenue covers the emails with a revenue record and its\n * delivery total covers the emails that recorded a delivery\n * count, which are different subsets — so the quotient would\n * be an average over a population nobody named.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${report.attributedOrders.toLocaleString()} ` +\n `${report.attributedOrders === 1 ? 'order' : 'orders'} ` +\n `credited, across ${report.recorded.toLocaleString()} of ` +\n `this campaign’s ${report.read.toLocaleString()} ` +\n `${report.read === 1 ? 'email' : 'emails'}. The rest have ` +\n 'never been credited with a sale.'}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${creditedUnder(report)} Clicks only — an open is not ` +\n 'treated as evidence that anybody read the email. An ' +\n 'order placed by somebody who never clicked, or who ' +\n 'checked out without giving an address, is credited to no ' +\n 'campaign, so this is a floor rather than every sale this ' +\n 'campaign influenced.'}\n </Typography>\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {report.recorded\n ? 'No orders have been credited to this campaign.'\n : 'No revenue has been attributed to any of this ' +\n 'campaign’s emails. Orders are credited to the last ' +\n 'campaign whose link the buyer clicked, within ' +\n `${EMAIL_ATTRIBUTION_WINDOW_DAYS} days — emails sent ` +\n 'before that was recorded, or a site with no store, will ' +\n 'never show a figure here.'}\n </Typography>\n )\n ) : null}\n {/*\n OUTSIDE both branches, because it qualifies both. A campaign that\n reports nothing over the emails this page holds has not reported\n nothing about itself, and the emptier answer is the one that most\n needs its population named.\n */}\n {report && truncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Across the ${report.read.toLocaleString()} emails this page ` +\n 'holds. The campaign has sent more.'}\n </Typography>\n ) : null}\n </Stack>\n )}\n </Section>\n )\n}\nCampaignRevenueSection.displayName = 'CampaignRevenueSection'\n\n/** One destination, summed across the campaign's emails. */\ninterface DestinationRow {\n url: string\n clicks: number\n /** How many of the campaign's emails carried a link to it. */\n emails: number\n}\n\n/** What one pass over the campaign's link rollups produced. */\ninterface DestinationsResult {\n rows: DestinationRow[]\n /** Emails whose rollup was read, which is the population the rows describe. */\n read: number\n /** Clicks on destinations past each email's own rollup cap. */\n overflowClicks: number\n /** Clicks that arrived naming no destination at all. */\n unattributedClicks: number\n}\n\n/**\n * WHERE THE CAMPAIGN SENT PEOPLE — the pages its mail pointed at.\n *\n * The union of `campaigns/{sendId}/reports/links` across the campaign's\n * emails, which is the closest the stored data comes to \"the surfaces this\n * campaign runs across\". It is observed rather than declared: a page is on\n * this list because a link in this campaign's mail was followed to it.\n *\n * ## Behind a button, and the button says the price\n *\n * One document per email, up to the ceiling the page holds — which is the\n * per-record read the figures above are shaped to avoid, so it is asked for\n * rather than paid on mount. The same bargain the conversions list makes for\n * its landing-page grouping.\n *\n * ## What a row is, and what it is not\n *\n * A destination is the link's address with its query string dropped, because\n * a campaign body is merged per recipient and a personalised query would mint\n * one row per person — and could carry that person's address into an\n * aggregate the whole team reads. The cost is that two links to one page\n * distinguished only by their tracking parameters are one row, which the note\n * under the table states rather than leaving the reader to discover.\n *\n * Clicks are EVENTS. One reader clicking twice counts twice, so a destination\n * total is not a count of people.\n */\nexport function CampaignDestinationsSection(props: CampaignReachProps) {\n const { orgId, sendIds, truncated } = props\n const firestore = useFirestore()\n const key = idsKey(sendIds)\n const [busy, setBusy] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const [result, setResult] = useState<DestinationsResult | null>(null)\n /*\n * The page is a SLICE of a window this section already holds. One campaign\n * can reach fifty destinations per email over fifty emails, so the row\n * count is bounded by the rollups rather than small — and a table that\n * grows with the campaign gets a footer like every other one.\n */\n const [page, setPage] = useState(0)\n const [pageSize, setPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleRows = useMemo(\n () => (result?.rows ?? []).slice(page * pageSize, page * pageSize + pageSize),\n [result, page, pageSize],\n )\n\n // A grouping read for one set of emails describes that set. Leaving it on\n // screen after the campaign's emails change labels it as something it is not.\n useEffect(() => {\n setResult(null)\n setError(null)\n setPage(0)\n }, [key])\n\n const load = useCallback(async () => {\n if (busy) return\n const ids = key ? key.split(',') : []\n if (!ids.length || !orgId) return\n setBusy(true)\n setError(null)\n try {\n const snapshots = await Promise.all(\n ids.map((id) =>\n getDoc(campaignSendReportDoc(firestore, orgId, id, 'links')),\n ),\n )\n const byUrl = new Map<string, DestinationRow>()\n let overflowClicks = 0\n let unattributedClicks = 0\n snapshots.forEach((snapshot) => {\n const rollup = snapshot.data() as SendLinkRollup | undefined\n if (!rollup) return\n overflowClicks += Number(rollup.overflowClicks ?? 0)\n unattributedClicks += Number(rollup.unattributedClicks ?? 0)\n Object.values(rollup.links ?? {}).forEach((entry) => {\n const url = String(entry?.url ?? '').trim()\n if (!url) return\n const row = byUrl.get(url) ?? { url, clicks: 0, emails: 0 }\n row.clicks += Number(entry?.clicks ?? 0)\n // One rollup holds at most one entry per destination, so this\n // counts EMAILS that linked there rather than link occurrences.\n row.emails += 1\n byUrl.set(url, row)\n })\n })\n setPage(0)\n setResult({\n rows: [...byUrl.values()].sort(\n (a, b) => b.clicks - a.clicks || a.url.localeCompare(b.url),\n ),\n read: ids.length,\n overflowClicks,\n unattributedClicks,\n })\n } catch (caught) {\n console.error(caught)\n setError('The destinations could not be read')\n } finally {\n setBusy(false)\n }\n }, [busy, firestore, orgId, key])\n\n const count = key ? key.split(',').length : 0\n\n return (\n <Section title=\"Where it sent people\">\n {!count ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No emails have gone out under this campaign, so it has sent ' +\n 'nobody anywhere yet.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'The pages this campaign’s links were followed to. A campaign ' +\n 'does not own a page — this is where its mail actually sent ' +\n 'people, read from each email’s own click report.'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Button size=\"small\" onClick={() => void load()} disabled={busy}>\n {busy ? 'Reading…' : result ? 'Read again' : 'Show destinations'}\n </Button>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Reads one record per email — ${count.toLocaleString()} of them.`}\n </Typography>\n </Stack>\n {error ? <Alert severity=\"warning\">{error}</Alert> : null}\n {result ? (\n result.rows.length ? (\n <Stack spacing={0.5}>\n <ScrollTable size=\"small\">\n <TableHead>\n <TableRow>\n <TableCell>{'Destination'}</TableCell>\n <TableCell align=\"right\">{'Emails'}</TableCell>\n <TableCell align=\"right\">{'Clicks'}</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {visibleRows.map((row) => (\n <TableRow key={row.url}>\n <TableCell sx={{ wordBreak: 'break-all' }}>\n {row.url}\n </TableCell>\n <TableCell align=\"right\">\n {row.emails.toLocaleString()}\n </TableCell>\n <TableCell align=\"right\">\n {row.clicks.toLocaleString()}\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </ScrollTable>\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={visibleRows.length}\n count={result.rows.length}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'A destination is the address without its query string, ' +\n 'so two links to one page that differ only in their ' +\n 'tracking parameters are one row. Clicks are events — ' +\n 'one reader clicking twice counts twice.'}\n </Typography>\n {result.overflowClicks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${result.overflowClicks.toLocaleString()} further ` +\n 'clicks landed on destinations past the per-email cap ' +\n 'and are not in the table.'}\n </Typography>\n ) : null}\n {result.unattributedClicks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${result.unattributedClicks.toLocaleString()} clicks ` +\n 'arrived naming no destination, so they belong to no ' +\n 'row.'}\n </Typography>\n ) : null}\n {truncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Across the ${result.read.toLocaleString()} emails this ` +\n 'page holds. The campaign has sent more.'}\n </Typography>\n ) : null}\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'None of this campaign’s emails has recorded a followed ' +\n 'link yet.'}\n </Typography>\n )\n ) : null}\n </Stack>\n )}\n </Section>\n )\n}\nCampaignDestinationsSection.displayName = 'CampaignDestinationsSection'\n\n/**\n * WHAT THE CAMPAIGN'S SEQUENCES PRODUCED (AGL-3254).\n *\n * A sequence joins a campaign from its own document, and the Outreach\n * runtime credits what each enrollment produced to the campaign's one\n * sequences report — `campaignSequenceReports/{campaignId}` on the org,\n * server-only like the conversions rollup, and readable by org-wide members\n * alone: a site collaborator is told it could not be read. One keyed read, joined on the\n * CONTAINER's id rather than on send ids: a sequence's emails are not the\n * campaign's sends, so the join the three sections above make does not\n * exist for it, and the report is written under the campaign directly.\n *\n * Absent is not zero: a campaign no sequence was ever in has no document,\n * and says so in words rather than as five dashes.\n */\nexport function CampaignSequencesSection(props: {\n orgId: string | null\n campaignId: string\n}) {\n const { orgId, campaignId } = props\n const firestore = useFirestore()\n const [rollup, setRollup] = useState<CampaignSequencesRollup | undefined | null>(null)\n const [failed, setFailed] = useState(false)\n\n useEffect(() => {\n let active = true\n setRollup(null)\n setFailed(false)\n if (!orgId) return undefined\n getDoc(campaignSequenceReportDoc(firestore, orgId, campaignId))\n .then((snapshot) => {\n if (active) setRollup((snapshot.data() as CampaignSequencesRollup | undefined) ?? undefined)\n })\n .catch(() => {\n // Withheld, never zeroed — the conversions section's reason.\n if (active) setFailed(true)\n })\n return () => {\n active = false\n }\n }, [firestore, orgId, campaignId])\n\n const report = rollup === null ? null : campaignSequencesReport(rollup)\n\n return (\n <Section title=\"What its sequences produced\">\n {failed ? (\n <Alert severity=\"warning\">{'What this campaign’s sequences produced could not be read.'}</Alert>\n ) : !report ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Reading what this campaign’s sequences produced…'}\n </Typography>\n ) : !report.recorded ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No sequence has been in this campaign. Put one in it from the ' +\n 'sequence’s settings, and everyone enrolled from then on counts here.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n {report.figures.map((figure) => (\n <Figure key={figure.outcome} label={figure.label} value={figure.value} note={figure.note} />\n ))}\n </Stack>\n {report.caveats.map((caveat) => (\n <Typography key={caveat.id} variant=\"caption\" color=\"text.secondary\">\n {caveat.message}\n </Typography>\n ))}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Credited to the campaigns a sequence was in when each person was ' +\n 'enrolled. A meeting counts when it was booked from a link in a ' +\n 'sequence email; a conversion when a lead in a sequence became a contact.'}\n </Typography>\n </Stack>\n )}\n </Section>\n )\n}\nCampaignSequencesSection.displayName = 'CampaignSequencesSection'\n\n/**\n * WHO IT REACHED ON THE SITE (AGL-3461) — first visits and views of the pages\n * filed under the campaign.\n *\n * One keyed read of `orgs/{orgId}/campaignVisitReports/{campaignId}`, which the\n * site collector's `campaignVisit` beacon writes: keyed by the campaign's own\n * id, so this costs one document whatever the traffic. Across every site the\n * campaign is placed on, because the visitors are the campaign's whichever of\n * them they read.\n *\n * Absent is not zero, for the sequences section's reason: a campaign whose\n * pages nobody has opened since counting began has no document, and says so.\n */\nexport function CampaignVisitsSection(props: {\n orgId: string | null\n campaignId: string\n}) {\n const { orgId, campaignId } = props\n const firestore = useFirestore()\n const [rollup, setRollup] = useState<CampaignVisitRollup | undefined | null>(null)\n const [failed, setFailed] = useState(false)\n\n useEffect(() => {\n let active = true\n setRollup(null)\n setFailed(false)\n if (!orgId) return undefined\n getDoc(campaignVisitReportDoc(firestore, orgId, campaignId))\n .then((snapshot) => {\n if (active) setRollup((snapshot.data() as CampaignVisitRollup | undefined) ?? undefined)\n })\n .catch(() => {\n // Withheld, never zeroed — the conversions section's reason.\n if (active) setFailed(true)\n })\n return () => {\n active = false\n }\n }, [firestore, orgId, campaignId])\n\n const report = rollup === null ? null : campaignVisitsReport(rollup)\n\n return (\n <Section title=\"Who it reached\">\n {failed ? (\n <Alert severity=\"warning\">{'The visits to this campaign could not be read.'}</Alert>\n ) : !report ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Reading the visits to this campaign…'}\n </Typography>\n ) : !report.recorded ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No visits yet. File a page under this campaign — or give it the ' +\n 'utm_campaign labels its links carry — and visitors count here ' +\n 'from their next visit.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n <Figure\n label=\"First visits\"\n value={report.firstVisits}\n note={`visitors reaching it for the first time in ${EMAIL_ATTRIBUTION_WINDOW_DAYS} days`}\n />\n <Figure label=\"Page views\" value={report.views} note=\"views of the pages filed under it\" />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'A first visit is a visitor reaching this campaign — on a page filed ' +\n 'under it, or from a link labeled for it — who has not reached it ' +\n `in the last ${EMAIL_ATTRIBUTION_WINDOW_DAYS} days. It is counted ` +\n 'only where the visitor’s device may remember the visit, so ' +\n 'visitors who declined analytics storage are in the page views and ' +\n 'not here. Across every site the campaign is placed on' +\n (report.since\n ? `, since ${new Date(`${report.since}-01T00:00:00Z`).toLocaleDateString(undefined, { month: 'long', year: 'numeric', timeZone: 'UTC' })}.`\n : '.')}\n </Typography>\n </Stack>\n )}\n </Section>\n )\n}\nCampaignVisitsSection.displayName = 'CampaignVisitsSection'\n"],"names":["AppLink","Figure","MoneyFigure","Section","ListPagination","TABLE_PAGE_SIZE_DEFAULT","ScrollTable","Alert","Button","Stack","TableBody","TableCell","TableHead","TableRow","Typography","collection","getCountFromServer","getDoc","query","where","useCallback","useEffect","useMemo","useState","useFirestore","campaignSequencesReport","EMAIL_ATTRIBUTION_WINDOW_DAYS","CAMPAIGN_CONVERSION_KINDS","CAMPAIGN_CONVERSION_KIND_COPY","campaignRevenueAcrossSends","campaignVisitsReport","campaignSendReportDoc","campaignSequenceReportDoc","campaignVisitReportDoc","ID_CHUNK","idsKey","sendIds","join","chunked","ids","out","index","length","push","slice","CampaignConversionsSection","props","hostId","truncated","basePath","campaignId","firestore","key","filter","id","counts","setCounts","failed","setFailed","split","active","attributions","Promise","all","map","kind","perChunk","chunk","then","snapshot","Number","data","count","reduce","sum","value","entries","Object","fromEntries","catch","title","variant","color","severity","spacing","direction","sx","flexWrap","label","note","component","componentVariant","nativeButton","href","size","displayName","creditedUnder","report","model","models","rule","window","windowDays","CampaignRevenueSection","orgId","busy","setBusy","error","setError","setReport","load","snapshots","caught","console","alignItems","onClick","disabled","toLocaleString","currencies","caveats","caveat","message","entry","multiCurrency","currency","toUpperCase","useFlexGap","cents","netCents","grossCents","refundedCents","orders","refundedOrders","emails","attributedOrders","recorded","read","CampaignDestinationsSection","result","setResult","page","setPage","pageSize","setPageSize","visibleRows","rows","byUrl","Map","overflowClicks","unattributedClicks","forEach","rollup","values","links","url","String","trim","row","get","clicks","set","sort","a","b","localeCompare","align","wordBreak","rowCount","onPageChange","onPageSizeChange","CampaignSequencesSection","setRollup","undefined","figures","figure","outcome","CampaignVisitsSection","firstVisits","views","since","Date","toLocaleDateString","month","year","timeZone"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,OAAO,QAAQ,uBAAsB;AAC9C,SACEC,MAAM,EACNC,WAAW,EACXC,OAAO,QACF,6DAA4D;AACnE,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,WAAW,QAAQ,yDAAwD;AACpF,SACEC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,UAAU,QACL,gBAAe;AACtB,SACEC,UAAU,EACVC,kBAAkB,EAClBC,MAAM,EACNC,KAAK,EACLC,KAAK,QACA,qBAAoB;AAC3B,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAASC,YAAY,QAAQ,iCAAgC;AAE7D,SACEC,uBAAuB,QAElB,8BAA0B;AACjC,SAASC,6BAA6B,QAAQ,2BAA0B;AACxE,SACEC,yBAAyB,EACzBC,6BAA6B,QAExB,mCAA+B;AACtC,SACEC,0BAA0B,QAGrB,+BAA2B;AAClC,SACEC,oBAAoB,QAEf,8BAA0B;AACjC,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,sBAAsB,QACjB,wBAAoB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+CC,GAED,sDAAsD,GACtD,MAAMC,WAAW;AAoBjB,+EAA+E,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tF;4BACCuF,OAAM;4BACNb,OAAOsB,OAAOgF,WAAW;4BACzBxF,MAAM,CAAC,2CAA2C,EAAE/D,8BAA8B,KAAK,CAAC;;sCAE1F,KAACzB;4BAAOuF,OAAM;4BAAab,OAAOsB,OAAOiF,KAAK;4BAAEzF,MAAK;;;;8BAEvD,KAAC3E;oBAAWmE,SAAQ;oBAAUC,OAAM;8BACjC,yEACC,sEACA,CAAC,YAAY,EAAExD,8BAA8B,qBAAqB,CAAC,GACnE,gEACA,uEACA,0DACCuE,CAAAA,OAAOkF,KAAK,GACT,CAAC,QAAQ,EAAE,IAAIC,KAAK,GAAGnF,OAAOkF,KAAK,CAAC,aAAa,CAAC,EAAEE,kBAAkB,CAACT,WAAW;wBAAEU,OAAO;wBAAQC,MAAM;wBAAWC,UAAU;oBAAM,GAAG,CAAC,CAAC,GACzI,GAAE;;;;;AAMpB;AACAR,sBAAsBjF,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/campaign-reach-sections.tsx"],"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'use client'\n\nimport { AppLink } from '@aglyn/shared-ui-jsx'\nimport {\n Figure,\n MoneyFigure,\n Section,\n} from '@aglyn/shared-ui-jsx/components/measured-figures.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { ScrollTable } from '@aglyn/shared-ui-jsx/components/scroll-table.component'\nimport {\n Alert,\n Button,\n Stack,\n TableBody,\n TableCell,\n TableHead,\n TableRow,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n getCountFromServer,\n getDoc,\n query,\n where,\n} from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { useFirestore } from '@aglyn/tenant-feature-instance'\nimport { type SendLinkRollup } from '@aglyn/shared-ui-email-campaigns/model/send-report'\nimport {\n campaignSequencesReport,\n type CampaignSequencesRollup,\n} from '../model/campaign-report'\nimport { EMAIL_ATTRIBUTION_WINDOW_DAYS } from '@aglyn/shared-util-email'\nimport {\n CAMPAIGN_CONVERSION_KINDS,\n CAMPAIGN_CONVERSION_KIND_COPY,\n type CampaignConversionKind,\n} from '../model/campaign-conversions'\nimport {\n campaignRevenueAcrossSends,\n type CampaignRevenueAcrossSends,\n type CampaignRevenueRollup,\n} from '../model/campaign-revenue'\nimport {\n campaignVisitsReport,\n type CampaignVisitRollup,\n} from '../model/campaign-visits'\nimport {\n campaignSendReportDoc,\n campaignSequenceReportDoc,\n campaignVisitReportDoc,\n} from './campaign-queries'\n\n/**\n * A CAMPAIGN BEYOND ITS MAIL — what it caused, what it earned, and where it\n * sent people.\n *\n * ## Attribution is the mechanism, and there is no other one\n *\n * A campaign owns no screen, no form and no overlay. Nothing in the stored\n * model connects `emailCampaigns/{id}` to a page a visitor lands on:\n * `HostExperiment` names a screen and never a campaign, `HostOverlay` names\n * neither, and a form document carries no campaign field. So a section\n * claiming a campaign CONTAINS a landing page would be inventing an edge, and\n * the containment would be a claim nothing in the data supports.\n *\n * What the data does support is EVIDENCE, of two kinds, and both are already\n * being written:\n *\n * - **Where it sent people.** `campaigns/{sendId}/reports/links` counts\n * clicks per destination URL, so the union across a campaign's emails is\n * the set of pages that campaign drove traffic to — observed rather than\n * declared, which is also why it stays true when a marketer re-points a\n * link.\n * - **What it caused there.** `campaignAttributions` records one row per\n * identify moment — a form submission, a lead, a contact, a booking —\n * carrying the SEND whose link the visitor followed.\n * - **What it earned there.** `campaigns/{sendId}/reports/revenue` buckets\n * the orders credited to that send by currency, so the merge across a\n * campaign's emails is what the campaign was credited with — per currency,\n * because the buckets have units and a total across them would not.\n *\n * All three sections below therefore hang off the campaign's own send ids,\n * which is the only handle any of those collections offers.\n *\n * ## What neither section can say, and says so instead\n *\n * A conversion credited to a WEB touch carries `utm_` labels and no send id.\n * A campaign container has no `utm_` label of its own — a marketer types\n * those into a URL — so there is no join to make, and no amount of matching\n * on the campaign's NAME would be one: two campaigns may share a name, and a\n * label is a string anybody who can vary a query string can mint. The\n * site-wide Conversions section is where the web channel is read, and the\n * copy below points at it rather than quietly leaving it out.\n *\n * A conversion with no touch at all is credited to nobody and is in neither\n * collection. The same holds for an order: one placed by somebody who never\n * clicked is credited to no campaign. That makes a page showing only credited\n * outcomes a partial account by construction, which is why the figures are\n * labelled \"credited to this campaign\" everywhere they appear.\n */\n\n/** Firestore's cap on the values in one `in` filter. */\nconst ID_CHUNK = 30\n\nexport interface CampaignReachProps {\n /**\n * The org whose sends the rollups sit under, `orgs/{orgId}/campaigns/{id}/\n * reports/*`; nothing is read until it is known.\n */\n orgId: string | null\n /**\n * The campaign's emails, by send id — the handle both collections join on.\n *\n * A stable array is not required: both sections key their reads on the\n * joined string, so a caller rebuilding the array every render pays for one\n * set of reads rather than one per render.\n */\n sendIds: readonly string[]\n /** The campaign holds more emails than `sendIds` names. */\n truncated: boolean\n}\n\n/** The ids as one primitive, so an effect depends on the VALUE not the array. */\nconst idsKey = (sendIds: readonly string[]): string => sendIds.join(',')\n\n/** `['a','b','c']` in runs of at most {@link ID_CHUNK}. */\nfunction chunked(ids: readonly string[]): string[][] {\n const out: string[][] = []\n for (let index = 0; index < ids.length; index += ID_CHUNK) {\n out.push(ids.slice(index, index + ID_CHUNK))\n }\n return out\n}\n\n/**\n * WHAT THE CAMPAIGN CAUSED, counted rather than listed.\n *\n * Four aggregation counts over `campaignAttributions`, one per kind, each\n * narrowed to this campaign's own sends. An aggregation is billed per\n * thousand index entries rather than per document, so the honest figure costs\n * about as much as a single row — which is what lets this run on mount\n * instead of behind a button. Listing the records would not: that is the\n * per-record read every figure on this page is arranged to avoid, and the\n * site-wide Conversions section already lists them.\n *\n * The composite index the query needs — `kind` then `campaignId` — is already\n * declared for the conversions list's own campaign-scoped view, and an `in`\n * runs as a disjunction of equalities against that same index.\n *\n * ## The kinds are never added together\n *\n * One form submission by a new person writes a submission, a contact AND a\n * lead: three true statements about one visit. A total would count that visit\n * three times and would look exactly like a bigger number, so there is no\n * total here and the note under the figures says why.\n */\nexport function CampaignConversionsSection(\n props: Omit<CampaignReachProps, 'orgId'> & {\n /**\n * The site whose conversions are counted. Conversions are a site's\n * visitors and are recorded under it, so on the org hub the caller picks\n * one.\n */\n hostId: string\n /**\n * The campaign CONTAINER's own id (AGL-3461). A conversion credited to a\n * page filed under the campaign, to a link labeled for it, or to one of\n * its sequences carries the container's id rather than a send's, so it\n * is counted beside the sends' — and a campaign that never sent an email\n * still has figures.\n */\n campaignId?: string\n /**\n * That site's marketing hub URL, for its conversions list; `null` hides\n * the link rather than pointing it nowhere.\n */\n basePath: string | null\n },\n) {\n const { hostId, sendIds, truncated, basePath, campaignId } = props\n const firestore = useFirestore()\n const key = idsKey(\n campaignId ? [campaignId, ...sendIds.filter((id) => id !== campaignId)] : sendIds,\n )\n const [counts, setCounts] = useState<Record<string, number> | null>(null)\n const [failed, setFailed] = useState(false)\n\n useEffect(() => {\n const ids = key ? key.split(',') : []\n setCounts(null)\n setFailed(false)\n if (!ids.length) return\n let active = true\n const attributions = collection(\n firestore,\n 'hosts',\n hostId,\n 'campaignAttributions',\n )\n /*\n * Summed ACROSS chunks, which is safe because a record carries exactly\n * one `campaignId`: the chunks partition the send ids, so no record can\n * be counted by two of them.\n */\n void Promise.all(\n CAMPAIGN_CONVERSION_KINDS.map(async (kind) => {\n const perChunk = await Promise.all(\n chunked(ids).map((chunk) =>\n getCountFromServer(\n query(\n attributions,\n where('kind', '==', kind),\n where('campaignId', 'in', chunk),\n ),\n ).then((snapshot) => Number(snapshot.data().count ?? 0)),\n ),\n )\n return [kind, perChunk.reduce((sum, value) => sum + value, 0)] as const\n }),\n )\n .then((entries) => {\n if (active) setCounts(Object.fromEntries(entries))\n })\n .catch(() => {\n /*\n * WITHHELD, never zeroed. A count that failed and a campaign that\n * caused nothing are opposite facts, and rendering the first as the\n * second is the most flattering wrong answer available here.\n */\n if (active) setFailed(true)\n })\n return () => {\n active = false\n }\n }, [firestore, hostId, key])\n\n return (\n <Section title=\"What it caused\">\n {!key ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No emails have gone out under this campaign, so nothing can be ' +\n 'credited to it yet.'}\n </Typography>\n ) : failed ? (\n <Alert severity=\"warning\">\n {'The conversions credited to this campaign could not be counted.'}\n </Alert>\n ) : !counts ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Counting what this campaign is credited with…'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Stack useFlexGap direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n {CAMPAIGN_CONVERSION_KINDS.map((kind: CampaignConversionKind) => (\n <Figure\n key={kind}\n label={CAMPAIGN_CONVERSION_KIND_COPY[kind].label}\n value={counts[kind] ?? 0}\n note={CAMPAIGN_CONVERSION_KIND_COPY[kind].note}\n />\n ))}\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'These count different things about the same visits and are ' +\n 'deliberately not added together — one person filling in one ' +\n 'form appears as a submission, a contact and a lead.'}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {(campaignId\n ? 'Credited to this campaign — a click on one of its emails or ' +\n 'sequences, a link carrying a utm_campaign label it declares, ' +\n 'or a page filed under it, whichever touched the visitor last. '\n : 'Credited to this email. ') +\n 'Somebody who arrived from a utm_ label no campaign declares is ' +\n 'credited to that label instead, and somebody who arrived ' +\n 'directly is credited to nobody — both are counted on the ' +\n 'site’s conversions list.'}\n </Typography>\n {truncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Over the emails listed below. This campaign has sent more ' +\n 'than the page holds, and their conversions are not in these ' +\n 'figures.'}\n </Typography>\n ) : null}\n </Stack>\n )}\n {basePath ? (\n <Stack direction=\"row\">\n <Button\n component={AppLink as any}\n {...({ componentVariant: 'naked', nativeButton: false } as any)}\n href={`${basePath}/conversions`}\n size=\"small\"\n color=\"primary\"\n >\n {'All conversions'}\n </Button>\n </Stack>\n ) : null}\n </Section>\n )\n}\nCampaignConversionsSection.displayName = 'CampaignConversionsSection'\n\n/**\n * The rule the amounts were credited under, in the sentence a reader can\n * check them against.\n *\n * Plural where the campaign is plural. A container can hold emails credited\n * under different models or windows, and printing one of them as though it\n * governed all of them would be the same lie as printing one currency symbol\n * over two currencies.\n */\nfunction creditedUnder(report: CampaignRevenueAcrossSends): string {\n const model = report.models.length === 1 ? report.models[0] : ''\n const rule =\n model === 'last-click'\n ? 'to the last campaign whose link the buyer clicked'\n : model\n ? `under the ${model} model`\n : 'under more than one attribution model'\n const window =\n report.windowDays.length === 1\n ? `within ${report.windowDays[0]} days of that click`\n : `within ${report.windowDays.join(' or ')} days of that click, ` +\n 'depending on the email'\n return `Credited ${rule}, ${window}.`\n}\n\n/**\n * WHAT THE CAMPAIGN EARNED — per currency, and never across them.\n *\n * The same question a campaign of one email answers, answered the same way by\n * a campaign of several: how many messages a container happens to hold is not\n * a fact about whether its revenue is knowable. So this is the same section\n * the single-send report carries — `Revenue`, in the same place in the page's\n * order, drawn by the same money components — over a merge rather than over\n * one document.\n *\n * ## Why it takes a merge, and what the merge may not do\n *\n * `reports/revenue` is written per SEND. There is no container-level rollup\n * and there should not be one: it would have to be kept true against every\n * order and every refund of every email in the campaign, duplicating figures\n * that are already correct one level down. So the campaign's figure is one\n * document per email and an addition — and the addition is the danger.\n *\n * **Currency is to money what kind is to a conversion.** The section above\n * refuses to total form submissions with leads because one visit writes both;\n * this refuses to total USD with EUR because the sum has no unit. Both\n * refusals are structural rather than remembered:\n * {@link campaignRevenueAcrossSends} keys its accumulator on the currency, so\n * amounts in different currencies never reach the same addition, and the\n * result carries no combined field for a screen to print.\n *\n * ## One currency reads as one figure; several read as several\n *\n * The common case is one currency, and it is drawn exactly as a single\n * email's report draws it — net, gross, refunded, orders — with no currency\n * heading, because a label saying `USD` over a page that only ever shows\n * dollars is noise. The moment a second currency appears every block gets its\n * code as a heading and its own email count, and a caveat says in words what\n * the headings say in layout: these do not add up, and nothing here converts\n * between them. The rare case pays for itself; the common one does not pay\n * for the rare one.\n *\n * ## Behind a button, and the button says the price\n *\n * One document per email — the per-record read the conversions section above\n * is shaped to avoid. That section can run on mount because an aggregation is\n * billed per thousand index entries, so its four honest figures cost about as\n * much as a single row however large the campaign is. This cannot: fifty\n * emails is fifty document reads, every time the page opens, for a section\n * most readers of a campaign are not opening the page for. So it is asked\n * for, at the same control and in the same words as the destinations section\n * below, which buys its rows the same way.\n *\n * ## Nothing, and nothing readable, are different sentences\n *\n * The rollup is created by the writer on the first order it credits, so an\n * email with no record has never earned. A campaign where NO email has one\n * has not been shown to have earned nothing — it is also every campaign sent\n * before the join existed and every campaign on a site with no store, which\n * is the distinction the single-send report draws in the same two sentences.\n * A read that is REFUSED shows neither: the figures are withheld behind a\n * warning, and any figures already on screen are dropped rather than left\n * standing beside it, because a stale total under a fresh error is the one\n * arrangement that looks authoritative and is not.\n */\nexport function CampaignRevenueSection(props: CampaignReachProps) {\n const { orgId, sendIds, truncated } = props\n const firestore = useFirestore()\n const key = idsKey(sendIds)\n const [busy, setBusy] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const [report, setReport] = useState<CampaignRevenueAcrossSends | null>(null)\n\n // A merge over one set of emails describes that set. Leaving it on screen\n // after the campaign's emails change labels it as something it is not.\n useEffect(() => {\n setReport(null)\n setError(null)\n }, [key])\n\n const load = useCallback(async () => {\n if (busy) return\n const ids = key ? key.split(',') : []\n if (!ids.length || !orgId) return\n setBusy(true)\n setError(null)\n try {\n const snapshots = await Promise.all(\n ids.map((id) =>\n getDoc(campaignSendReportDoc(firestore, orgId, id, 'revenue')),\n ),\n )\n /*\n * `data()` is `undefined` on a document that does not exist, and it is\n * handed on as `undefined` rather than as an empty rollup: the merge\n * counts the records that EXIST to tell a campaign that earned nothing\n * from one whose revenue was never recorded at all.\n */\n setReport(\n campaignRevenueAcrossSends(\n snapshots.map(\n (snapshot) => snapshot.data() as CampaignRevenueRollup | undefined,\n ),\n ),\n )\n } catch (caught) {\n console.error(caught)\n /*\n * WITHHELD, never zeroed and never left stale. A refused read and a\n * campaign that earned nothing are opposite facts, and the second is\n * the more flattering of the two.\n */\n setReport(null)\n setError('The revenue credited to this campaign could not be read')\n } finally {\n setBusy(false)\n }\n }, [busy, firestore, orgId, key])\n\n const count = key ? key.split(',').length : 0\n\n return (\n <Section title=\"Revenue\">\n {!count ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No emails have gone out under this campaign, so nothing can be ' +\n 'credited to it yet.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'What this campaign’s emails were credited with, read from each ' +\n 'email’s own revenue record and merged by currency.'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Button size=\"small\" onClick={() => void load()} disabled={busy}>\n {busy ? 'Reading…' : report ? 'Read again' : 'Show revenue'}\n </Button>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Reads one record per email — ${count.toLocaleString()} of them.`}\n </Typography>\n </Stack>\n {error ? <Alert severity=\"warning\">{error}</Alert> : null}\n {report ? (\n report.currencies.length ? (\n <Stack spacing={3}>\n {report.caveats.map((caveat) => (\n <Alert key={caveat.id} severity=\"info\">\n {caveat.message}\n </Alert>\n ))}\n {report.currencies.map((entry) => (\n <Stack key={entry.currency} spacing={1}>\n {/*\n * The currency is a HEADING when there is more than one\n * and absent when there is one — the single-send report's\n * rule, so the two shapes of campaign page read alike.\n */}\n {report.multiCurrency ? (\n <Typography variant=\"subtitle2\">\n {entry.currency.toUpperCase()}\n </Typography>\n ) : null}\n <Stack\n direction=\"row\"\n spacing={4}\n useFlexGap\n sx={{ flexWrap: 'wrap' }}\n >\n <MoneyFigure\n label=\"Net revenue\"\n cents={entry.netCents}\n currency={entry.currency}\n note=\"after refunds\"\n />\n <MoneyFigure\n label=\"Gross revenue\"\n cents={entry.grossCents}\n currency={entry.currency}\n note=\"as charged\"\n />\n <MoneyFigure\n label=\"Refunded\"\n cents={entry.refundedCents}\n currency={entry.currency}\n note=\"handed back\"\n />\n <Figure\n label=\"Orders\"\n value={entry.orders}\n note=\"credited to this campaign\"\n />\n <Figure\n label=\"Fully refunded\"\n value={entry.refundedOrders}\n note=\"of those orders\"\n />\n {/*\n * Only where it says something. With one currency this\n * repeats the coverage line under the figures; with\n * two it is what shows the blocks are disjoint parts of\n * the campaign rather than two views of all of it.\n */}\n {report.multiCurrency ? (\n <Figure\n label=\"Emails\"\n value={entry.emails}\n note={`earned in ${entry.currency.toUpperCase()}`}\n />\n ) : null}\n </Stack>\n </Stack>\n ))}\n {/*\n * NO PER-MESSAGE AVERAGE, and this is where a reader of the\n * single-send report would look for one. That page divides by\n * the send's own delivered count, read from the same document\n * at the same instant. A campaign has no such pair — its\n * revenue covers the emails with a revenue record and its\n * delivery total covers the emails that recorded a delivery\n * count, which are different subsets — so the quotient would\n * be an average over a population nobody named.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${report.attributedOrders.toLocaleString()} ` +\n `${report.attributedOrders === 1 ? 'order' : 'orders'} ` +\n `credited, across ${report.recorded.toLocaleString()} of ` +\n `this campaign’s ${report.read.toLocaleString()} ` +\n `${report.read === 1 ? 'email' : 'emails'}. The rest have ` +\n 'never been credited with a sale.'}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${creditedUnder(report)} Clicks only — an open is not ` +\n 'treated as evidence that anybody read the email. An ' +\n 'order placed by somebody who never clicked, or who ' +\n 'checked out without giving an address, is credited to no ' +\n 'campaign, so this is a floor rather than every sale this ' +\n 'campaign influenced.'}\n </Typography>\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {report.recorded\n ? 'No orders have been credited to this campaign.'\n : 'No revenue has been attributed to any of this ' +\n 'campaign’s emails. Orders are credited to the last ' +\n 'campaign whose link the buyer clicked, within ' +\n `${EMAIL_ATTRIBUTION_WINDOW_DAYS} days — emails sent ` +\n 'before that was recorded, or a site with no store, will ' +\n 'never show a figure here.'}\n </Typography>\n )\n ) : null}\n {/*\n OUTSIDE both branches, because it qualifies both. A campaign that\n reports nothing over the emails this page holds has not reported\n nothing about itself, and the emptier answer is the one that most\n needs its population named.\n */}\n {report && truncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Across the ${report.read.toLocaleString()} emails this page ` +\n 'holds. The campaign has sent more.'}\n </Typography>\n ) : null}\n </Stack>\n )}\n </Section>\n )\n}\nCampaignRevenueSection.displayName = 'CampaignRevenueSection'\n\n/** One destination, summed across the campaign's emails. */\ninterface DestinationRow {\n url: string\n clicks: number\n /** How many of the campaign's emails carried a link to it. */\n emails: number\n}\n\n/** What one pass over the campaign's link rollups produced. */\ninterface DestinationsResult {\n rows: DestinationRow[]\n /** Emails whose rollup was read, which is the population the rows describe. */\n read: number\n /** Clicks on destinations past each email's own rollup cap. */\n overflowClicks: number\n /** Clicks that arrived naming no destination at all. */\n unattributedClicks: number\n}\n\n/**\n * WHERE THE CAMPAIGN SENT PEOPLE — the pages its mail pointed at.\n *\n * The union of `campaigns/{sendId}/reports/links` across the campaign's\n * emails, which is the closest the stored data comes to \"the surfaces this\n * campaign runs across\". It is observed rather than declared: a page is on\n * this list because a link in this campaign's mail was followed to it.\n *\n * ## Behind a button, and the button says the price\n *\n * One document per email, up to the ceiling the page holds — which is the\n * per-record read the figures above are shaped to avoid, so it is asked for\n * rather than paid on mount. The same bargain the conversions list makes for\n * its landing-page grouping.\n *\n * ## What a row is, and what it is not\n *\n * A destination is the link's address with its query string dropped, because\n * a campaign body is merged per recipient and a personalised query would mint\n * one row per person — and could carry that person's address into an\n * aggregate the whole team reads. The cost is that two links to one page\n * distinguished only by their tracking parameters are one row, which the note\n * under the table states rather than leaving the reader to discover.\n *\n * Clicks are EVENTS. One reader clicking twice counts twice, so a destination\n * total is not a count of people.\n */\nexport function CampaignDestinationsSection(props: CampaignReachProps) {\n const { orgId, sendIds, truncated } = props\n const firestore = useFirestore()\n const key = idsKey(sendIds)\n const [busy, setBusy] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const [result, setResult] = useState<DestinationsResult | null>(null)\n /*\n * The page is a SLICE of a window this section already holds. One campaign\n * can reach fifty destinations per email over fifty emails, so the row\n * count is bounded by the rollups rather than small — and a table that\n * grows with the campaign gets a footer like every other one.\n */\n const [page, setPage] = useState(0)\n const [pageSize, setPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleRows = useMemo(\n () => (result?.rows ?? []).slice(page * pageSize, page * pageSize + pageSize),\n [result, page, pageSize],\n )\n\n // A grouping read for one set of emails describes that set. Leaving it on\n // screen after the campaign's emails change labels it as something it is not.\n useEffect(() => {\n setResult(null)\n setError(null)\n setPage(0)\n }, [key])\n\n const load = useCallback(async () => {\n if (busy) return\n const ids = key ? key.split(',') : []\n if (!ids.length || !orgId) return\n setBusy(true)\n setError(null)\n try {\n const snapshots = await Promise.all(\n ids.map((id) =>\n getDoc(campaignSendReportDoc(firestore, orgId, id, 'links')),\n ),\n )\n const byUrl = new Map<string, DestinationRow>()\n let overflowClicks = 0\n let unattributedClicks = 0\n snapshots.forEach((snapshot) => {\n const rollup = snapshot.data() as SendLinkRollup | undefined\n if (!rollup) return\n overflowClicks += Number(rollup.overflowClicks ?? 0)\n unattributedClicks += Number(rollup.unattributedClicks ?? 0)\n Object.values(rollup.links ?? {}).forEach((entry) => {\n const url = String(entry?.url ?? '').trim()\n if (!url) return\n const row = byUrl.get(url) ?? { url, clicks: 0, emails: 0 }\n row.clicks += Number(entry?.clicks ?? 0)\n // One rollup holds at most one entry per destination, so this\n // counts EMAILS that linked there rather than link occurrences.\n row.emails += 1\n byUrl.set(url, row)\n })\n })\n setPage(0)\n setResult({\n rows: [...byUrl.values()].sort(\n (a, b) => b.clicks - a.clicks || a.url.localeCompare(b.url),\n ),\n read: ids.length,\n overflowClicks,\n unattributedClicks,\n })\n } catch (caught) {\n console.error(caught)\n setError('The destinations could not be read')\n } finally {\n setBusy(false)\n }\n }, [busy, firestore, orgId, key])\n\n const count = key ? key.split(',').length : 0\n\n return (\n <Section title=\"Where it sent people\">\n {!count ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No emails have gone out under this campaign, so it has sent ' +\n 'nobody anywhere yet.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'The pages this campaign’s links were followed to. A campaign ' +\n 'does not own a page — this is where its mail actually sent ' +\n 'people, read from each email’s own click report.'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Button size=\"small\" onClick={() => void load()} disabled={busy}>\n {busy ? 'Reading…' : result ? 'Read again' : 'Show destinations'}\n </Button>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Reads one record per email — ${count.toLocaleString()} of them.`}\n </Typography>\n </Stack>\n {error ? <Alert severity=\"warning\">{error}</Alert> : null}\n {result ? (\n result.rows.length ? (\n <Stack spacing={0.5}>\n <ScrollTable size=\"small\">\n <TableHead>\n <TableRow>\n <TableCell>{'Destination'}</TableCell>\n <TableCell align=\"right\">{'Emails'}</TableCell>\n <TableCell align=\"right\">{'Clicks'}</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {visibleRows.map((row) => (\n <TableRow key={row.url}>\n <TableCell sx={{ wordBreak: 'break-all' }}>\n {row.url}\n </TableCell>\n <TableCell align=\"right\">\n {row.emails.toLocaleString()}\n </TableCell>\n <TableCell align=\"right\">\n {row.clicks.toLocaleString()}\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </ScrollTable>\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={visibleRows.length}\n count={result.rows.length}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'A destination is the address without its query string, ' +\n 'so two links to one page that differ only in their ' +\n 'tracking parameters are one row. Clicks are events — ' +\n 'one reader clicking twice counts twice.'}\n </Typography>\n {result.overflowClicks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${result.overflowClicks.toLocaleString()} further ` +\n 'clicks landed on destinations past the per-email cap ' +\n 'and are not in the table.'}\n </Typography>\n ) : null}\n {result.unattributedClicks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${result.unattributedClicks.toLocaleString()} clicks ` +\n 'arrived naming no destination, so they belong to no ' +\n 'row.'}\n </Typography>\n ) : null}\n {truncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Across the ${result.read.toLocaleString()} emails this ` +\n 'page holds. The campaign has sent more.'}\n </Typography>\n ) : null}\n </Stack>\n ) : (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'None of this campaign’s emails has recorded a followed ' +\n 'link yet.'}\n </Typography>\n )\n ) : null}\n </Stack>\n )}\n </Section>\n )\n}\nCampaignDestinationsSection.displayName = 'CampaignDestinationsSection'\n\n/**\n * WHAT THE CAMPAIGN'S SEQUENCES PRODUCED (AGL-3254).\n *\n * A sequence joins a campaign from its own document, and the Outreach\n * runtime credits what each enrollment produced to the campaign's one\n * sequences report — `campaignSequenceReports/{campaignId}` on the org,\n * server-only like the conversions rollup, and readable by org-wide members\n * alone: a site collaborator is told it could not be read. One keyed read, joined on the\n * CONTAINER's id rather than on send ids: a sequence's emails are not the\n * campaign's sends, so the join the three sections above make does not\n * exist for it, and the report is written under the campaign directly.\n *\n * Absent is not zero: a campaign no sequence was ever in has no document,\n * and says so in words rather than as five dashes.\n */\nexport function CampaignSequencesSection(props: {\n orgId: string | null\n campaignId: string\n}) {\n const { orgId, campaignId } = props\n const firestore = useFirestore()\n const [rollup, setRollup] = useState<CampaignSequencesRollup | undefined | null>(null)\n const [failed, setFailed] = useState(false)\n\n useEffect(() => {\n let active = true\n setRollup(null)\n setFailed(false)\n if (!orgId) return undefined\n getDoc(campaignSequenceReportDoc(firestore, orgId, campaignId))\n .then((snapshot) => {\n if (active) setRollup((snapshot.data() as CampaignSequencesRollup | undefined) ?? undefined)\n })\n .catch(() => {\n // Withheld, never zeroed — the conversions section's reason.\n if (active) setFailed(true)\n })\n return () => {\n active = false\n }\n }, [firestore, orgId, campaignId])\n\n const report = rollup === null ? null : campaignSequencesReport(rollup)\n\n return (\n <Section title=\"What its sequences produced\">\n {failed ? (\n <Alert severity=\"warning\">{'What this campaign’s sequences produced could not be read.'}</Alert>\n ) : !report ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Reading what this campaign’s sequences produced…'}\n </Typography>\n ) : !report.recorded ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No sequence has been in this campaign. Put one in it from the ' +\n 'sequence’s settings, and everyone enrolled from then on counts here.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Stack useFlexGap direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n {report.figures.map((figure) => (\n <Figure key={figure.outcome} label={figure.label} value={figure.value} note={figure.note} />\n ))}\n </Stack>\n {report.caveats.map((caveat) => (\n <Typography key={caveat.id} variant=\"caption\" color=\"text.secondary\">\n {caveat.message}\n </Typography>\n ))}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Credited to the campaigns a sequence was in when each person was ' +\n 'enrolled. A meeting counts when it was booked from a link in a ' +\n 'sequence email; a conversion when a lead in a sequence became a contact.'}\n </Typography>\n </Stack>\n )}\n </Section>\n )\n}\nCampaignSequencesSection.displayName = 'CampaignSequencesSection'\n\n/**\n * WHO IT REACHED ON THE SITE (AGL-3461) — first visits and views of the pages\n * filed under the campaign.\n *\n * One keyed read of `orgs/{orgId}/campaignVisitReports/{campaignId}`, which the\n * site collector's `campaignVisit` beacon writes: keyed by the campaign's own\n * id, so this costs one document whatever the traffic. Across every site the\n * campaign is placed on, because the visitors are the campaign's whichever of\n * them they read.\n *\n * Absent is not zero, for the sequences section's reason: a campaign whose\n * pages nobody has opened since counting began has no document, and says so.\n */\nexport function CampaignVisitsSection(props: {\n orgId: string | null\n campaignId: string\n}) {\n const { orgId, campaignId } = props\n const firestore = useFirestore()\n const [rollup, setRollup] = useState<CampaignVisitRollup | undefined | null>(null)\n const [failed, setFailed] = useState(false)\n\n useEffect(() => {\n let active = true\n setRollup(null)\n setFailed(false)\n if (!orgId) return undefined\n getDoc(campaignVisitReportDoc(firestore, orgId, campaignId))\n .then((snapshot) => {\n if (active) setRollup((snapshot.data() as CampaignVisitRollup | undefined) ?? undefined)\n })\n .catch(() => {\n // Withheld, never zeroed — the conversions section's reason.\n if (active) setFailed(true)\n })\n return () => {\n active = false\n }\n }, [firestore, orgId, campaignId])\n\n const report = rollup === null ? null : campaignVisitsReport(rollup)\n\n return (\n <Section title=\"Who it reached\">\n {failed ? (\n <Alert severity=\"warning\">{'The visits to this campaign could not be read.'}</Alert>\n ) : !report ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Reading the visits to this campaign…'}\n </Typography>\n ) : !report.recorded ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'No visits yet. File a page under this campaign — or give it the ' +\n 'utm_campaign labels its links carry — and visitors count here ' +\n 'from their next visit.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n <Stack useFlexGap direction=\"row\" spacing={3} sx={{ flexWrap: 'wrap' }}>\n <Figure\n label=\"First visits\"\n value={report.firstVisits}\n note={`visitors reaching it for the first time in ${EMAIL_ATTRIBUTION_WINDOW_DAYS} days`}\n />\n <Figure label=\"Page views\" value={report.views} note=\"views of the pages filed under it\" />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'A first visit is a visitor reaching this campaign — on a page filed ' +\n 'under it, or from a link labeled for it — who has not reached it ' +\n `in the last ${EMAIL_ATTRIBUTION_WINDOW_DAYS} days. It is counted ` +\n 'only where the visitor’s device may remember the visit, so ' +\n 'visitors who declined analytics storage are in the page views and ' +\n 'not here. Across every site the campaign is placed on' +\n (report.since\n ? `, since ${new Date(`${report.since}-01T00:00:00Z`).toLocaleDateString(undefined, { month: 'long', year: 'numeric', timeZone: 'UTC' })}.`\n : '.')}\n </Typography>\n </Stack>\n )}\n </Section>\n )\n}\nCampaignVisitsSection.displayName = 'CampaignVisitsSection'\n"],"names":["AppLink","Figure","MoneyFigure","Section","ListPagination","TABLE_PAGE_SIZE_DEFAULT","ScrollTable","Alert","Button","Stack","TableBody","TableCell","TableHead","TableRow","Typography","collection","getCountFromServer","getDoc","query","where","useCallback","useEffect","useMemo","useState","useFirestore","campaignSequencesReport","EMAIL_ATTRIBUTION_WINDOW_DAYS","CAMPAIGN_CONVERSION_KINDS","CAMPAIGN_CONVERSION_KIND_COPY","campaignRevenueAcrossSends","campaignVisitsReport","campaignSendReportDoc","campaignSequenceReportDoc","campaignVisitReportDoc","ID_CHUNK","idsKey","sendIds","join","chunked","ids","out","index","length","push","slice","CampaignConversionsSection","props","hostId","truncated","basePath","campaignId","firestore","key","filter","id","counts","setCounts","failed","setFailed","split","active","attributions","Promise","all","map","kind","perChunk","chunk","then","snapshot","Number","data","count","reduce","sum","value","entries","Object","fromEntries","catch","title","variant","color","severity","spacing","useFlexGap","direction","sx","flexWrap","label","note","component","componentVariant","nativeButton","href","size","displayName","creditedUnder","report","model","models","rule","window","windowDays","CampaignRevenueSection","orgId","busy","setBusy","error","setError","setReport","load","snapshots","caught","console","alignItems","onClick","disabled","toLocaleString","currencies","caveats","caveat","message","entry","multiCurrency","currency","toUpperCase","cents","netCents","grossCents","refundedCents","orders","refundedOrders","emails","attributedOrders","recorded","read","CampaignDestinationsSection","result","setResult","page","setPage","pageSize","setPageSize","visibleRows","rows","byUrl","Map","overflowClicks","unattributedClicks","forEach","rollup","values","links","url","String","trim","row","get","clicks","set","sort","a","b","localeCompare","align","wordBreak","rowCount","onPageChange","onPageSizeChange","CampaignSequencesSection","setRollup","undefined","figures","figure","outcome","CampaignVisitsSection","firstVisits","views","since","Date","toLocaleDateString","month","year","timeZone"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,OAAO,QAAQ,uBAAsB;AAC9C,SACEC,MAAM,EACNC,WAAW,EACXC,OAAO,QACF,6DAA4D;AACnE,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,WAAW,QAAQ,yDAAwD;AACpF,SACEC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,UAAU,QACL,gBAAe;AACtB,SACEC,UAAU,EACVC,kBAAkB,EAClBC,MAAM,EACNC,KAAK,EACLC,KAAK,QACA,qBAAoB;AAC3B,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAASC,YAAY,QAAQ,iCAAgC;AAE7D,SACEC,uBAAuB,QAElB,8BAA0B;AACjC,SAASC,6BAA6B,QAAQ,2BAA0B;AACxE,SACEC,yBAAyB,EACzBC,6BAA6B,QAExB,mCAA+B;AACtC,SACEC,0BAA0B,QAGrB,+BAA2B;AAClC,SACEC,oBAAoB,QAEf,8BAA0B;AACjC,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,sBAAsB,QACjB,wBAAoB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+CC,GAED,sDAAsD,GACtD,MAAMC,WAAW;AAoBjB,+EAA+E,GAC/E,MAAMC,SAAS,CAACC,UAAuCA,QAAQC,IAAI,CAAC;AAEpE,yDAAyD,GACzD,SAASC,QAAQC,GAAsB;IACrC,MAAMC,MAAkB,EAAE;IAC1B,IAAK,IAAIC,QAAQ,GAAGA,QAAQF,IAAIG,MAAM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,OAAM;4BAAad,OAAOuB,OAAOgF,KAAK;4BAAExF,MAAK;;;;8BAEvD,KAAC5E;oBAAWmE,SAAQ;oBAAUC,OAAM;8BACjC,yEACC,sEACA,CAAC,YAAY,EAAExD,8BAA8B,qBAAqB,CAAC,GACnE,gEACA,uEACA,0DACCwE,CAAAA,OAAOiF,KAAK,GACT,CAAC,QAAQ,EAAE,IAAIC,KAAK,GAAGlF,OAAOiF,KAAK,CAAC,aAAa,CAAC,EAAEE,kBAAkB,CAACT,WAAW;wBAAEU,OAAO;wBAAQC,MAAM;wBAAWC,UAAU;oBAAM,GAAG,CAAC,CAAC,GACzI,GAAE;;;;;AAMpB;AACAR,sBAAsBhF,WAAW,GAAG"}
@@ -32,6 +32,7 @@ import { ListRowActions, ListTable, listActionsColumn } from "@aglyn/shared-ui-j
32
32
  import { hiddenFilterVisibility } from "@aglyn/shared-ui-jsx/const/list-filter";
33
33
  import { listFilterGridColumns } from "@aglyn/shared-ui-jsx/const/list-grid-filter";
34
34
  import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filter";
35
+ import { useListColumnSort } from "@aglyn/shared-ui-jsx/hooks/use-list-column-sort";
35
36
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
36
37
  import { Alert, Button, Chip, Stack, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material";
37
38
  import { collection, limit, query, setDoc, where } from "firebase/firestore";
@@ -57,6 +58,21 @@ import { useCampaignTopicOptions } from "./use-campaign-topic-options.js";
57
58
  /** Firestore's cap on an `in` clause's values. */ const IN_LIMIT = 30;
58
59
  const formatDay = (ms)=>ms === null ? '' : new Date(ms).toLocaleDateString();
59
60
  /** A rolled-up figure, or an em dash where nothing recorded one. */ const figure = (value)=>value.value === null ? '—' : value.value.toLocaleString();
61
+ /*
62
+ * EVERY HEADER SORTS (AGL-3680). A campaign's name and a single send's
63
+ * subject order the kind's query (`declaration.sorts`); what a row is drawn
64
+ * from — its sites, its window, its lists, and its figures (a campaign's
65
+ * summed from its emails for the page, a send's counters absent until
66
+ * something is counted) — sorts the page.
67
+ */ const CAMPAIGN_PAGE_SORT_HEADERS = {
68
+ sitesLabel: 'Sites',
69
+ windowState: 'Window',
70
+ listIds: 'Lists',
71
+ emails: 'Emails',
72
+ sent: 'Mail sent',
73
+ opens: 'Mail opens',
74
+ clicks: 'Mail clicks'
75
+ };
60
76
  const WINDOW_LABEL = {
61
77
  undated: 'No dates',
62
78
  upcoming: 'Upcoming',
@@ -146,6 +162,8 @@ const NO_CLAUSES = {
146
162
  * is asked by scope token, a send by the site it was sent as); the search
147
163
  * words are the reader's and carry across.
148
164
  *=========================================*/ const [kind, setKind] = useState('campaign');
165
+ // The header order asked of the kind on screen; a new kind starts unsorted.
166
+ const [askedSort, setAskedSort] = useState(null);
149
167
  const [clausesByKind, setClausesByKind] = useState(NO_CLAUSES);
150
168
  const [searchWords, setSearchWords] = useState([]);
151
169
  const setKindClauses = useCallback((next)=>setClausesByKind((current)=>_extends({}, current, {
@@ -184,7 +202,8 @@ const NO_CLAUSES = {
184
202
  ...gridFilter.clauses
185
203
  ] : gridFilter.clauses : [],
186
204
  search: hostId ? [] : gridFilter.searchWords,
187
- base: campaignContainersScope(hostId)
205
+ base: campaignContainersScope(hostId),
206
+ sort: kind === 'campaign' ? askedSort : null
188
207
  },
189
208
  deps: [
190
209
  firestore,
@@ -203,7 +222,8 @@ const NO_CLAUSES = {
203
222
  base: [
204
223
  SINGLE_SENDS_BASE,
205
224
  ...campaignSendsScope(hostId)
206
- ]
225
+ ],
226
+ sort: kind === 'single' ? askedSort : null
207
227
  },
208
228
  deps: [
209
229
  firestore,
@@ -335,6 +355,32 @@ const NO_CLAUSES = {
335
355
  restSends.rows,
336
356
  orgMount
337
357
  ]);
358
+ const pageSorts = useMemo(()=>({
359
+ sitesLabel: (row)=>row.sitesLabel || null,
360
+ windowState: (row)=>{
361
+ var _ref, _row_startAtMs;
362
+ return (_ref = (_row_startAtMs = row.startAtMs) != null ? _row_startAtMs : row.endAtMs) != null ? _ref : null;
363
+ },
364
+ listIds: (row)=>row.listIds.map((id)=>{
365
+ var _listNames_get;
366
+ return (_listNames_get = listNames.get(id)) != null ? _listNames_get : id;
367
+ }).join(', ') || null,
368
+ emails: (row)=>row.rollup.sends,
369
+ sent: (row)=>row.rollup.sent.value,
370
+ opens: (row)=>row.rollup.opens.value,
371
+ clicks: (row)=>row.rollup.clicks.value
372
+ }), [
373
+ listNames
374
+ ]);
375
+ const columnSort = useListColumnSort({
376
+ sorts: declaration.sorts,
377
+ sort: askedSort,
378
+ onSortChange: setAskedSort,
379
+ orderBy: page.plan.orderBy,
380
+ rows,
381
+ pageSorts,
382
+ headers: CAMPAIGN_PAGE_SORT_HEADERS
383
+ });
338
384
  /*
339
385
  * The choices the picked fields offer. A campaign's Sites are asked by
340
386
  * scope token — `org` is placed on every site — and a single send's by
@@ -827,7 +873,10 @@ const NO_CLAUSES = {
827
873
  size: "small",
828
874
  value: kind,
829
875
  onChange: (_event, next)=>{
830
- if (next) setKind(next);
876
+ if (next) {
877
+ setKind(next);
878
+ setAskedSort(null);
879
+ }
831
880
  },
832
881
  "aria-label": "Which rows the table lists",
833
882
  sx: {
@@ -857,25 +906,30 @@ const NO_CLAUSES = {
857
906
  headers: filterHeaders,
858
907
  options: filterOptions
859
908
  }),
860
- notices: siteSearch ? [
861
- CAMPAIGN_SITE_SEARCH_NOTICE,
862
- ...page.plan.notices
863
- ] : page.plan.notices
909
+ notices: [
910
+ ...siteSearch ? [
911
+ CAMPAIGN_SITE_SEARCH_NOTICE
912
+ ] : [],
913
+ ...page.plan.notices,
914
+ ...columnSort.notices
915
+ ]
864
916
  }),
865
917
  /*#__PURE__*/ _jsx(ListTable, {
866
- rows: rows,
918
+ rows: columnSort.rows,
867
919
  columns: listFilterGridColumns(columns, declaration.fields, filterOptions, filterHeaders),
868
920
  onOpen: (id)=>openCampaign(id),
869
921
  loading: page.status === 'loading',
870
922
  /*
871
923
  * The panel and the search are the grid's; every clause and the
872
924
  * search word are on the list's query (AGL-3321), and the grid
873
- * neither filters nor sorts the page it is handed.
925
+ * neither filters nor sorts the page it is handed: a stored
926
+ * column's header orders the query, a drawn one the page
927
+ * (AGL-3680).
874
928
  */ filterMode: "server",
875
929
  filterModel: gridFilter.filterModel,
876
930
  onFilterModelChange: gridFilter.onFilterModelChange,
877
931
  quickFilter: true,
878
- disableColumnSorting: true,
932
+ columnSort: columnSort,
879
933
  hideFooter: true,
880
934
  initialState: {
881
935
  columns: {