@aglyn/plugins-marketing 1.0.0-beta.232 → 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.
- package/package.json +16 -16
- package/src/lib/components/campaign-conversions-card.js +58 -15
- package/src/lib/components/campaign-conversions-card.js.map +1 -1
- package/src/lib/components/campaign-detail-card.js +50 -5
- package/src/lib/components/campaign-detail-card.js.map +1 -1
- package/src/lib/components/campaign-members-section.js +36 -8
- package/src/lib/components/campaign-members-section.js.map +1 -1
- package/src/lib/components/campaigns-card.js +64 -10
- package/src/lib/components/campaigns-card.js.map +1 -1
- package/src/lib/components/email-recipients-card.js +37 -2
- package/src/lib/components/email-recipients-card.js.map +1 -1
- package/src/lib/components/emails-list-card.js +59 -6
- package/src/lib/components/emails-list-card.js.map +1 -1
- package/src/lib/components/host-experiments-card.component.js +32 -6
- package/src/lib/components/host-experiments-card.component.js.map +1 -1
- package/src/lib/components/staff-org-email-card.component.js +82 -6
- package/src/lib/components/staff-org-email-card.component.js.map +1 -1
- package/src/lib/model/campaign-conversions.d.ts +2 -0
- package/src/lib/model/campaign-conversions.js +32 -0
- package/src/lib/model/campaign-conversions.js.map +1 -1
- package/src/lib/model/campaign-list-query.d.ts +6 -2
- package/src/lib/model/campaign-list-query.js +64 -9
- package/src/lib/model/campaign-list-query.js.map +1 -1
- package/src/lib/model/campaign-members-query.d.ts +2 -1
- package/src/lib/model/campaign-members-query.js +23 -1
- package/src/lib/model/campaign-members-query.js.map +1 -1
- package/src/lib/model/experiment-list-query.js +30 -2
- package/src/lib/model/experiment-list-query.js.map +1 -1
- package/src/lib/model/native-vocabulary.d.ts +26 -0
- package/src/lib/model/native-vocabulary.js +31 -0
- package/src/lib/model/native-vocabulary.js.map +1 -0
- package/src/lib/server/campaign-manage.d.ts +1 -1
- package/src/lib/server/campaign-manage.js +1 -0
- package/src/lib/server/campaign-manage.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-marketing",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.233",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-enums": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-ui-jsx-forms": "1.0.0-beta.
|
|
34
|
-
"@aglyn/shared-ui-next": "1.0.0-beta.
|
|
35
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
36
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
37
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
38
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
39
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
40
|
-
"@aglyn/tenant-data-admin": "1.0.0-beta.
|
|
41
|
-
"@aglyn/tenant-feature-instance": "1.0.0-beta.
|
|
42
|
-
"@aglyn/tenant-runtime": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.233",
|
|
29
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.233",
|
|
30
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.233",
|
|
31
|
+
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.233",
|
|
32
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.233",
|
|
33
|
+
"@aglyn/shared-ui-jsx-forms": "1.0.0-beta.233",
|
|
34
|
+
"@aglyn/shared-ui-next": "1.0.0-beta.233",
|
|
35
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.233",
|
|
36
|
+
"@aglyn/shared-util-email": "1.0.0-beta.233",
|
|
37
|
+
"@aglyn/shared-util-http": "1.0.0-beta.233",
|
|
38
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.233",
|
|
39
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.233",
|
|
40
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.233",
|
|
41
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.233",
|
|
42
|
+
"@aglyn/tenant-runtime": "1.0.0-beta.233",
|
|
43
43
|
"@swc/helpers": "0.5.23"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
@@ -25,7 +25,9 @@ import { ListRowActions, ListTable, listActionsColumn } from "@aglyn/shared-ui-j
|
|
|
25
25
|
import { ListPagination } from "@aglyn/shared-ui-jsx/components/list-pagination.component";
|
|
26
26
|
import { Figure, Section } from "@aglyn/shared-ui-jsx/components/measured-figures.component";
|
|
27
27
|
import { Alert, Button, Chip, Divider, Stack, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material";
|
|
28
|
-
import { collection, getCountFromServer, getDocs, query, where } from "firebase/firestore";
|
|
28
|
+
import { collection, getCountFromServer, getDocs, limit, orderBy, query, where } from "firebase/firestore";
|
|
29
|
+
import ListQueryNotices from "@aglyn/shared-ui-jsx/components/list-query-notices.component";
|
|
30
|
+
import { useListColumnSort } from "@aglyn/shared-ui-jsx/hooks/use-list-column-sort";
|
|
29
31
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
30
32
|
import { useRouter } from "next/navigation";
|
|
31
33
|
import { useFirestore, useOrgDataScope, usePagedCollection } from "@aglyn/tenant-feature-instance";
|
|
@@ -34,7 +36,7 @@ import { useFirestore, useOrgDataScope, usePagedCollection } from "@aglyn/tenant
|
|
|
34
36
|
* `@aglyn/tenant-feature-instance` wholesale to stage its Firestore hooks
|
|
35
37
|
* would otherwise lose them, and neither is a hook.
|
|
36
38
|
*/ import { ceilingedWindow, collectionCeiling, collectionPage } from "@aglyn/tenant-feature-instance/hooks/host-collection-queries";
|
|
37
|
-
import { CAMPAIGN_CONVERSION_KINDS, CAMPAIGN_CONVERSION_KIND_COPY, CAMPAIGN_CONVERSION_RECORD_KINDS, campaignConversionsCoverage, campaignTouchLabel } from "../model/campaign-conversions.js";
|
|
39
|
+
import { CAMPAIGN_CONVERSION_KINDS, CAMPAIGN_CONVERSION_KIND_COPY, CAMPAIGN_CONVERSION_SORTS, CAMPAIGN_CONVERSION_RECORD_KINDS, campaignConversionsCoverage, campaignTouchLabel } from "../model/campaign-conversions.js";
|
|
38
40
|
import { MarketingInsightsZone } from "./marketing-insight-zones.js";
|
|
39
41
|
/**
|
|
40
42
|
* WHAT THE CAMPAIGNS CAUSED, from the conversions' end.
|
|
@@ -86,6 +88,12 @@ const conversionsDocsHelp = pluginDocsHelp('emailCampaigns', {
|
|
|
86
88
|
anchor: '#the-campaign-report',
|
|
87
89
|
excerpt: 'A conversion is credited to the last campaign whose link the visitor ' + 'followed. The four kinds count different things about the same visits ' + 'and are never added together.'
|
|
88
90
|
});
|
|
91
|
+
/** Credited to is a label drawn from several fields: it sorts the page (AGL-3680). */ const CONVERSION_PAGE_SORTS = {
|
|
92
|
+
campaign: (row)=>campaignTouchLabel(row) || null
|
|
93
|
+
};
|
|
94
|
+
const CONVERSION_PAGE_SORT_HEADERS = {
|
|
95
|
+
campaign: 'Credited to'
|
|
96
|
+
};
|
|
89
97
|
const day = (ms)=>{
|
|
90
98
|
const value = Number(ms != null ? ms : 0);
|
|
91
99
|
return Number.isFinite(value) && value > 0 ? new Date(value).toLocaleString() : '—';
|
|
@@ -117,22 +125,49 @@ export function CampaignConversionsCard(props) {
|
|
|
117
125
|
* campaign. It is never applied to the web list: a `utm_` label is not a
|
|
118
126
|
* campaign id and a query pretending otherwise would return nothing while
|
|
119
127
|
* reading as "this campaign caused no web conversions".
|
|
120
|
-
*=========================================*/ const
|
|
128
|
+
*=========================================*/ const [emailSortAsked, setEmailSortAsked] = useState(null);
|
|
129
|
+
const [webSortAsked, setWebSortAsked] = useState(null);
|
|
130
|
+
/*
|
|
131
|
+
* A header order asked of a list replaces the document-name walk with an
|
|
132
|
+
* `orderBy` on that field (AGL-3680, `CAMPAIGN_CONVERSION_SORTS`): both
|
|
133
|
+
* fields are on every attribution, so the ordered walk is as total.
|
|
134
|
+
*/ const orderedPage = (base, sort, pageLimit)=>sort ? query(base, orderBy(sort.path, sort.direction), limit(pageLimit)) : collectionPage(base, pageLimit);
|
|
135
|
+
const emailList = usePagedCollection((pageLimit)=>orderedPage(campaignId ? query(attributions(), where('kind', '==', kind), where('campaignId', '==', campaignId)) : query(attributions(), where('kind', '==', kind), where('channel', '==', 'email')), emailSortAsked, pageLimit), [
|
|
121
136
|
firestore,
|
|
122
137
|
hostId,
|
|
123
138
|
kind,
|
|
124
|
-
campaignId
|
|
139
|
+
campaignId,
|
|
140
|
+
emailSortAsked == null ? void 0 : emailSortAsked.path,
|
|
141
|
+
emailSortAsked == null ? void 0 : emailSortAsked.direction
|
|
125
142
|
], {
|
|
126
143
|
idField: '$id'
|
|
127
144
|
});
|
|
128
|
-
const webList = usePagedCollection((pageLimit)=>campaignId ? null :
|
|
145
|
+
const webList = usePagedCollection((pageLimit)=>campaignId ? null : orderedPage(query(attributions(), where('kind', '==', kind), where('channel', '==', 'web')), webSortAsked, pageLimit), [
|
|
129
146
|
firestore,
|
|
130
147
|
hostId,
|
|
131
148
|
kind,
|
|
132
|
-
campaignId
|
|
149
|
+
campaignId,
|
|
150
|
+
webSortAsked == null ? void 0 : webSortAsked.path,
|
|
151
|
+
webSortAsked == null ? void 0 : webSortAsked.direction
|
|
133
152
|
], {
|
|
134
153
|
idField: '$id'
|
|
135
154
|
});
|
|
155
|
+
const emailSort = useListColumnSort({
|
|
156
|
+
sorts: CAMPAIGN_CONVERSION_SORTS,
|
|
157
|
+
sort: emailSortAsked,
|
|
158
|
+
onSortChange: setEmailSortAsked,
|
|
159
|
+
rows: emailList.rows,
|
|
160
|
+
pageSorts: CONVERSION_PAGE_SORTS,
|
|
161
|
+
headers: CONVERSION_PAGE_SORT_HEADERS
|
|
162
|
+
});
|
|
163
|
+
const webSort = useListColumnSort({
|
|
164
|
+
sorts: CAMPAIGN_CONVERSION_SORTS,
|
|
165
|
+
sort: webSortAsked,
|
|
166
|
+
onSortChange: setWebSortAsked,
|
|
167
|
+
rows: webList.rows,
|
|
168
|
+
pageSorts: CONVERSION_PAGE_SORTS,
|
|
169
|
+
headers: CONVERSION_PAGE_SORT_HEADERS
|
|
170
|
+
});
|
|
136
171
|
/*==========================================
|
|
137
172
|
* THE UNCREDITED HALF.
|
|
138
173
|
*
|
|
@@ -526,13 +561,17 @@ export function CampaignConversionsCard(props) {
|
|
|
526
561
|
/*#__PURE__*/ _jsxs(Section, {
|
|
527
562
|
title: "From campaign emails",
|
|
528
563
|
children: [
|
|
564
|
+
/*#__PURE__*/ _jsx(ListQueryNotices, {
|
|
565
|
+
refused: [],
|
|
566
|
+
notices: emailSort.notices
|
|
567
|
+
}),
|
|
529
568
|
/*#__PURE__*/ _jsx(ListTable, {
|
|
530
|
-
rows:
|
|
569
|
+
rows: emailSort.rows,
|
|
531
570
|
columns: columns,
|
|
532
571
|
hideFooter: true,
|
|
533
|
-
//
|
|
534
|
-
//
|
|
535
|
-
|
|
572
|
+
// Converted and Record order the query; Credited to sorts the
|
|
573
|
+
// page and says so (AGL-3680).
|
|
574
|
+
columnSort: emailSort,
|
|
536
575
|
onOpen: (_id, row)=>{
|
|
537
576
|
const href = campaignHref(row);
|
|
538
577
|
if (href) router.push(href);
|
|
@@ -551,7 +590,7 @@ export function CampaignConversionsCard(props) {
|
|
|
551
590
|
/*#__PURE__*/ _jsx(Typography, {
|
|
552
591
|
variant: "caption",
|
|
553
592
|
color: "text.secondary",
|
|
554
|
-
children: 'Listed in the order they are stored, which is not the order ' + 'they happened in — every row is reachable by paging, but the ' + 'first page is not the most recent conversions.'
|
|
593
|
+
children: 'Listed in the order they are stored, which is not the order ' + 'they happened in — every row is reachable by paging, but the ' + 'first page is not the most recent conversions. Sort by ' + 'Converted for those.'
|
|
555
594
|
})
|
|
556
595
|
]
|
|
557
596
|
}),
|
|
@@ -563,13 +602,17 @@ export function CampaignConversionsCard(props) {
|
|
|
563
602
|
color: "text.secondary",
|
|
564
603
|
children: 'Credited to the utm_ label on the link the visitor followed. ' + 'These are listed one by one rather than grouped: the label ' + 'is free text with no campaign behind it, so there is ' + 'nothing to open and no fixed set to total.'
|
|
565
604
|
}),
|
|
605
|
+
/*#__PURE__*/ _jsx(ListQueryNotices, {
|
|
606
|
+
refused: [],
|
|
607
|
+
notices: webSort.notices
|
|
608
|
+
}),
|
|
566
609
|
/*#__PURE__*/ _jsx(ListTable, {
|
|
567
|
-
rows:
|
|
610
|
+
rows: webSort.rows,
|
|
568
611
|
columns: columns,
|
|
569
612
|
hideFooter: true,
|
|
570
|
-
//
|
|
571
|
-
//
|
|
572
|
-
|
|
613
|
+
// Converted and Record order the query; Credited to sorts the
|
|
614
|
+
// page and says so (AGL-3680).
|
|
615
|
+
columnSort: webSort,
|
|
573
616
|
noRowsLabel: "Nothing credited to a tagged link",
|
|
574
617
|
noRowsDescription: 'A conversion lands here when the visitor arrived on a URL ' + 'carrying utm_ parameters.'
|
|
575
618
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/campaign-conversions-card.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 { pluginDocsHelp } from '@aglyn/aglyn'\nimport { pluginRecordCountSource } from '@aglyn/aglyn/plugin-manager/plugin-record-counts'\nimport {\n PLUGIN_RECORD_LIST_IDS_MAX,\n pluginRecordListByIdsQuery,\n pluginRecordsFromRows,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { mdiEyeOutline, mdiMapMarkerOutline } from '@aglyn/shared-data-mdi'\nimport { AppLink, CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport {\n ListRowActions,\n ListTable,\n listActionsColumn,\n} from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { Figure, Section } from '@aglyn/shared-ui-jsx/components/measured-figures.component'\nimport {\n Alert,\n Button,\n Chip,\n Divider,\n Stack,\n ToggleButton,\n ToggleButtonGroup,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n getCountFromServer,\n getDocs,\n query,\n where,\n} from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { useRouter } from 'next/navigation'\nimport {\n useFirestore,\n useOrgDataScope,\n usePagedCollection,\n} from '@aglyn/tenant-feature-instance'\n/*\n * The MODULE, not the barrel, for the pure query helpers — a spec that mocks\n * `@aglyn/tenant-feature-instance` wholesale to stage its Firestore hooks\n * would otherwise lose them, and neither is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n collectionPage,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n CAMPAIGN_CONVERSION_KINDS,\n CAMPAIGN_CONVERSION_KIND_COPY,\n CAMPAIGN_CONVERSION_RECORD_KINDS,\n campaignConversionsCoverage,\n campaignTouchLabel,\n type CampaignConversionKind,\n type CampaignConversionRecord,\n} from '../model/campaign-conversions'\nimport { MarketingInsightsZone } from './marketing-insight-zones'\n\n/**\n * WHAT THE CAMPAIGNS CAUSED, from the conversions' end.\n *\n * A campaign's own report says what that campaign caused. This is the list\n * the report cannot be: every credited conversion on the site, the ones\n * credited to a tagged web link rather than to a campaign document, and — the\n * half a report of successes can never show — how many were credited to\n * nothing at all.\n *\n * ## ONE KIND AT A TIME, and that is the whole design\n *\n * A form submission by a new person writes a submission record, a contact and\n * a lead. Three true statements about one visit, and a screen that showed\n * them together would invite the reader to add them and treble every figure.\n * So the kind is a MODE rather than a column: the query carries\n * `where('kind','==', …)`, only one kind's rows are ever on screen, and there\n * is no view in which two kinds could be totalled because there is no view in\n * which two kinds are both present.\n *\n * ## THE TWO CHANNELS ARE TWO LISTS, and never one\n *\n * An email touch names a campaign document — a real entity with a report to\n * open. A web touch names `utm_` text a marketer typed into a URL: no\n * document, no id, no bound on how many distinct values exist. Merging them\n * would put a linkable record and an unlinkable label in one column and imply\n * they are the same kind of thing, and grouping the web side into a rollup\n * would build a map anybody who can vary a query string can grow. So there\n * are two tables, the web one is read as records, and neither is summed into\n * the other.\n *\n * ## The read cost\n *\n * Two paged listeners bounded by the page size, and two aggregation counts.\n * Nothing scans a collection, no row triggers a read of its own, and the\n * landing-page join — the only expensive thing here — is behind a button and\n * says what it will cost before it runs.\n */\n\n/**\n * How many attribution records the landing-page join reads.\n *\n * A CEILING rather than a page size: grouping is over a window and a window\n * sliced ten at a time cannot be grouped at all. Kept low because this is the\n * one read on the surface that is measured in hundreds — see the button that\n * asks for it.\n */\nconst LANDING_PAGE_CEILING = 100\n\n/** The most submissions one by-name read asks for — Firestore's `in` cap. */\nconst ID_CHUNK = PLUGIN_RECORD_LIST_IDS_MAX\n\n/** A credited form conversion's `refId` names a submission of this kind. */\nconst SUBMISSION_RECORD_KIND = CAMPAIGN_CONVERSION_RECORD_KINDS.form\n\nconst conversionsDocsHelp = pluginDocsHelp('emailCampaigns', {\n anchor: '#the-campaign-report',\n excerpt:\n 'A conversion is credited to the last campaign whose link the visitor ' +\n 'followed. The four kinds count different things about the same visits ' +\n 'and are never added together.',\n})\n\n/** The stored record plus the document name the reader listed it under. */\ntype ConversionRow = CampaignConversionRecord & { $id: string }\n\nconst day = (ms: unknown): string => {\n const value = Number(ms ?? 0)\n return Number.isFinite(value) && value > 0\n ? new Date(value).toLocaleString()\n : '—'\n}\n\nexport interface CampaignConversionsCardProps {\n hostId: string\n /** The marketing hub URL, for the link to each credited campaign. */\n basePath: string\n /**\n * One campaign's conversions rather than the whole site's.\n *\n * Set from `/marketing/conversions/{campaignId}`. It narrows the EMAIL list\n * only: a web-channel record carries no campaign id, so there is nothing\n * for it to be narrowed by — and the uncredited figure is withheld\n * entirely, because a conversion credited to nobody belongs to no campaign\n * and attributing the site's whole direct traffic to whichever campaign the\n * reader happens to be looking at is the exact inference this join refuses\n * to make.\n */\n campaignId?: string\n}\n\nexport function CampaignConversionsCard(props: CampaignConversionsCardProps) {\n const { hostId, basePath, campaignId } = props\n const firestore = useFirestore()\n const router = useRouter()\n const { scope: dataScope } = useOrgDataScope({ hostId })\n const [kind, setKind] = useState<CampaignConversionKind>('form')\n\n const attributions = useCallback(\n () => collection(firestore, 'hosts', hostId, 'campaignAttributions'),\n [firestore, hostId],\n )\n\n /*==========================================\n * THE TWO LISTS.\n *\n * Both walk the collection in DOCUMENT-NAME order through `collectionPage`,\n * which is the console's one ordering decision: `orderBy` on a field\n * matches only documents that HAVE it, so ordering on a date would hide\n * rows rather than merely mis-order them, and an unordered `limit()` is a\n * pseudo-random sample whose gaps leave nothing to notice. The walk is\n * total — every row is reachable by paging — and it is deliberately NOT\n * newest-first, which the note under each table says out loud.\n *\n * `campaignId` narrows the email list when the reader arrived from one\n * campaign. It is never applied to the web list: a `utm_` label is not a\n * campaign id and a query pretending otherwise would return nothing while\n * reading as \"this campaign caused no web conversions\".\n *=========================================*/\n const emailList = usePagedCollection<ConversionRow>(\n (pageLimit) =>\n collectionPage(\n campaignId\n ? query(\n attributions(),\n where('kind', '==', kind),\n where('campaignId', '==', campaignId),\n )\n : query(\n attributions(),\n where('kind', '==', kind),\n where('channel', '==', 'email'),\n ),\n pageLimit,\n ),\n [firestore, hostId, kind, campaignId],\n { idField: '$id' },\n )\n\n const webList = usePagedCollection<ConversionRow>(\n (pageLimit) =>\n campaignId\n ? null\n : collectionPage(\n query(\n attributions(),\n where('kind', '==', kind),\n where('channel', '==', 'web'),\n ),\n pageLimit,\n ),\n [firestore, hostId, kind, campaignId],\n { idField: '$id' },\n )\n\n /*==========================================\n * THE UNCREDITED HALF.\n *\n * Two aggregation counts, and they are on the page by DEFAULT rather than\n * behind a button, because the tables above them are a list of the\n * successes: showing only those renders \"we credited nine of these\" as\n * \"nine of these happened\", which is the conclusion this surface exists to\n * stop a reader drawing. An aggregation is billed per thousand index\n * entries rather than per document, so the honest figure costs about as\n * much as one row.\n *\n * Withheld entirely when either count fails. Defaulting the total to the\n * attributed figure would render every conversion as attributed, which is\n * the most flattering wrong answer available here.\n *=========================================*/\n /*\n * THE TOTAL IS COUNTED BY THE PLUGIN THAT KEEPS THE RECORDS\n * (`plugin-record-counts`, AGL-3080): the forms plugin's submissions, the\n * bookings plugin's bookings, the record system's leads and contacts. The\n * owner says which of its records this site produced — its own\n * submissions and bookings, the leads it CAPTURED (AGL-3275; not the ones\n * a consent group merely shares with it), and for contacts, which the\n * organization holds once for every site, all of them, which the owner\n * marks as a count that crosses sites. With no owner in this console the\n * total is withheld exactly as a failed count is.\n *\n * The source is resolved per kind and the query built inside the effect,\n * from primitives: a query object rebuilt on every render as a dependency\n * would reopen the effect, and pay for two aggregation counts, on every\n * render rather than per kind.\n */\n const orgId = dataScope ? dataScope[1] : null\n const countSource = useMemo(\n () => pluginRecordCountSource(CAMPAIGN_CONVERSION_RECORD_KINDS[kind]),\n [kind],\n )\n\n /** The kind's records live outside this host, so the total over-counts. */\n const totalCrossesHosts = countSource?.crossesSites === true\n\n const [attributedCount, setAttributedCount] = useState<number | null>(null)\n const [totalCount, setTotalCount] = useState<number | null>(null)\n\n useEffect(() => {\n // A campaign-scoped view has no uncredited figure to compute — see the\n // prop's docblock — so it does not pay for one either.\n const totalQuery = campaignId\n ? null\n : (countSource?.query(firestore, { hostId, orgId }) ?? null)\n if (!totalQuery) {\n setAttributedCount(null)\n setTotalCount(null)\n return\n }\n let active = true\n setAttributedCount(null)\n setTotalCount(null)\n void getCountFromServer(query(attributions(), where('kind', '==', kind)))\n .then((snapshot) => {\n if (active) setAttributedCount(snapshot.data().count)\n })\n .catch(() => {\n // Left null, which withholds the split. See the block comment.\n })\n void getCountFromServer(totalQuery)\n .then((snapshot) => {\n if (active) setTotalCount(snapshot.data().count)\n })\n .catch(() => {\n // Left null, which withholds the split. See the block comment.\n })\n return () => {\n active = false\n }\n }, [attributions, firestore, kind, campaignId, countSource, hostId, orgId])\n\n const coverage = campaignConversionsCoverage({\n kind,\n attributed: attributedCount,\n total: totalCount,\n crossHostTotal: totalCrossesHosts,\n })\n\n /*==========================================\n * LANDING PAGES — a join, and an EXPENSIVE one, so it is asked for.\n *\n * The attribution record carries `refId`; a form submission carries the\n * `path` it was submitted from. Joining the two is the only landing-page\n * answer the stored data supports, and the notice below says plainly what\n * it is not: `path` is where the FORM was, not where the campaign link\n * landed, so a visitor who arrived on one page and submitted on another is\n * grouped under the second.\n *\n * Two reads deep and both bounded: a ceiling over the attributions, then\n * their submissions by document name in chunks of thirty. `getDocs` rather\n * than a listener — a grouping nobody is watching does not need to be kept\n * live, and a listener would go on costing after the reader looked away.\n *=========================================*/\n const [landingBusy, setLandingBusy] = useState(false)\n const [landingError, setLandingError] = useState<string | null>(null)\n const [landing, setLanding] = useState<{\n rows: { $id: string; path: string; conversions: number }[]\n /** Attributions read, which is the population the grouping describes. */\n read: number\n /** The ceiling bit: there are more credited submissions than were read. */\n truncated: boolean\n /** Of `read`, how many named a submission that could not be found. */\n missing: number\n } | null>(null)\n\n // A grouping computed for one kind describes that kind. Switching the mode\n // leaves it on screen labelled as something it is not.\n useEffect(() => {\n setLanding(null)\n setLandingError(null)\n }, [kind, campaignId])\n\n const groupByLandingPage = useCallback(async () => {\n if (landingBusy) return\n setLandingBusy(true)\n setLandingError(null)\n try {\n const credited = await getDocs(\n collectionCeiling(\n campaignId\n ? query(\n attributions(),\n where('kind', '==', 'form'),\n where('campaignId', '==', campaignId),\n )\n : query(attributions(), where('kind', '==', 'form')),\n LANDING_PAGE_CEILING,\n ),\n )\n const { rows: credits, truncated } = ceilingedWindow(\n credited.docs.map((entry) => entry.data() as CampaignConversionRecord),\n LANDING_PAGE_CEILING,\n )\n const refIds = Array.from(\n new Set(\n credits\n .map((record) => String(record.refId ?? ''))\n .filter((id) => id.length > 0),\n ),\n )\n\n /*\n * The page each credited submission was sent from, asked of the plugin\n * that keeps submissions (`plugin-record-lists`, by name), a chunk at a\n * time. With no such plugin here every one reads as not found, and is\n * counted as missing below rather than grouped under a guess.\n */\n const paths = new Map<string, string>()\n for (let index = 0; index < refIds.length; index += ID_CHUNK) {\n const named = pluginRecordListByIdsQuery(SUBMISSION_RECORD_KIND, firestore, {\n hostId,\n ids: refIds.slice(index, index + ID_CHUNK),\n })\n if (!named) continue\n const found = await getDocs(named)\n const records = pluginRecordsFromRows(\n SUBMISSION_RECORD_KIND,\n found.docs.map((entry) => ({ ...entry.data(), $id: entry.id })),\n )\n for (const record of records) {\n const path = String(record.facts['path'] ?? '').trim()\n if (path) paths.set(record.id, path)\n }\n }\n\n const counts = new Map<string, number>()\n let missing = 0\n refIds.forEach((refId) => {\n const path = paths.get(refId)\n if (!path) {\n /*\n * The submission was deleted, or it carries no path — an older one,\n * or a form posted by an integration that sent none. Counted and\n * REPORTED rather than filed under a placeholder page: a bar\n * labelled \"/\" that is really \"we do not know\" is the kind of row a\n * reader acts on.\n */\n missing += 1\n return\n }\n counts.set(path, (counts.get(path) ?? 0) + 1)\n })\n\n setLanding({\n rows: Array.from(counts.entries())\n .map(([path, conversions]) => ({ $id: path, path, conversions }))\n .sort(\n (a, b) =>\n b.conversions - a.conversions || a.path.localeCompare(b.path),\n ),\n read: refIds.length,\n truncated,\n missing,\n })\n } catch (error) {\n console.error(error)\n setLandingError('The landing pages could not be read')\n } finally {\n setLandingBusy(false)\n }\n }, [attributions, campaignId, firestore, hostId, landingBusy])\n\n const campaignHref = (row: ConversionRow) =>\n row.campaignId ? `${basePath}/campaigns/${row.campaignId}` : undefined\n\n const columns = useMemo(\n () => [\n {\n field: 'refId',\n headerName: 'Record',\n flex: 1,\n minWidth: 200,\n renderCell: ({ row }: any) => (\n <Stack sx={{ minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {String(row.refId ?? row.$id)}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {CAMPAIGN_CONVERSION_KIND_COPY[kind].label}\n </Typography>\n </Stack>\n ),\n },\n {\n field: 'campaign',\n headerName: 'Credited to',\n flex: 1,\n minWidth: 180,\n renderCell: ({ row }: any) => {\n const label = campaignTouchLabel(row) || '—'\n const href = campaignHref(row)\n return href ? (\n <AppLink\n href={href}\n onClick={(event: { stopPropagation: () => void }) =>\n event.stopPropagation()\n }\n >\n {label}\n </AppLink>\n ) : (\n <Typography variant=\"body2\" noWrap>\n {label}\n </Typography>\n )\n },\n },\n {\n field: 'convertedAtMs',\n headerName: 'Converted',\n width: 190,\n renderCell: ({ row }: any) => (\n <Typography variant=\"body2\" noWrap>\n {day(row.convertedAtMs)}\n </Typography>\n ),\n },\n listActionsColumn((row: any) => (\n <ListRowActions\n label={String(row.refId ?? row.$id)}\n items={[\n {\n key: 'campaign',\n label: 'Open campaign',\n icon: <MdiIcon path={mdiEyeOutline.path} size={0.8} />,\n href: campaignHref(row),\n disabled: !campaignHref(row),\n /*\n * Shown disabled with the reason rather than hidden. A control\n * that vanishes and one that does not apply look identical from\n * the outside, and only one of them is honest — there is no\n * campaign document behind a `utm_` label to open.\n */\n disabledReason:\n 'This came from a tagged link rather than a campaign email, ' +\n 'so there is no campaign to open',\n },\n ]}\n />\n )),\n ],\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [kind, basePath],\n )\n\n const landingColumns = useMemo(\n () => [\n {\n field: 'path',\n headerName: 'Page the form was on',\n flex: 1,\n minWidth: 240,\n renderCell: ({ row }: any) => (\n <Typography variant=\"body2\" noWrap>\n {row.path}\n </Typography>\n ),\n },\n {\n field: 'conversions',\n headerName: 'Credited submissions',\n width: 190,\n align: 'right',\n headerAlign: 'right',\n renderCell: ({ row }: any) => (\n <Typography variant=\"body2\">\n {Number(row.conversions).toLocaleString()}\n </Typography>\n ),\n },\n ],\n [],\n )\n\n const kindCopy = CAMPAIGN_CONVERSION_KIND_COPY[kind]\n\n return (\n <CardDisplay\n header=\"Conversions\"\n subheader={\n campaignId\n ? 'Credited to this campaign'\n : 'What the campaigns caused, one kind at a time'\n }\n help={conversionsDocsHelp}\n HeaderProps={{\n action: (\n <Stack direction=\"row\" spacing={1}>\n {/*\n The figures in words, from a plugin (AGL-3603): the\n `marketingInsights` zone this plugin declares, handed the site\n these conversions are one site's.\n */}\n <MarketingInsightsZone hostId={hostId} subject=\"conversions\" campaign={null} />\n {campaignId ? (\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 ) : null}\n </Stack>\n ),\n }}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n {/*\n THE KIND IS A MODE, NOT A COLUMN.\n\n One form submission by a new person writes a submission, a contact\n and a lead, so any view holding two kinds at once invites a total\n that counts one visit twice. Only one kind's rows can be on screen,\n which is what makes the addition unavailable rather than merely\n discouraged.\n */}\n <Stack spacing={1}>\n <ToggleButtonGroup\n exclusive\n size=\"small\"\n color=\"primary\"\n value={kind}\n onChange={(_event, next) => {\n if (next) setKind(next as CampaignConversionKind)\n }}\n aria-label=\"Conversion kind\"\n >\n {CAMPAIGN_CONVERSION_KINDS.map((one) => (\n <ToggleButton key={one} value={one}>\n {CAMPAIGN_CONVERSION_KIND_COPY[one].label}\n </ToggleButton>\n ))}\n </ToggleButtonGroup>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'One kind at a time. The four count different things about the ' +\n 'same visits — one person filling in one form appears as a ' +\n 'submission, a contact and a lead — so they are never shown ' +\n 'together and never added.'}\n </Typography>\n </Stack>\n\n <Divider />\n\n {/*==========================================\n * WHAT IS NOT CREDITED, beside what is.\n *\n * The tables below list the successes. Without this strip the reader\n * has no way to see how much of their site's activity the campaigns\n * account for, and every campaign reads as more effective than it is.\n *=========================================*/}\n {campaignId ? (\n <Alert severity=\"info\">\n {'This is one campaign’s share. Conversions credited to no ' +\n 'campaign belong to no campaign, so they are not counted here ' +\n '— open all conversions for the site-wide figure.'}\n </Alert>\n ) : coverage ? (\n <Section title={`${kindCopy.label} on this site`}>\n <Stack\n direction=\"row\"\n spacing={4}\n useFlexGap\n sx={{ flexWrap: 'wrap' }}\n >\n <Figure\n label=\"Credited to a campaign\"\n value={coverage.attributed}\n note=\"from a campaign email or a tagged link\"\n />\n <Figure\n label=\"Not credited\"\n value={coverage.unattributed}\n note=\"arrived directly, or predate attribution\"\n />\n <Figure\n label={`${kindCopy.label} in total`}\n value={coverage.total}\n note={\n coverage.exact ? 'on this site' : 'on this site, all time'\n }\n />\n </Stack>\n {coverage.caveats.map((caveat) => (\n <Alert key={caveat.id} severity=\"info\">\n {caveat.message}\n </Alert>\n ))}\n </Section>\n ) : (\n <Alert severity=\"info\">\n {'How many of these were credited to no campaign could not be ' +\n 'counted, so it is not shown. The lists below are the credited ' +\n 'ones only and are not a count of everything that happened.'}\n </Alert>\n )}\n\n <Divider />\n\n <Section title=\"From campaign emails\">\n <ListTable\n rows={emailList.rows}\n columns={columns as any}\n hideFooter\n // One page of a walk in stored order; a header sort would order\n // only that page.\n disableColumnSorting\n onOpen={(_id, row) => {\n const href = campaignHref(row as ConversionRow)\n if (href) router.push(href)\n }}\n noRowsLabel=\"Nothing credited to a campaign email\"\n noRowsDescription={\n 'A conversion is credited when the visitor followed a link in ' +\n 'a campaign email before converting.'\n }\n />\n <ListPagination\n page={emailList.page}\n pageSize={emailList.pageSize}\n rowCount={emailList.rows.length}\n hasMore={emailList.hasMore}\n onPageChange={emailList.setPage}\n onPageSizeChange={emailList.setPageSize}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Listed in the order they are stored, which is not the order ' +\n 'they happened in — every row is reachable by paging, but the ' +\n 'first page is not the most recent conversions.'}\n </Typography>\n </Section>\n\n {/*==========================================\n * THE WEB CHANNEL — its own list, and no rollup.\n *\n * A `utm_` label is text somebody typed into a URL. There is no\n * document behind it, no id, and no bound on how many distinct\n * values exist, so it gets no rollup under a campaign and no summary\n * keyed on the label: a map anybody who can vary a query string can\n * grow is a map that grows. The records stand on their own and this\n * lists them.\n *\n * Absent entirely on a campaign-scoped view, because these belong to\n * no campaign.\n *=========================================*/}\n {campaignId ? null : (\n <Section title=\"From tagged web links\">\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Credited to the utm_ label on the link the visitor followed. ' +\n 'These are listed one by one rather than grouped: the label ' +\n 'is free text with no campaign behind it, so there is ' +\n 'nothing to open and no fixed set to total.'}\n </Typography>\n <ListTable\n rows={webList.rows}\n columns={columns as any}\n hideFooter\n // One page of a walk in stored order; a header sort would\n // order only that page.\n disableColumnSorting\n noRowsLabel=\"Nothing credited to a tagged link\"\n noRowsDescription={\n 'A conversion lands here when the visitor arrived on a URL ' +\n 'carrying utm_ parameters.'\n }\n />\n <ListPagination\n page={webList.page}\n pageSize={webList.pageSize}\n rowCount={webList.rows.length}\n hasMore={webList.hasMore}\n onPageChange={webList.setPage}\n onPageSizeChange={webList.setPageSize}\n />\n </Section>\n )}\n\n {/*==========================================\n * LANDING PAGES, on request.\n *\n * `refId` on the record, `path` on the submission: joining those is\n * the landing-page surface, and it is hundreds of reads, so it is a\n * button rather than something every reader of this page pays for.\n *=========================================*/}\n {kind === 'form' ? (\n <>\n <Divider />\n <Section title=\"Landing pages\">\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Groups credited form submissions by the page the form was ' +\n 'on. This reads up to ' +\n `${LANDING_PAGE_CEILING.toLocaleString()} attribution ` +\n 'records and their submissions, so it runs when you ask ' +\n 'for it rather than on every visit.'}\n </Typography>\n <Stack direction=\"row\" spacing={1}>\n <Button\n size=\"small\"\n variant=\"contained\"\n disabled={landingBusy}\n startIcon={\n <MdiIcon path={mdiMapMarkerOutline.path} size={0.8} />\n }\n onClick={() => void groupByLandingPage()}\n >\n {landingBusy ? 'Reading…' : 'Group by landing page'}\n </Button>\n </Stack>\n {landingError ? (\n <Alert severity=\"warning\">{landingError}</Alert>\n ) : null}\n {landing ? (\n <Stack spacing={1}>\n {/*\n WHAT THIS CANNOT ANSWER, above the table rather than under\n it. Every line is a question a reader will otherwise\n assume it answered.\n */}\n <Alert severity=\"info\">\n {'This is the page each form sat on, not the page the ' +\n 'campaign link landed on — a visitor who arrived on ' +\n 'one page and submitted on another is counted under ' +\n 'the second. There is no conversion RATE here either: ' +\n 'the record carries no count of visits to a page from ' +\n 'a campaign, so there is no denominator to divide by. ' +\n 'Only form submissions carry a page at all, so leads, ' +\n 'contacts and bookings have no landing page.'}\n </Alert>\n {landing.truncated ? (\n <Alert severity=\"warning\">\n {`More than ${LANDING_PAGE_CEILING.toLocaleString()} ` +\n 'credited submissions exist. This groups the ' +\n `${landing.read.toLocaleString()} that were read, ` +\n 'which are not the most recent — they are the ones ' +\n 'that came first in storage order.'}\n </Alert>\n ) : null}\n {landing.missing ? (\n <Alert severity=\"info\">\n {`${landing.missing.toLocaleString()} of the ` +\n `${landing.read.toLocaleString()} credited ` +\n 'submissions are not grouped: the submission has ' +\n 'been deleted, or it recorded no page. They are ' +\n 'reported here rather than filed under a page they ' +\n 'may not have come from.'}\n </Alert>\n ) : null}\n <ListTable\n rows={landing.rows}\n columns={landingColumns as any}\n hideFooter\n noRowsLabel=\"No pages to group\"\n noRowsDescription=\"None of the credited submissions recorded a page.\"\n />\n <Stack direction=\"row\" spacing={1}>\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={`${landing.read.toLocaleString()} credited submissions read`}\n />\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={`${landing.rows.length.toLocaleString()} pages`}\n />\n </Stack>\n </Stack>\n ) : null}\n </Section>\n </>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nCampaignConversionsCard.displayName = 'CampaignConversionsCard'\n\nexport default CampaignConversionsCard\n"],"names":["pluginDocsHelp","pluginRecordCountSource","PLUGIN_RECORD_LIST_IDS_MAX","pluginRecordListByIdsQuery","pluginRecordsFromRows","mdiEyeOutline","mdiMapMarkerOutline","AppLink","CardDisplay","MdiIcon","ListRowActions","ListTable","listActionsColumn","ListPagination","Figure","Section","Alert","Button","Chip","Divider","Stack","ToggleButton","ToggleButtonGroup","Typography","collection","getCountFromServer","getDocs","query","where","useCallback","useEffect","useMemo","useState","useRouter","useFirestore","useOrgDataScope","usePagedCollection","ceilingedWindow","collectionCeiling","collectionPage","CAMPAIGN_CONVERSION_KINDS","CAMPAIGN_CONVERSION_KIND_COPY","CAMPAIGN_CONVERSION_RECORD_KINDS","campaignConversionsCoverage","campaignTouchLabel","MarketingInsightsZone","LANDING_PAGE_CEILING","ID_CHUNK","SUBMISSION_RECORD_KIND","form","conversionsDocsHelp","anchor","excerpt","day","ms","value","Number","isFinite","Date","toLocaleString","CampaignConversionsCard","props","hostId","basePath","campaignId","firestore","router","scope","dataScope","kind","setKind","attributions","emailList","pageLimit","idField","webList","orgId","countSource","totalCrossesHosts","crossesSites","attributedCount","setAttributedCount","totalCount","setTotalCount","totalQuery","active","then","snapshot","data","count","catch","coverage","attributed","total","crossHostTotal","landingBusy","setLandingBusy","landingError","setLandingError","landing","setLanding","groupByLandingPage","credited","rows","credits","truncated","docs","map","entry","refIds","Array","from","Set","record","String","refId","filter","id","length","paths","Map","index","named","ids","slice","found","records","$id","path","facts","trim","set","counts","missing","forEach","get","entries","conversions","sort","a","b","localeCompare","read","error","console","campaignHref","row","undefined","columns","field","headerName","flex","minWidth","renderCell","sx","variant","noWrap","color","label","href","onClick","event","stopPropagation","width","convertedAtMs","items","key","icon","size","disabled","disabledReason","landingColumns","align","headerAlign","kindCopy","header","subheader","help","HeaderProps","action","direction","spacing","subject","campaign","component","componentVariant","nativeButton","contentGutterX","contentGutterY","exclusive","onChange","_event","next","aria-label","one","severity","title","useFlexGap","flexWrap","note","unattributed","exact","caveats","caveat","message","hideFooter","disableColumnSorting","onOpen","_id","push","noRowsLabel","noRowsDescription","page","pageSize","rowCount","hasMore","onPageChange","setPage","onPageSizeChange","setPageSize","startIcon","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,eAAc;AAC7C,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SACEC,0BAA0B,EAC1BC,0BAA0B,EAC1BC,qBAAqB,QAChB,kDAAiD;AACxD,SAASC,aAAa,EAAEC,mBAAmB,QAAQ,yBAAwB;AAC3E,SAASC,OAAO,EAAEC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AACpE,SACEC,cAAc,EACdC,SAAS,EACTC,iBAAiB,QACZ,uDAAsD;AAC7D,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,MAAM,EAAEC,OAAO,QAAQ,6DAA4D;AAC5F,SACEC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,OAAO,EACPC,KAAK,EACLC,YAAY,EACZC,iBAAiB,EACjBC,UAAU,QACL,gBAAe;AACtB,SACEC,UAAU,EACVC,kBAAkB,EAClBC,OAAO,EACPC,KAAK,EACLC,KAAK,QACA,qBAAoB;AAC3B,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SACEC,YAAY,EACZC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC;;;;CAIC,GACD,SACEC,eAAe,EACfC,iBAAiB,EACjBC,cAAc,QACT,+DAA8D;AACrE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,oBAAoB0H,IAAI;4CAAEwC,MAAM;;wCAEjDR,SAAS,IAAM,KAAK3D;kDAEnBN,cAAc,aAAa;;;gCAG/BE,6BACC,KAACjF;oCAAMmL,UAAS;8CAAWlG;qCACzB;gCACHE,wBACC,MAAC/E;oCAAMiK,SAAS;;sDAMd,KAACrK;4CAAMmL,UAAS;sDACb,yDACC,wDACA,wDACA,0DACA,0DACA,0DACA,0DACA;;wCAEHhG,QAAQM,SAAS,iBAChB,KAACzF;4CAAMmL,UAAS;sDACb,CAAC,UAAU,EAAErJ,qBAAqBa,cAAc,GAAG,CAAC,CAAC,GACpD,iDACA,GAAGwC,QAAQ2C,IAAI,CAACnF,cAAc,GAAG,iBAAiB,CAAC,GACnD,uDACA;6CAEF;wCACHwC,QAAQkC,OAAO,iBACd,KAACrH;4CAAMmL,UAAS;sDACb,GAAGhG,QAAQkC,OAAO,CAAC1E,cAAc,GAAG,QAAQ,CAAC,GAC5C,GAAGwC,QAAQ2C,IAAI,CAACnF,cAAc,GAAG,UAAU,CAAC,GAC5C,qDACA,oDACA,uDACA;6CAEF;sDACJ,KAAChD;4CACC4F,MAAMJ,QAAQI,IAAI;4CAClB6C,SAASuB;4CACTkC,UAAU;4CACVK,aAAY;4CACZC,mBAAkB;;sDAEpB,MAAC/L;4CAAMgK,WAAU;4CAAMC,SAAS;;8DAC9B,KAACnK;oDACCsJ,MAAK;oDACLb,SAAQ;oDACRG,OAAO,GAAG3D,QAAQ2C,IAAI,CAACnF,cAAc,GAAG,0BAA0B,CAAC;;8DAErE,KAACzC;oDACCsJ,MAAK;oDACLb,SAAQ;oDACRG,OAAO,GAAG3D,QAAQI,IAAI,CAACe,MAAM,CAAC3D,cAAc,GAAG,MAAM,CAAC;;;;;qCAI1D;;;;qBAGN;;;;AAIZ;AACAC,wBAAwBiK,WAAW,GAAG;AAEtC,eAAejK,wBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/campaign-conversions-card.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 { pluginDocsHelp } from '@aglyn/aglyn'\nimport { pluginRecordCountSource } from '@aglyn/aglyn/plugin-manager/plugin-record-counts'\nimport {\n PLUGIN_RECORD_LIST_IDS_MAX,\n pluginRecordListByIdsQuery,\n pluginRecordsFromRows,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { mdiEyeOutline, mdiMapMarkerOutline } from '@aglyn/shared-data-mdi'\nimport { AppLink, CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport {\n ListRowActions,\n ListTable,\n listActionsColumn,\n} from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { Figure, Section } from '@aglyn/shared-ui-jsx/components/measured-figures.component'\nimport {\n Alert,\n Button,\n Chip,\n Divider,\n Stack,\n ToggleButton,\n ToggleButtonGroup,\n Typography,\n} from '@mui/material'\nimport {\n collection,\n getCountFromServer,\n getDocs,\n limit,\n orderBy,\n type Query,\n query,\n where,\n} from 'firebase/firestore'\nimport ListQueryNotices from '@aglyn/shared-ui-jsx/components/list-query-notices.component'\nimport type { ListQuerySort } from '@aglyn/shared-ui-jsx/const/list-query-plan'\nimport { useListColumnSort } from '@aglyn/shared-ui-jsx/hooks/use-list-column-sort'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { useRouter } from 'next/navigation'\nimport {\n useFirestore,\n useOrgDataScope,\n usePagedCollection,\n} from '@aglyn/tenant-feature-instance'\n/*\n * The MODULE, not the barrel, for the pure query helpers — a spec that mocks\n * `@aglyn/tenant-feature-instance` wholesale to stage its Firestore hooks\n * would otherwise lose them, and neither is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n collectionPage,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n CAMPAIGN_CONVERSION_KINDS,\n CAMPAIGN_CONVERSION_KIND_COPY,\n CAMPAIGN_CONVERSION_SORTS,\n CAMPAIGN_CONVERSION_RECORD_KINDS,\n campaignConversionsCoverage,\n campaignTouchLabel,\n type CampaignConversionKind,\n type CampaignConversionRecord,\n} from '../model/campaign-conversions'\nimport { MarketingInsightsZone } from './marketing-insight-zones'\n\n/**\n * WHAT THE CAMPAIGNS CAUSED, from the conversions' end.\n *\n * A campaign's own report says what that campaign caused. This is the list\n * the report cannot be: every credited conversion on the site, the ones\n * credited to a tagged web link rather than to a campaign document, and — the\n * half a report of successes can never show — how many were credited to\n * nothing at all.\n *\n * ## ONE KIND AT A TIME, and that is the whole design\n *\n * A form submission by a new person writes a submission record, a contact and\n * a lead. Three true statements about one visit, and a screen that showed\n * them together would invite the reader to add them and treble every figure.\n * So the kind is a MODE rather than a column: the query carries\n * `where('kind','==', …)`, only one kind's rows are ever on screen, and there\n * is no view in which two kinds could be totalled because there is no view in\n * which two kinds are both present.\n *\n * ## THE TWO CHANNELS ARE TWO LISTS, and never one\n *\n * An email touch names a campaign document — a real entity with a report to\n * open. A web touch names `utm_` text a marketer typed into a URL: no\n * document, no id, no bound on how many distinct values exist. Merging them\n * would put a linkable record and an unlinkable label in one column and imply\n * they are the same kind of thing, and grouping the web side into a rollup\n * would build a map anybody who can vary a query string can grow. So there\n * are two tables, the web one is read as records, and neither is summed into\n * the other.\n *\n * ## The read cost\n *\n * Two paged listeners bounded by the page size, and two aggregation counts.\n * Nothing scans a collection, no row triggers a read of its own, and the\n * landing-page join — the only expensive thing here — is behind a button and\n * says what it will cost before it runs.\n */\n\n/**\n * How many attribution records the landing-page join reads.\n *\n * A CEILING rather than a page size: grouping is over a window and a window\n * sliced ten at a time cannot be grouped at all. Kept low because this is the\n * one read on the surface that is measured in hundreds — see the button that\n * asks for it.\n */\nconst LANDING_PAGE_CEILING = 100\n\n/** The most submissions one by-name read asks for — Firestore's `in` cap. */\nconst ID_CHUNK = PLUGIN_RECORD_LIST_IDS_MAX\n\n/** A credited form conversion's `refId` names a submission of this kind. */\nconst SUBMISSION_RECORD_KIND = CAMPAIGN_CONVERSION_RECORD_KINDS.form\n\nconst conversionsDocsHelp = pluginDocsHelp('emailCampaigns', {\n anchor: '#the-campaign-report',\n excerpt:\n 'A conversion is credited to the last campaign whose link the visitor ' +\n 'followed. The four kinds count different things about the same visits ' +\n 'and are never added together.',\n})\n\n/** The stored record plus the document name the reader listed it under. */\ntype ConversionRow = CampaignConversionRecord & { $id: string }\n\n/** Credited to is a label drawn from several fields: it sorts the page (AGL-3680). */\nconst CONVERSION_PAGE_SORTS = {\n campaign: (row: ConversionRow) => campaignTouchLabel(row) || null,\n}\nconst CONVERSION_PAGE_SORT_HEADERS = { campaign: 'Credited to' }\n\nconst day = (ms: unknown): string => {\n const value = Number(ms ?? 0)\n return Number.isFinite(value) && value > 0\n ? new Date(value).toLocaleString()\n : '—'\n}\n\nexport interface CampaignConversionsCardProps {\n hostId: string\n /** The marketing hub URL, for the link to each credited campaign. */\n basePath: string\n /**\n * One campaign's conversions rather than the whole site's.\n *\n * Set from `/marketing/conversions/{campaignId}`. It narrows the EMAIL list\n * only: a web-channel record carries no campaign id, so there is nothing\n * for it to be narrowed by — and the uncredited figure is withheld\n * entirely, because a conversion credited to nobody belongs to no campaign\n * and attributing the site's whole direct traffic to whichever campaign the\n * reader happens to be looking at is the exact inference this join refuses\n * to make.\n */\n campaignId?: string\n}\n\nexport function CampaignConversionsCard(props: CampaignConversionsCardProps) {\n const { hostId, basePath, campaignId } = props\n const firestore = useFirestore()\n const router = useRouter()\n const { scope: dataScope } = useOrgDataScope({ hostId })\n const [kind, setKind] = useState<CampaignConversionKind>('form')\n\n const attributions = useCallback(\n () => collection(firestore, 'hosts', hostId, 'campaignAttributions'),\n [firestore, hostId],\n )\n\n /*==========================================\n * THE TWO LISTS.\n *\n * Both walk the collection in DOCUMENT-NAME order through `collectionPage`,\n * which is the console's one ordering decision: `orderBy` on a field\n * matches only documents that HAVE it, so ordering on a date would hide\n * rows rather than merely mis-order them, and an unordered `limit()` is a\n * pseudo-random sample whose gaps leave nothing to notice. The walk is\n * total — every row is reachable by paging — and it is deliberately NOT\n * newest-first, which the note under each table says out loud.\n *\n * `campaignId` narrows the email list when the reader arrived from one\n * campaign. It is never applied to the web list: a `utm_` label is not a\n * campaign id and a query pretending otherwise would return nothing while\n * reading as \"this campaign caused no web conversions\".\n *=========================================*/\n const [emailSortAsked, setEmailSortAsked] = useState<ListQuerySort | null>(null)\n const [webSortAsked, setWebSortAsked] = useState<ListQuerySort | null>(null)\n /*\n * A header order asked of a list replaces the document-name walk with an\n * `orderBy` on that field (AGL-3680, `CAMPAIGN_CONVERSION_SORTS`): both\n * fields are on every attribution, so the ordered walk is as total.\n */\n const orderedPage = (base: Query, sort: ListQuerySort | null, pageLimit: number) =>\n sort ? query(base, orderBy(sort.path, sort.direction), limit(pageLimit)) : collectionPage(base, pageLimit)\n const emailList = usePagedCollection<ConversionRow>(\n (pageLimit) =>\n orderedPage(\n campaignId\n ? query(\n attributions(),\n where('kind', '==', kind),\n where('campaignId', '==', campaignId),\n )\n : query(\n attributions(),\n where('kind', '==', kind),\n where('channel', '==', 'email'),\n ),\n emailSortAsked,\n pageLimit,\n ),\n [firestore, hostId, kind, campaignId, emailSortAsked?.path, emailSortAsked?.direction],\n { idField: '$id' },\n )\n\n const webList = usePagedCollection<ConversionRow>(\n (pageLimit) =>\n campaignId\n ? null\n : orderedPage(\n query(\n attributions(),\n where('kind', '==', kind),\n where('channel', '==', 'web'),\n ),\n webSortAsked,\n pageLimit,\n ),\n [firestore, hostId, kind, campaignId, webSortAsked?.path, webSortAsked?.direction],\n { idField: '$id' },\n )\n const emailSort = useListColumnSort<ConversionRow>({\n sorts: CAMPAIGN_CONVERSION_SORTS,\n sort: emailSortAsked,\n onSortChange: setEmailSortAsked,\n rows: emailList.rows,\n pageSorts: CONVERSION_PAGE_SORTS,\n headers: CONVERSION_PAGE_SORT_HEADERS,\n })\n const webSort = useListColumnSort<ConversionRow>({\n sorts: CAMPAIGN_CONVERSION_SORTS,\n sort: webSortAsked,\n onSortChange: setWebSortAsked,\n rows: webList.rows,\n pageSorts: CONVERSION_PAGE_SORTS,\n headers: CONVERSION_PAGE_SORT_HEADERS,\n })\n\n /*==========================================\n * THE UNCREDITED HALF.\n *\n * Two aggregation counts, and they are on the page by DEFAULT rather than\n * behind a button, because the tables above them are a list of the\n * successes: showing only those renders \"we credited nine of these\" as\n * \"nine of these happened\", which is the conclusion this surface exists to\n * stop a reader drawing. An aggregation is billed per thousand index\n * entries rather than per document, so the honest figure costs about as\n * much as one row.\n *\n * Withheld entirely when either count fails. Defaulting the total to the\n * attributed figure would render every conversion as attributed, which is\n * the most flattering wrong answer available here.\n *=========================================*/\n /*\n * THE TOTAL IS COUNTED BY THE PLUGIN THAT KEEPS THE RECORDS\n * (`plugin-record-counts`, AGL-3080): the forms plugin's submissions, the\n * bookings plugin's bookings, the record system's leads and contacts. The\n * owner says which of its records this site produced — its own\n * submissions and bookings, the leads it CAPTURED (AGL-3275; not the ones\n * a consent group merely shares with it), and for contacts, which the\n * organization holds once for every site, all of them, which the owner\n * marks as a count that crosses sites. With no owner in this console the\n * total is withheld exactly as a failed count is.\n *\n * The source is resolved per kind and the query built inside the effect,\n * from primitives: a query object rebuilt on every render as a dependency\n * would reopen the effect, and pay for two aggregation counts, on every\n * render rather than per kind.\n */\n const orgId = dataScope ? dataScope[1] : null\n const countSource = useMemo(\n () => pluginRecordCountSource(CAMPAIGN_CONVERSION_RECORD_KINDS[kind]),\n [kind],\n )\n\n /** The kind's records live outside this host, so the total over-counts. */\n const totalCrossesHosts = countSource?.crossesSites === true\n\n const [attributedCount, setAttributedCount] = useState<number | null>(null)\n const [totalCount, setTotalCount] = useState<number | null>(null)\n\n useEffect(() => {\n // A campaign-scoped view has no uncredited figure to compute — see the\n // prop's docblock — so it does not pay for one either.\n const totalQuery = campaignId\n ? null\n : (countSource?.query(firestore, { hostId, orgId }) ?? null)\n if (!totalQuery) {\n setAttributedCount(null)\n setTotalCount(null)\n return\n }\n let active = true\n setAttributedCount(null)\n setTotalCount(null)\n void getCountFromServer(query(attributions(), where('kind', '==', kind)))\n .then((snapshot) => {\n if (active) setAttributedCount(snapshot.data().count)\n })\n .catch(() => {\n // Left null, which withholds the split. See the block comment.\n })\n void getCountFromServer(totalQuery)\n .then((snapshot) => {\n if (active) setTotalCount(snapshot.data().count)\n })\n .catch(() => {\n // Left null, which withholds the split. See the block comment.\n })\n return () => {\n active = false\n }\n }, [attributions, firestore, kind, campaignId, countSource, hostId, orgId])\n\n const coverage = campaignConversionsCoverage({\n kind,\n attributed: attributedCount,\n total: totalCount,\n crossHostTotal: totalCrossesHosts,\n })\n\n /*==========================================\n * LANDING PAGES — a join, and an EXPENSIVE one, so it is asked for.\n *\n * The attribution record carries `refId`; a form submission carries the\n * `path` it was submitted from. Joining the two is the only landing-page\n * answer the stored data supports, and the notice below says plainly what\n * it is not: `path` is where the FORM was, not where the campaign link\n * landed, so a visitor who arrived on one page and submitted on another is\n * grouped under the second.\n *\n * Two reads deep and both bounded: a ceiling over the attributions, then\n * their submissions by document name in chunks of thirty. `getDocs` rather\n * than a listener — a grouping nobody is watching does not need to be kept\n * live, and a listener would go on costing after the reader looked away.\n *=========================================*/\n const [landingBusy, setLandingBusy] = useState(false)\n const [landingError, setLandingError] = useState<string | null>(null)\n const [landing, setLanding] = useState<{\n rows: { $id: string; path: string; conversions: number }[]\n /** Attributions read, which is the population the grouping describes. */\n read: number\n /** The ceiling bit: there are more credited submissions than were read. */\n truncated: boolean\n /** Of `read`, how many named a submission that could not be found. */\n missing: number\n } | null>(null)\n\n // A grouping computed for one kind describes that kind. Switching the mode\n // leaves it on screen labelled as something it is not.\n useEffect(() => {\n setLanding(null)\n setLandingError(null)\n }, [kind, campaignId])\n\n const groupByLandingPage = useCallback(async () => {\n if (landingBusy) return\n setLandingBusy(true)\n setLandingError(null)\n try {\n const credited = await getDocs(\n collectionCeiling(\n campaignId\n ? query(\n attributions(),\n where('kind', '==', 'form'),\n where('campaignId', '==', campaignId),\n )\n : query(attributions(), where('kind', '==', 'form')),\n LANDING_PAGE_CEILING,\n ),\n )\n const { rows: credits, truncated } = ceilingedWindow(\n credited.docs.map((entry) => entry.data() as CampaignConversionRecord),\n LANDING_PAGE_CEILING,\n )\n const refIds = Array.from(\n new Set(\n credits\n .map((record) => String(record.refId ?? ''))\n .filter((id) => id.length > 0),\n ),\n )\n\n /*\n * The page each credited submission was sent from, asked of the plugin\n * that keeps submissions (`plugin-record-lists`, by name), a chunk at a\n * time. With no such plugin here every one reads as not found, and is\n * counted as missing below rather than grouped under a guess.\n */\n const paths = new Map<string, string>()\n for (let index = 0; index < refIds.length; index += ID_CHUNK) {\n const named = pluginRecordListByIdsQuery(SUBMISSION_RECORD_KIND, firestore, {\n hostId,\n ids: refIds.slice(index, index + ID_CHUNK),\n })\n if (!named) continue\n const found = await getDocs(named)\n const records = pluginRecordsFromRows(\n SUBMISSION_RECORD_KIND,\n found.docs.map((entry) => ({ ...entry.data(), $id: entry.id })),\n )\n for (const record of records) {\n const path = String(record.facts['path'] ?? '').trim()\n if (path) paths.set(record.id, path)\n }\n }\n\n const counts = new Map<string, number>()\n let missing = 0\n refIds.forEach((refId) => {\n const path = paths.get(refId)\n if (!path) {\n /*\n * The submission was deleted, or it carries no path — an older one,\n * or a form posted by an integration that sent none. Counted and\n * REPORTED rather than filed under a placeholder page: a bar\n * labelled \"/\" that is really \"we do not know\" is the kind of row a\n * reader acts on.\n */\n missing += 1\n return\n }\n counts.set(path, (counts.get(path) ?? 0) + 1)\n })\n\n setLanding({\n rows: Array.from(counts.entries())\n .map(([path, conversions]) => ({ $id: path, path, conversions }))\n .sort(\n (a, b) =>\n b.conversions - a.conversions || a.path.localeCompare(b.path),\n ),\n read: refIds.length,\n truncated,\n missing,\n })\n } catch (error) {\n console.error(error)\n setLandingError('The landing pages could not be read')\n } finally {\n setLandingBusy(false)\n }\n }, [attributions, campaignId, firestore, hostId, landingBusy])\n\n const campaignHref = (row: ConversionRow) =>\n row.campaignId ? `${basePath}/campaigns/${row.campaignId}` : undefined\n\n const columns = useMemo(\n () => [\n {\n field: 'refId',\n headerName: 'Record',\n flex: 1,\n minWidth: 200,\n renderCell: ({ row }: any) => (\n <Stack sx={{ minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {String(row.refId ?? row.$id)}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {CAMPAIGN_CONVERSION_KIND_COPY[kind].label}\n </Typography>\n </Stack>\n ),\n },\n {\n field: 'campaign',\n headerName: 'Credited to',\n flex: 1,\n minWidth: 180,\n renderCell: ({ row }: any) => {\n const label = campaignTouchLabel(row) || '—'\n const href = campaignHref(row)\n return href ? (\n <AppLink\n href={href}\n onClick={(event: { stopPropagation: () => void }) =>\n event.stopPropagation()\n }\n >\n {label}\n </AppLink>\n ) : (\n <Typography variant=\"body2\" noWrap>\n {label}\n </Typography>\n )\n },\n },\n {\n field: 'convertedAtMs',\n headerName: 'Converted',\n width: 190,\n renderCell: ({ row }: any) => (\n <Typography variant=\"body2\" noWrap>\n {day(row.convertedAtMs)}\n </Typography>\n ),\n },\n listActionsColumn((row: any) => (\n <ListRowActions\n label={String(row.refId ?? row.$id)}\n items={[\n {\n key: 'campaign',\n label: 'Open campaign',\n icon: <MdiIcon path={mdiEyeOutline.path} size={0.8} />,\n href: campaignHref(row),\n disabled: !campaignHref(row),\n /*\n * Shown disabled with the reason rather than hidden. A control\n * that vanishes and one that does not apply look identical from\n * the outside, and only one of them is honest — there is no\n * campaign document behind a `utm_` label to open.\n */\n disabledReason:\n 'This came from a tagged link rather than a campaign email, ' +\n 'so there is no campaign to open',\n },\n ]}\n />\n )),\n ],\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [kind, basePath],\n )\n\n const landingColumns = useMemo(\n () => [\n {\n field: 'path',\n headerName: 'Page the form was on',\n flex: 1,\n minWidth: 240,\n renderCell: ({ row }: any) => (\n <Typography variant=\"body2\" noWrap>\n {row.path}\n </Typography>\n ),\n },\n {\n field: 'conversions',\n headerName: 'Credited submissions',\n width: 190,\n align: 'right',\n headerAlign: 'right',\n renderCell: ({ row }: any) => (\n <Typography variant=\"body2\">\n {Number(row.conversions).toLocaleString()}\n </Typography>\n ),\n },\n ],\n [],\n )\n\n const kindCopy = CAMPAIGN_CONVERSION_KIND_COPY[kind]\n\n return (\n <CardDisplay\n header=\"Conversions\"\n subheader={\n campaignId\n ? 'Credited to this campaign'\n : 'What the campaigns caused, one kind at a time'\n }\n help={conversionsDocsHelp}\n HeaderProps={{\n action: (\n <Stack direction=\"row\" spacing={1}>\n {/*\n The figures in words, from a plugin (AGL-3603): the\n `marketingInsights` zone this plugin declares, handed the site\n these conversions are one site's.\n */}\n <MarketingInsightsZone hostId={hostId} subject=\"conversions\" campaign={null} />\n {campaignId ? (\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 ) : null}\n </Stack>\n ),\n }}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={2}>\n {/*\n THE KIND IS A MODE, NOT A COLUMN.\n\n One form submission by a new person writes a submission, a contact\n and a lead, so any view holding two kinds at once invites a total\n that counts one visit twice. Only one kind's rows can be on screen,\n which is what makes the addition unavailable rather than merely\n discouraged.\n */}\n <Stack spacing={1}>\n <ToggleButtonGroup\n exclusive\n size=\"small\"\n color=\"primary\"\n value={kind}\n onChange={(_event, next) => {\n if (next) setKind(next as CampaignConversionKind)\n }}\n aria-label=\"Conversion kind\"\n >\n {CAMPAIGN_CONVERSION_KINDS.map((one) => (\n <ToggleButton key={one} value={one}>\n {CAMPAIGN_CONVERSION_KIND_COPY[one].label}\n </ToggleButton>\n ))}\n </ToggleButtonGroup>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'One kind at a time. The four count different things about the ' +\n 'same visits — one person filling in one form appears as a ' +\n 'submission, a contact and a lead — so they are never shown ' +\n 'together and never added.'}\n </Typography>\n </Stack>\n\n <Divider />\n\n {/*==========================================\n * WHAT IS NOT CREDITED, beside what is.\n *\n * The tables below list the successes. Without this strip the reader\n * has no way to see how much of their site's activity the campaigns\n * account for, and every campaign reads as more effective than it is.\n *=========================================*/}\n {campaignId ? (\n <Alert severity=\"info\">\n {'This is one campaign’s share. Conversions credited to no ' +\n 'campaign belong to no campaign, so they are not counted here ' +\n '— open all conversions for the site-wide figure.'}\n </Alert>\n ) : coverage ? (\n <Section title={`${kindCopy.label} on this site`}>\n <Stack\n direction=\"row\"\n spacing={4}\n useFlexGap\n sx={{ flexWrap: 'wrap' }}\n >\n <Figure\n label=\"Credited to a campaign\"\n value={coverage.attributed}\n note=\"from a campaign email or a tagged link\"\n />\n <Figure\n label=\"Not credited\"\n value={coverage.unattributed}\n note=\"arrived directly, or predate attribution\"\n />\n <Figure\n label={`${kindCopy.label} in total`}\n value={coverage.total}\n note={\n coverage.exact ? 'on this site' : 'on this site, all time'\n }\n />\n </Stack>\n {coverage.caveats.map((caveat) => (\n <Alert key={caveat.id} severity=\"info\">\n {caveat.message}\n </Alert>\n ))}\n </Section>\n ) : (\n <Alert severity=\"info\">\n {'How many of these were credited to no campaign could not be ' +\n 'counted, so it is not shown. The lists below are the credited ' +\n 'ones only and are not a count of everything that happened.'}\n </Alert>\n )}\n\n <Divider />\n\n <Section title=\"From campaign emails\">\n <ListQueryNotices refused={[]} notices={emailSort.notices} />\n <ListTable\n rows={emailSort.rows}\n columns={columns as any}\n hideFooter\n // Converted and Record order the query; Credited to sorts the\n // page and says so (AGL-3680).\n columnSort={emailSort}\n onOpen={(_id, row) => {\n const href = campaignHref(row as ConversionRow)\n if (href) router.push(href)\n }}\n noRowsLabel=\"Nothing credited to a campaign email\"\n noRowsDescription={\n 'A conversion is credited when the visitor followed a link in ' +\n 'a campaign email before converting.'\n }\n />\n <ListPagination\n page={emailList.page}\n pageSize={emailList.pageSize}\n rowCount={emailList.rows.length}\n hasMore={emailList.hasMore}\n onPageChange={emailList.setPage}\n onPageSizeChange={emailList.setPageSize}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Listed in the order they are stored, which is not the order ' +\n 'they happened in — every row is reachable by paging, but the ' +\n 'first page is not the most recent conversions. Sort by ' +\n 'Converted for those.'}\n </Typography>\n </Section>\n\n {/*==========================================\n * THE WEB CHANNEL — its own list, and no rollup.\n *\n * A `utm_` label is text somebody typed into a URL. There is no\n * document behind it, no id, and no bound on how many distinct\n * values exist, so it gets no rollup under a campaign and no summary\n * keyed on the label: a map anybody who can vary a query string can\n * grow is a map that grows. The records stand on their own and this\n * lists them.\n *\n * Absent entirely on a campaign-scoped view, because these belong to\n * no campaign.\n *=========================================*/}\n {campaignId ? null : (\n <Section title=\"From tagged web links\">\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Credited to the utm_ label on the link the visitor followed. ' +\n 'These are listed one by one rather than grouped: the label ' +\n 'is free text with no campaign behind it, so there is ' +\n 'nothing to open and no fixed set to total.'}\n </Typography>\n <ListQueryNotices refused={[]} notices={webSort.notices} />\n <ListTable\n rows={webSort.rows}\n columns={columns as any}\n hideFooter\n // Converted and Record order the query; Credited to sorts the\n // page and says so (AGL-3680).\n columnSort={webSort}\n noRowsLabel=\"Nothing credited to a tagged link\"\n noRowsDescription={\n 'A conversion lands here when the visitor arrived on a URL ' +\n 'carrying utm_ parameters.'\n }\n />\n <ListPagination\n page={webList.page}\n pageSize={webList.pageSize}\n rowCount={webList.rows.length}\n hasMore={webList.hasMore}\n onPageChange={webList.setPage}\n onPageSizeChange={webList.setPageSize}\n />\n </Section>\n )}\n\n {/*==========================================\n * LANDING PAGES, on request.\n *\n * `refId` on the record, `path` on the submission: joining those is\n * the landing-page surface, and it is hundreds of reads, so it is a\n * button rather than something every reader of this page pays for.\n *=========================================*/}\n {kind === 'form' ? (\n <>\n <Divider />\n <Section title=\"Landing pages\">\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Groups credited form submissions by the page the form was ' +\n 'on. This reads up to ' +\n `${LANDING_PAGE_CEILING.toLocaleString()} attribution ` +\n 'records and their submissions, so it runs when you ask ' +\n 'for it rather than on every visit.'}\n </Typography>\n <Stack direction=\"row\" spacing={1}>\n <Button\n size=\"small\"\n variant=\"contained\"\n disabled={landingBusy}\n startIcon={\n <MdiIcon path={mdiMapMarkerOutline.path} size={0.8} />\n }\n onClick={() => void groupByLandingPage()}\n >\n {landingBusy ? 'Reading…' : 'Group by landing page'}\n </Button>\n </Stack>\n {landingError ? (\n <Alert severity=\"warning\">{landingError}</Alert>\n ) : null}\n {landing ? (\n <Stack spacing={1}>\n {/*\n WHAT THIS CANNOT ANSWER, above the table rather than under\n it. Every line is a question a reader will otherwise\n assume it answered.\n */}\n <Alert severity=\"info\">\n {'This is the page each form sat on, not the page the ' +\n 'campaign link landed on — a visitor who arrived on ' +\n 'one page and submitted on another is counted under ' +\n 'the second. There is no conversion RATE here either: ' +\n 'the record carries no count of visits to a page from ' +\n 'a campaign, so there is no denominator to divide by. ' +\n 'Only form submissions carry a page at all, so leads, ' +\n 'contacts and bookings have no landing page.'}\n </Alert>\n {landing.truncated ? (\n <Alert severity=\"warning\">\n {`More than ${LANDING_PAGE_CEILING.toLocaleString()} ` +\n 'credited submissions exist. This groups the ' +\n `${landing.read.toLocaleString()} that were read, ` +\n 'which are not the most recent — they are the ones ' +\n 'that came first in storage order.'}\n </Alert>\n ) : null}\n {landing.missing ? (\n <Alert severity=\"info\">\n {`${landing.missing.toLocaleString()} of the ` +\n `${landing.read.toLocaleString()} credited ` +\n 'submissions are not grouped: the submission has ' +\n 'been deleted, or it recorded no page. They are ' +\n 'reported here rather than filed under a page they ' +\n 'may not have come from.'}\n </Alert>\n ) : null}\n <ListTable\n rows={landing.rows}\n columns={landingColumns as any}\n hideFooter\n noRowsLabel=\"No pages to group\"\n noRowsDescription=\"None of the credited submissions recorded a page.\"\n />\n <Stack direction=\"row\" spacing={1}>\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={`${landing.read.toLocaleString()} credited submissions read`}\n />\n <Chip\n size=\"small\"\n variant=\"outlined\"\n label={`${landing.rows.length.toLocaleString()} pages`}\n />\n </Stack>\n </Stack>\n ) : null}\n </Section>\n </>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nCampaignConversionsCard.displayName = 'CampaignConversionsCard'\n\nexport default CampaignConversionsCard\n"],"names":["pluginDocsHelp","pluginRecordCountSource","PLUGIN_RECORD_LIST_IDS_MAX","pluginRecordListByIdsQuery","pluginRecordsFromRows","mdiEyeOutline","mdiMapMarkerOutline","AppLink","CardDisplay","MdiIcon","ListRowActions","ListTable","listActionsColumn","ListPagination","Figure","Section","Alert","Button","Chip","Divider","Stack","ToggleButton","ToggleButtonGroup","Typography","collection","getCountFromServer","getDocs","limit","orderBy","query","where","ListQueryNotices","useListColumnSort","useCallback","useEffect","useMemo","useState","useRouter","useFirestore","useOrgDataScope","usePagedCollection","ceilingedWindow","collectionCeiling","collectionPage","CAMPAIGN_CONVERSION_KINDS","CAMPAIGN_CONVERSION_KIND_COPY","CAMPAIGN_CONVERSION_SORTS","CAMPAIGN_CONVERSION_RECORD_KINDS","campaignConversionsCoverage","campaignTouchLabel","MarketingInsightsZone","LANDING_PAGE_CEILING","ID_CHUNK","SUBMISSION_RECORD_KIND","form","conversionsDocsHelp","anchor","excerpt","CONVERSION_PAGE_SORTS","campaign","row","CONVERSION_PAGE_SORT_HEADERS","day","ms","value","Number","isFinite","Date","toLocaleString","CampaignConversionsCard","props","hostId","basePath","campaignId","firestore","router","scope","dataScope","kind","setKind","attributions","emailSortAsked","setEmailSortAsked","webSortAsked","setWebSortAsked","orderedPage","base","sort","pageLimit","path","direction","emailList","idField","webList","emailSort","sorts","onSortChange","rows","pageSorts","headers","webSort","orgId","countSource","totalCrossesHosts","crossesSites","attributedCount","setAttributedCount","totalCount","setTotalCount","totalQuery","active","then","snapshot","data","count","catch","coverage","attributed","total","crossHostTotal","landingBusy","setLandingBusy","landingError","setLandingError","landing","setLanding","groupByLandingPage","credited","credits","truncated","docs","map","entry","refIds","Array","from","Set","record","String","refId","filter","id","length","paths","Map","index","named","ids","slice","found","records","$id","facts","trim","set","counts","missing","forEach","get","entries","conversions","a","b","localeCompare","read","error","console","campaignHref","undefined","columns","field","headerName","flex","minWidth","renderCell","sx","variant","noWrap","color","label","href","onClick","event","stopPropagation","width","convertedAtMs","items","key","icon","size","disabled","disabledReason","landingColumns","align","headerAlign","kindCopy","header","subheader","help","HeaderProps","action","spacing","subject","component","componentVariant","nativeButton","contentGutterX","contentGutterY","exclusive","onChange","_event","next","aria-label","one","severity","title","useFlexGap","flexWrap","note","unattributed","exact","caveats","caveat","message","refused","notices","hideFooter","columnSort","onOpen","_id","push","noRowsLabel","noRowsDescription","page","pageSize","rowCount","hasMore","onPageChange","setPage","onPageSizeChange","setPageSize","startIcon","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,eAAc;AAC7C,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SACEC,0BAA0B,EAC1BC,0BAA0B,EAC1BC,qBAAqB,QAChB,kDAAiD;AACxD,SAASC,aAAa,EAAEC,mBAAmB,QAAQ,yBAAwB;AAC3E,SAASC,OAAO,EAAEC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AACpE,SACEC,cAAc,EACdC,SAAS,EACTC,iBAAiB,QACZ,uDAAsD;AAC7D,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,MAAM,EAAEC,OAAO,QAAQ,6DAA4D;AAC5F,SACEC,KAAK,EACL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AChG,cAAc,GAAG,0BAA0B,CAAC;;8DAErE,KAAClD;oDACC2K,MAAK;oDACLb,SAAQ;oDACRG,OAAO,GAAGvD,QAAQ3B,IAAI,CAAC6C,MAAM,CAAC1E,cAAc,GAAG,MAAM,CAAC;;;;;qCAI1D;;;;qBAGN;;;;AAIZ;AACAC,wBAAwB6K,WAAW,GAAG;AAEtC,eAAe7K,wBAAuB"}
|
|
@@ -27,6 +27,7 @@ import { ListRowActions, ListTable, listActionsColumn } from "@aglyn/shared-ui-j
|
|
|
27
27
|
import { hiddenFilterVisibility } from "@aglyn/shared-ui-jsx/const/list-filter";
|
|
28
28
|
import { listFilterGridColumns } from "@aglyn/shared-ui-jsx/const/list-grid-filter";
|
|
29
29
|
import { useListGridFilter } from "@aglyn/shared-ui-jsx/hooks/use-list-grid-filter";
|
|
30
|
+
import { useListColumnSort } from "@aglyn/shared-ui-jsx/hooks/use-list-column-sort";
|
|
30
31
|
import RowActionsMenu from "@aglyn/shared-ui-jsx/components/row-actions-menu.component";
|
|
31
32
|
import { TABLE_ROW_HEIGHT } from "@aglyn/shared-ui-jsx/const/table-pagination";
|
|
32
33
|
import { ceilingedWindow } from "@aglyn/tenant-feature-instance/hooks/host-collection-queries";
|
|
@@ -82,6 +83,34 @@ const SEND_FILTER_HEADERS = {
|
|
|
82
83
|
status: 'Status',
|
|
83
84
|
createdAtMs: 'Created'
|
|
84
85
|
};
|
|
86
|
+
/*
|
|
87
|
+
* State is derived from the send's counters, and the counters stay absent
|
|
88
|
+
* until something is counted (see `campaign-list-query.ts`), so these sort
|
|
89
|
+
* the page (AGL-3680); Subject orders the query.
|
|
90
|
+
*/ const SEND_PAGE_SORTS = {
|
|
91
|
+
state: (send)=>campaignSendDisplay(send).label,
|
|
92
|
+
sent: (send)=>{
|
|
93
|
+
var _ref;
|
|
94
|
+
var _send_stats;
|
|
95
|
+
return (_ref = (_send_stats = send.stats) == null ? void 0 : _send_stats.sent) != null ? _ref : null;
|
|
96
|
+
},
|
|
97
|
+
opens: (send)=>{
|
|
98
|
+
var _ref;
|
|
99
|
+
var _send_stats;
|
|
100
|
+
return (_ref = (_send_stats = send.stats) == null ? void 0 : _send_stats.opens) != null ? _ref : null;
|
|
101
|
+
},
|
|
102
|
+
clicks: (send)=>{
|
|
103
|
+
var _ref;
|
|
104
|
+
var _send_stats;
|
|
105
|
+
return (_ref = (_send_stats = send.stats) == null ? void 0 : _send_stats.clicks) != null ? _ref : null;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const SEND_PAGE_SORT_HEADERS = {
|
|
109
|
+
state: 'State',
|
|
110
|
+
sent: 'Sent',
|
|
111
|
+
opens: 'Opens',
|
|
112
|
+
clicks: 'Clicks'
|
|
113
|
+
};
|
|
85
114
|
/**
|
|
86
115
|
* ONE CAMPAIGN: its lists, what it caused, what it earned, where it sent
|
|
87
116
|
* people, and the emails it did all of that with.
|
|
@@ -253,6 +282,8 @@ const SEND_FILTER_HEADERS = {
|
|
|
253
282
|
'status'
|
|
254
283
|
]
|
|
255
284
|
});
|
|
285
|
+
// Subject orders the query; State and the figures the page (AGL-3680).
|
|
286
|
+
const [askedSort, setAskedSort] = useState(null);
|
|
256
287
|
const sendPage = useListQuery({
|
|
257
288
|
collection: campaign ? campaignSendsCollection(firestore, orgId) : null,
|
|
258
289
|
declaration: CAMPAIGN_EMAILS_QUERY,
|
|
@@ -266,7 +297,8 @@ const SEND_FILTER_HEADERS = {
|
|
|
266
297
|
value: campaignId
|
|
267
298
|
},
|
|
268
299
|
...campaignSendsScope(hostId)
|
|
269
|
-
]
|
|
300
|
+
],
|
|
301
|
+
sort: askedSort
|
|
270
302
|
},
|
|
271
303
|
deps: [
|
|
272
304
|
firestore,
|
|
@@ -277,6 +309,15 @@ const SEND_FILTER_HEADERS = {
|
|
|
277
309
|
],
|
|
278
310
|
idField: '$id'
|
|
279
311
|
});
|
|
312
|
+
const sendSort = useListColumnSort({
|
|
313
|
+
sorts: CAMPAIGN_EMAILS_QUERY.sorts,
|
|
314
|
+
sort: askedSort,
|
|
315
|
+
onSortChange: setAskedSort,
|
|
316
|
+
orderBy: sendPage.plan.orderBy,
|
|
317
|
+
rows: sendPage.rows,
|
|
318
|
+
pageSorts: SEND_PAGE_SORTS,
|
|
319
|
+
headers: SEND_PAGE_SORT_HEADERS
|
|
320
|
+
});
|
|
280
321
|
// The ids the two sections beneath the figures join on. Derived from the
|
|
281
322
|
// window this card already holds, so neither of them reads the send list
|
|
282
323
|
// again to find out which emails the campaign has.
|
|
@@ -907,11 +948,14 @@ const SEND_FILTER_HEADERS = {
|
|
|
907
948
|
headers: SEND_FILTER_HEADERS,
|
|
908
949
|
options: SEND_FILTER_OPTIONS
|
|
909
950
|
}),
|
|
910
|
-
notices:
|
|
951
|
+
notices: [
|
|
952
|
+
...sendPage.plan.notices,
|
|
953
|
+
...sendSort.notices
|
|
954
|
+
]
|
|
911
955
|
}),
|
|
912
956
|
/*#__PURE__*/ _jsx(ListTable, {
|
|
913
957
|
"aria-label": "The campaign's emails",
|
|
914
|
-
rows:
|
|
958
|
+
rows: sendSort.rows,
|
|
915
959
|
columns: listFilterGridColumns(sendColumns, SEND_FILTER_FIELDS, SEND_FILTER_OPTIONS, SEND_FILTER_HEADERS),
|
|
916
960
|
rowHeight: TABLE_ROW_HEIGHT,
|
|
917
961
|
onOpen: (_id, send)=>{
|
|
@@ -922,12 +966,13 @@ const SEND_FILTER_HEADERS = {
|
|
|
922
966
|
/*
|
|
923
967
|
* The panel and the search are the grid's; every clause and the
|
|
924
968
|
* search word are on the table's query (AGL-3321), and the grid
|
|
925
|
-
* neither filters nor sorts the page it is handed
|
|
969
|
+
* neither filters nor sorts the page it is handed: Subject
|
|
970
|
+
* orders the query, State and the figures the page (AGL-3680).
|
|
926
971
|
*/ filterMode: "server",
|
|
927
972
|
filterModel: gridFilter.filterModel,
|
|
928
973
|
onFilterModelChange: gridFilter.onFilterModelChange,
|
|
929
974
|
quickFilter: true,
|
|
930
|
-
|
|
975
|
+
columnSort: sendSort,
|
|
931
976
|
hideFooter: true,
|
|
932
977
|
initialState: {
|
|
933
978
|
columns: {
|