Skip to content

feat(reports): add the AI-sourced pipeline section to reports and their PDF - #2270

Merged
gkhngyk merged 10 commits into
ansvisor:mainfrom
cihan-gyk:feature/hubspot-report-section
Nov 10, 2026
Merged

gkhngyk merged 10 commits into
ansvisor:mainfrom
cihan-gyk:feature/hubspot-report-section

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #2266 (AI-sourced pipeline in AI Traffic), which is stacked on #2265 (HubSpot connection). Merge after #2266; until then this diff also shows theirs.

HubSpot, part 3 of #2140: a report can include HubSpot's AI-sourced contacts, deals and revenue for its period, as the owner approved in the mockup's Reports screen.

What a person sees

  • The New report dialog:
    • a new section, AI-sourced pipeline, after AI Traffic;
    • on by default in the Monthly Executive Report, like every section;
    • below Growth it shows off, with a "Growth" badge, and can't be picked.
  • The report page: an AI-sourced pipeline card ("From HubSpot") with:
    • four KPIs: AI-sourced contacts and won revenue (each with its % against the previous period), AI-influenced deals, and open pipeline;
    • the top 5 AI engines (contacts and won revenue) and the top 5 landing pages by won revenue;
    • HubSpot's own AI Referrals contacts on a line of their own;
    • the counting rule.
  • The PDF: the same section, "AI-sourced pipeline (HubSpot)".

