Repository navigation
feat(ai-traffic): AI-sourced contacts, deals and revenue from HubSpot by engine and page (00520) - #2266
Merged
Conversation
… 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
# Conflicts: # supabase/schema.sql
gkhngyk
requested changes
Nov 10, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Nothing clears hubspot_ai_contacts / hubspot_ai_deals when the brand switches HubSpot account or disconnects (only a successful sync prunes them), so until a sync of the new account succeeds, or forever if it keeps failing, AI Traffic shows the old account's contacts, deals and revenue as the new one's. Please delete the brand's rows in both tables on account change and on disconnect.
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
cihan-gyk
pushed a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 10, 2026
…t-section Brings in upstream/main (the Slack PRs) through ansvisor#2266's branch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
This was referenced Nov 10, 2026
…pipeline # Conflicts: # supabase/schema.sql
…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
pushed a commit
that referenced
this pull request
Nov 10, 2026
…ir PDF HubSpot, part 3 of #2140 (stacked on #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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #2265 (
feature/hubspot-connect). Merge that first; until then this diff also shows its commits. This is HubSpot part 2 of #2140: the AI-sourced pipeline section on the AI Traffic page, as the owner approved it on 2026-11-10 (the mockup's screen 5, and the decisions on revenue and HubSpot's own AI Referrals).What a person sees on AI Traffic: a new section after "Where AI visitors convert", with:
Its states:
The HubSpot card now says when HubSpot was last read ("Read from HubSpot 2 hours ago: 42 AI-sourced contacts, 7 deals."), with Sync now for admins and managers.
Counting (owner, 2026-11-10)
amount_in_home_currency, elseamount).How it works
supabase/schema.sqlrebuilt):hubspot_ai_contactsandhubspot_ai_dealshold HubSpot ids, AI source, landing page (with its page key), amounts, stages and dates. Never a name or an email.user_brand_ids()); only the server writes them.brand_ai_pipeline(brand, since, until)returns the section as one jsonb.public.can_access_brand(p_brand_id)holds or the caller is the service role.brand_integrations.settings.lib/hubspot/pipeline-sync.jsreads HubSpot once a day (fromrunDailyTracking), and on Sync now (POST /api/hubspot/brands/:brandId/sync). Sync now runs in the background, answers 202, and runs at most once every 5 minutes per brand.crm_integrations, and an active brand that isn't the demo. It never writes to HubSpot.ansvisor_brand_id, paged past the last id, so it goes beyond HubSpot's 10,000 search results, up to 50,000;hs_analytics_source = AI_REFERRALScontacts from the last 400 days whose first page is on the brand's domains. An account that refuses that filter just has none.brand_integrations.settings.sync. If HubSpot refuses the sign-in, the connection is marked for reconnecting.getTrafficAiPipelineis one more AI Traffic read (/api/traffic/read, readaiPipeline).traffic/_ai-pipeline.tsx, gated oncrm_integrations.web/messages/en.json.SKIPPEDinlib/demo/coverage.js, and the section says HubSpot isn't connected.help/ai-traffic/ai-sourced-pipeline.md(plan: growth,approved: false).help/settings/hubspot.mdnow mentions Sync now.Notes
server/src/lib/hubspot/__fixtures__) follow HubSpot's API reference, with ids replaced. Replace them with recorded answers.AI_REFERRALSfor HubSpot's AI Referrals source isn't confirmed yet; check it on the test portal. A different value only leaves that line empty, because a refused filter is skipped.Related issue
Part of #2140
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/hubspot src/routes/hubspot.test.js src/lib/demo/coverage.test.js src/middleware/demo-brand.test.jscd web && yarn vitest run "src/app/[locale]/(dashboard)/dashboard/traffic/_ai-pipeline.test.tsx" src/components/settings/hubspot-card.test.tsx src/lib/hubspot-client.test.ts src/app/api/traffic/read00520_hubspot_ai_pipeline.sqlon a dev database. As a member of the brand,select brand_ai_pipeline('<brand>', current_date - 30, current_date - 1);gives the section. A member without access to the brand gets null.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) — 0 errors; 9 warnings, all in files this PR doesn't touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)help/(or no user-visible change) — see help/README.mdChecks run on 723ff72, after merging
upstream/main(Slack #2259, MCP OAuth) through #2265's branch:npm run format:checkandnpm run lintpass.npm test: 451 files, 6211 passed, 4 skipped.yarn format:check,yarn lint(0 errors) andyarn typecheckpass.yarn test: 1,065 files, 11,664 passed, 1 skipped. This includesbrand-access-functions.test.ts, which checks thatbrand_ai_pipelineaskscan_access_brand.yarn build(CI's placeholder env) passes.bash supabase/build-schema.sh:schema.sqlis up to date in this commit.The branch merges cleanly into current
main. If #2263 (Slack, 00515) merges first,schema.sqlwill need rebuilding here.Generated by Claude Code