Repository navigation
Description
What
Add a Export CSV button to the top-right of the Answer Engine
Insights page header, next to the existing action buttons. Clicking it
downloads the currently-filtered prompt results as a CSV file the user
can open in Excel / Google Sheets / a BI tool.
This is the first of several export endpoints we're rolling out — start
with this one. Citations / AI Traffic / etc. will come as separate
issues.
Why
Marketers and analysts regularly want to pivot, filter, or chart the
raw result data outside the dashboard. Right now their only option is
to take screenshots or read individual rows in the UI. A one-click CSV
export turns "I want to play with this data" into a 5-second
operation.
Where the button goes
The header lives at:
web/src/app/[locale]/(dashboard)/dashboard/insights/page.tsx
around line 1714 — the<div className="flex items-start justify-between gap-4">wrapping the title + action buttons.
Two things to handle:
- The right-side action cluster currently renders only when
!isCloud(line 1723). Move it (or duplicate the wrapping div)
so the Export button is always visible while Test Single
Prompt / Run All stay self-host-only. - The button itself uses the existing
Buttoncomponent from
@/components/ui/button,variant="outline", with a Download icon
fromlucide-react(import { Download } from "lucide-react";).
Match the style of the other buttons in that cluster.
What to export
The page already loads PromptResultWithText[] into the results
state (look for getPromptResults in page.tsx). Export exactly
what's currently loaded — that means the active filters
automatically apply (date range, model, region, topic) because the
data was already fetched with those filters.
Each row in the CSV should have these columns (flattened):
| Column | Source |
|---|---|
created_at |
r.createdAt (ISO string) |
prompt |
r.promptText |
topic |
r.topicName ?? "" |
platform |
r.platform |
model |
r.modelUsed ?? "" |
region |
r.region ?? "" |
mention_count |
r.mentionCount |
citation_count |
r.citationCount |
visibility_score |
r.visibilityScore |
sentiment |
r.sentiment |
citation_urls |
`r.citations.map(c => c.url).join(" |
competitor_mentions |
r.competitorMentions?.map(c => \${c.name}:${c.mention_count}`).join(" |
Do not include the full response text — it's long, often
multi-paragraph, and breaks CSV parsers. Citations and competitor
mentions get flattened to pipe-separated strings (CSV-safe).
CSV building
A tiny helper is enough — no library needed. Create something like
web/src/lib/csv.ts:
function escape(value: unknown): string {
if (value === null || value === undefined) return "";
const s = String(value);
// Wrap in quotes if it contains comma, quote, or newline.
if (/[",\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
return s;
}
export function toCsv(rows: Record<string, unknown>[], headers: string[]): string {
const headerLine = headers.join(",");
const dataLines = rows.map((row) =>
headers.map((h) => escape(row[h])).join(","),
);
return [headerLine, ...dataLines].join("\n");
}In the page, when the button is clicked, build the rows in the
shape above and trigger a download:
const csv = toCsv(rowsForExport, headerArray);
const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `ansvisor_${brand.slug}_results_${new Date().toISOString().slice(0, 10)}.csv`;
a.click();
URL.revokeObjectURL(url);File naming convention: ansvisor_<brand-slug>_results_<YYYY-MM-DD>.csv.
Disabled state
The button should be disabled when:
results.length === 0(nothing to export)- The page is still loading (
isLoading === true)
Show a subtle tooltip on hover when disabled — something like "No
results in the current filter — adjust filters or run a tracking
job".
How to verify
- Navigate to
/dashboard/insightswith a brand that has tracked
results → Export button is visible top-right - Click → file downloads with the correct name pattern
- Open the CSV in Excel / Google Sheets → columns line up, no
extra quotes, no broken rows - Apply a date filter (e.g. last 7 days) → re-export → file only
contains rows within that range - Same for region / model filters
- Brand with zero results → button is disabled with tooltip
- Cloud and self-host modes both show the button (only Test
Single Prompt / Run All stay self-host-only)
Out of scope
Don't include in this PR:
- Excel format (CSV only for now)
- Async / background export
- Other datasets (Citations, AI Traffic, etc. — coming as separate
issues) - Plan gating / rate limiting (cap is handled implicitly by the
existingPROMPT_RESULTS_ROW_LIMIT) - Adding the helper to MCP / REST API
Contribution guide
See CONTRIBUTING.md for branch naming, commit
conventions, and PR workflow.
Activity
gkhngyk commentedon May 21, 2026
@sourabh-31 Would you like to work on this issue?
sourabh-31 commentedon May 21, 2026
Hey @gkhngyk, I started looking into this issue, but I’m currently hitting a blocker on the Insights page.
Right now the page is showing the empty state (“No tracking data yet”), and when I click “Run Prompt Now”, it finishes with “analysis complete - 0 results saved”. Because of that, I don’t have any prompt result data available to test/export against.
Am I missing a setup step or seed data for this flow? Would appreciate some guidance on how to get actual results populated so I can work on the CSV export properly.
gkhngyk commentedon May 21, 2026
Hey @sourabh-31 — quick note before the answer: this is a real gap in our contributor setup, not something you did wrong. The fact that you can't just
pnpm devand see a populated dashboard is friction on us, and we're sorry it slowed you down. Seed data is something we're actively working on (going to open a separate issue for it shortly so it's tracked publicly).Now to your specific question — a few things to clear up:
The cloud trial doesn't help here
The trial you start on
app.ansvisor.comlives in our production Supabase, which is a completely separate database from the one your local instance points to. Auth, organizations, subscriptions, brands, prompt results — none of it is shared. So there's no way (and you wouldn't want) to bridge them.You don't actually need a subscription locally
When
IS_CLOUDis unset (the default for self-host / local dev), the plan resolver returns the unlimitedself_hostedplan and skips the subscription check entirely. So plan gating is not what's blocking you.Why "Run Prompt Now" returns 0 results
The tracking pipeline needs:
OPENAI_API_KEY/ANTHROPIC_API_KEY/GOOGLE_GENERATIVE_AI_API_KEYinserver/.envfor the direct-API providersCLORO_API_KEY+CLORO_WEBHOOK_URLfor the scraper-backed providers (ChatGPT / Claude / Perplexity / Gemini web UIs)Cloro is a paid third-party service, which is exactly the kind of thing a contributor shouldn't have to sign up for to ship a UI feature. This is the gap I mentioned above.
Unblocker for this PR specifically
For the CSV export you actually don't need real tracked data — you just need some rows in
prompt_resultsto drive the UI. The fastest path: open Supabase Studio against your local instance and insert ~10 rows directly intoprompt_resultswith realistic values (you can crib the column shape fromweb/src/lib/actions/insights.ts— look forPromptResultWithText). That's enough to iterate on the button, the disabled state, the CSV output, and the file naming.Once seed data lands you'll be able to skip that step entirely. In the meantime, sorry for the extra mile. Ping back when you've got a draft and I'll review.
sourabh-31 commentedon May 21, 2026
@gkhngyk a PR has been created regarding this feature. Kindly take a look at it when you get time.