How it works

  • lib/reports/templates.ts: aiPipeline joins ReportSection, ALL_REPORT_SECTIONS and the executive summary template.
  • lib/actions/reports.ts:
    • Gating: the section is dropped unless the brand's organization has crm_integrations (getOrgPlan), as the shopping section is dropped without Shopping mode.
    • Gathering: it calls AI Traffic's getTrafficAiPipeline (brand_ai_pipeline, 00520) for the report's dates.
    • No data: a brand with HubSpot not connected, marking contacts off, or not read yet gets no section, and it isn't listed as missing.
    • Stored data: the payload keeps the totals, the top 5 engines and pages, HubSpot's own AI Referrals, and when HubSpot was last read. Saved reports are frozen, as before.
  • lib/format.ts gains formatMoney (whole amounts in the HubSpot account's currency) and percentChange. The AI Traffic section's money now uses formatMoney.
  • Help: help/reports/visibility-reports.md names the section, and has a short "AI-sourced pipeline" part. That article is approved, so approved-articles.json was regenerated (yarn test -u src/lib/help).

Not in this PR

  • A "Connect HubSpot to include it" line in the dialog. The dialog doesn't read the brand's HubSpot connection. A brand without HubSpot simply gets no section, and the report isn't marked as missing anything.
  • Live data until contact marking ships: before contact marking (PR 2, waiting for the HubSpot spike) ships, the main figures are zero, and only HubSpot's own AI Referrals line has data.
  • Live test with Gökhan: generate a report for a brand with HubSpot connected and read, then check the card and the PDF.

Related issue

Part of #2140

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd web && yarn vitest run "src/app/[locale]/(dashboard)/dashboard/reports" src/lib/format.test.ts "src/app/[locale]/(dashboard)/dashboard/traffic/_ai-pipeline.test.tsx" src/lib/help. In particular:
    • reports/page.test.tsx: the section can be picked on Growth, and is off with "Growth" below it;
    • reports/[id]/page.test.tsx: the card's KPIs, engines, pages and the AI Referrals line, and no card on a report without it;
    • _report-pdf.render.test.tsx: the PDF prints the section.
  2. Live, with HubSpot connected for a Growth brand and read once (Sync now on its card):
    • Generate a Monthly Executive Report. It has the AI-sourced pipeline card, and its PDF has the section.
    • A brand without HubSpot gets a report without the card, and without a "missing sections" note.
    • On Starter, the section shows off with "Growth".

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — 0 errors; 9 warnings, all in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — see help/README.md

Checks run on bc439c9 (web only, since the server is unchanged):

  • yarn format:check, yarn lint (0 errors) and yarn typecheck pass.
  • yarn test: 1,065 files, 11,670 passed, 1 skipped.
  • yarn build (CI's placeholder env) passes.

After merging main (the Slack PRs, through #2265's and #2266's branches): the reports, format and Help tests pass again (7 files, 46 tests), and the branch merges cleanly into current main.


Generated by Claude Code

… by engine and page

HubSpot, part 2 of ansvisor#2140 (stacked on the HubSpot connection): AI Traffic
gets an "AI-sourced pipeline" section after "Where AI visitors convert".

- 00520: hubspot_ai_contacts and hubspot_ai_deals, the brand's AI-sourced
  HubSpot contacts and their deals (HubSpot ids, AI source, landing page,
  amounts and dates; never a name or an email), read by the brand's
  members. brand_ai_pipeline(brand, since, until) answers the section,
  checking can_access_brand.
- A daily read of each brand's HubSpot (lib/hubspot/pipeline-sync.js), and
  Sync now on the HubSpot card: the contacts Ansvisor marked for the brand,
  and HubSpot's own AI Referrals contacts on the brand's domains as a line
  of their own; their deals, each once, in full, credited to the earliest
  AI contact (Ansvisor's first). Read-only on HubSpot, with consent to mark
  contacts, a live sign-in and the plan's crm_integrations.
- Won revenue by close date, open pipeline now and unweighted, in the
  HubSpot account's currency (owner, 2026-11-10).
- The section: four KPIs against the period before, by AI engine, by
  landing page, and its states (locked below Growth, not connected,
  marking contacts off, first read, nothing yet).
- The HubSpot card says when HubSpot was last read, with Sync now.
- The demo brand connects no HubSpot account: both tables are skipped in
  the demo's coverage.
- Help: ai-traffic/ai-sourced-pipeline (approved: false); settings/hubspot
  mentions Sync now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
The Supabase types gain the pipeline's RPC and its two tables (00520), so
the AI Traffic read typechecks; the section's test is formatted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…ir PDF

HubSpot, part 3 of ansvisor#2140 (stacked on ansvisor#2266): a report can carry HubSpot's
AI-sourced contacts, deals and revenue for its period, as AI Traffic shows
them.

- A new section, "AI-sourced pipeline", in the picker and in the Monthly
  Executive Report's defaults. It needs the plan's crm_integrations: below
  Growth it shows off, with the plan it needs, and the server leaves it out.
- Gathered with brand_ai_pipeline (00520) for the report's dates; a brand
  that hasn't connected HubSpot with consent to mark contacts, or whose
  HubSpot hasn't been read yet, gets no such section (not a missing one).
- The report page and its PDF show the four KPIs (contacts and won revenue
  against the previous period), the top 5 engines and landing pages, and
  HubSpot's own AI Referrals on a line of their own.
- formatMoney and percentChange join lib/format, and AI Traffic's section
  uses formatMoney.
- Help: reports/visibility-reports names the section (approved copy
  regenerated).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Brings in upstream/main through ansvisor#2265's branch (the Slack PRs).
schema.sql is rebuilt with 00510, 00515 and 00520.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 10, 2026
gkhngyk
gkhngyk previously approved these changes Nov 10, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 10, 2026 11:49

The merge-base changed after approval.

…hanges account or disconnects

Only a successful sync pruned hubspot_ai_contacts and hubspot_ai_deals, so
after a brand moved to another HubSpot account AI Traffic showed the old
account's contacts, deals and revenue as the new one's until a sync of it
succeeded, or forever when it kept failing. The brand's rows now go where
its other sign-in reads go (brand-integrations.js): when it uses another
account, activates a new login of its own, or disconnects. A sync still
reading the old account when that happens writes nothing (account_changed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
gkhngyk
gkhngyk previously approved these changes Nov 10, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 10, 2026 20:23

The merge-base changed after approval.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit 26bcce4 into ansvisor:main Nov 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants