Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Problem
After onboarding, a new user's prompts start tracking automatically once payment completes — but volume & competition data still requires them to find the Prompts page and click Analyze prompts manually. Most new users don't discover this, so the Volume/Competition columns sit empty.
Proposal
Kick off the volume analysis automatically right after checkout, reusing the exact pattern the post-payment flow already uses for tracking.
Current post-payment flow (web/src/app/api/stripe/success/route.ts): validate session → update org subscription → alignPromptsToPlanForOrg → call Express POST /api/internal/trigger-tracking with CRON_SECRET auth.
Changes:
- Extract the analysis core into a shared lib function. Pull the per-prompt loop out of
POST /api/volumes/analyze-batch(server/src/routes/volumes.js) — intent/keyword extraction (extractIntentKeywords) + DataForSEO fetch (fetchAndSaveVolumes), reusing saved keywords when present — so the manual button and the auto-run share one implementation. - New internal endpoint
POST /api/internal/analyze-volumes(CRON_SECRETbearer auth, alongside the existing/api/internal/*endpoints). Body:{ brandId }. It must respond immediately (202) and process in the background — analyzing ~50 prompts takes minutes and must never block the caller. Results land inprompt_volumesas they complete, so the Prompts page fills in on its own. - Fire-and-forget call from the Stripe success route, right after the
trigger-trackingcall. Any failure is logged and never affects the checkout redirect. (Optionally mirror in thecheckout.session.completedwebhook branch for checkouts that never hit the redirect — must be idempotent if both fire.)
Free of charge — does not consume quota:
- The automatic onboarding run does not count against the plan's
maxVolumeAnalysesquota: skip thevolume_usageinsert for this internal run. It's a one-time welcome analysis; the user keeps their full monthly manual-analysis budget.
Idempotency / safety:
- The existing analyze logic already reuses saved keywords (LLM is only called for prompts without them), so a later manual Analyze click just refreshes volumes — no double LLM spend.
- If the brand already has volume rows (e.g. retriggered success URL), the run is a cheap refresh; guard with an "already analyzed recently" check if needed.
- DataForSEO/LLM errors are caught per prompt (as in the batch route) and logged; partial results are fine.
Scope:
- Cloud post-payment flow only. Self-host has no payment step (tracking starts at onboarding finish) — out of scope here; the
analyzePromptVolumeenv checks already no-op when DataForSEO credentials are absent. - The additional-brand wizard (Dashboard → Brands → New) has the same manual step — candidate for a follow-up using the same shared function.
Acceptance criteria
- Completing checkout results in volume & competition data appearing on the Prompts page within a few minutes, with no manual action.
volume_usageis not incremented by the automatic run; the manual Analyze button and its quota behave exactly as before.- A DataForSEO or LLM outage during the auto-run never affects the checkout redirect or tracking kickoff.
cd server && yarn testpasses; the shared function is covered by the existing batch-route behavior.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
BharadwajKanneveti commentedon Jul 31, 2026
Hi @gkhngyk can I work on this issue?
gkhngyk commentedon Aug 1, 2026
Assigned to you — thanks for picking this up! 🙌
BharadwajKanneveti commentedon Aug 2, 2026
Hi @gkhngyk , I extracted the shared analysis logic into analyzeBrandVolumes(). For the new /api/internal/analyze-volumes endpoint, should it use the existing job infrastructure (similar to tracking) with a new volume job type/worker, or is it acceptable to detach analyzeBrandVolumes() from the request and return 202 immediately without creating a job?
gkhngyk commentedon Aug 2, 2026
Option (b) is fine — detach and return 202. That's the existing pattern for post-run background work (Daily Pulse and opportunity generation are both fire-and-forget with a
.catchlog), and the manual Analyze button remains as the fallback if it fails. Just make sure errors are logged and the endpoint is idempotent so a duplicate call doesn't double-analyze. No new job type needed.