Skip to content

Auto-run prompt volume analysis after checkout — drop the manual Analyze step for new users #541

Closed

Description

@gkhngyk

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:

  1. 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.
  2. New internal endpoint POST /api/internal/analyze-volumes (CRON_SECRET bearer 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 in prompt_volumes as they complete, so the Prompts page fills in on its own.
  3. Fire-and-forget call from the Stripe success route, right after the trigger-tracking call. Any failure is logged and never affects the checkout redirect. (Optionally mirror in the checkout.session.completed webhook 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 maxVolumeAnalyses quota: skip the volume_usage insert 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 analyzePromptVolume env 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_usage is 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 test passes; the shared function is covered by the existing batch-route behavior.

Activity

  1. added
    enhancement
    on Jul 28, 2026
  2. BharadwajKanneveti commented on Jul 31, 2026

    @BharadwajKanneveti
    Contributor

    Hi @gkhngyk can I work on this issue?

  3. gkhngyk commented on Aug 1, 2026

    @gkhngyk
    ContributorAuthor

    Assigned to you — thanks for picking this up! 🙌

  4. BharadwajKanneveti commented on Aug 2, 2026

    @BharadwajKanneveti
    Contributor

    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?

  5. gkhngyk commented on Aug 2, 2026

    @gkhngyk
    ContributorAuthor

    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 .catch log), 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions