Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(onboarding): align prompts to selected plan's engine set on Stripe success (#111)

Gökhan Geyik16dbc8696d9b
diff --git a/web/src/app/api/stripe/success/route.ts b/web/src/app/api/stripe/success/route.ts
index 51e57c4d7..92d22f7c9 100644
--- a/web/src/app/api/stripe/success/route.ts
+++ b/web/src/app/api/stripe/success/route.ts
@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from 'next/server';
import { stripe } from '@/lib/stripe';
import { supabaseAdmin } from '@/lib/supabase/admin';
+import { getActiveEngineIdsForPlan } from '@/lib/plan-engines';
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url);
@@ -50,6 +51,57 @@ export async function GET(req: NextRequest) {
} else {
console.log('[stripe/success] DB updated for org:', orgId);
+ // Align onboarding-created prompts to the just-confirmed plan's
+ // engine set. Onboarding saves prompts at step 4 with whatever
+ // engines the *current* (pre-checkout, default Starter) plan
+ // allows — 2 scrapers. Without this, a user who picks Growth at
+ // step 6 still ends up tracking only those 2 engines instead of
+ // the 8 Growth allows. Issue #78.
+ //
+ // This runs only on the initial checkout-success redirect (i.e.
+ // onboarding's plan step). Plan changes / upgrades for existing
+ // orgs flow through the Stripe subscription update path and are
+ // tracked separately.
+ try {
+ const { platforms, models } = getActiveEngineIdsForPlan(planId || 'starter');
+
+ const { data: orgBrands } = await supabaseAdmin
+ .from('brands')
+ .select('id')
+ .eq('organization_id', orgId);
+
+ const brandIds = (orgBrands ?? []).map((b) => b.id);
+
+ if (brandIds.length > 0) {
+ const { data: promptSets } = await supabaseAdmin
+ .from('prompt_sets')
+ .select('id')
+ .in('brand_id', brandIds);
+
+ const promptSetIds = (promptSets ?? []).map((p) => p.id);
+
+ if (promptSetIds.length > 0) {
+ const { error: alignError } = await supabaseAdmin
+ .from('prompts')
+ .update({ platforms, models })
+ .in('prompt_set_id', promptSetIds);
+
+ if (alignError) {
+ console.error(
+ '[stripe/success] Failed to align prompts to plan engines:',
+ alignError,
+ );
+ } else {
+ console.log(
+ `[stripe/success] Aligned prompts to plan=${planId || 'starter'} engines (${platforms.length} scrapers, ${models.length} models) for org ${orgId}`,
+ );
+ }
+ }
+ }
+ } catch (alignErr) {
+ console.error('[stripe/success] Plan-engine alignment threw:', alignErr);
+ }
+
// Find first brand and trigger tracking via aeo-server
const { data: brand } = await supabaseAdmin
.from('brands')
diff --git a/web/src/lib/plan-engines.ts b/web/src/lib/plan-engines.ts
new file mode 100644
index 000000000..928d39374
--- /dev/null
+++ b/web/src/lib/plan-engines.ts
@@ -0,0 +1,36 @@
+import { getPlan, type PlanId } from '@/config/plans';
+import { ALL_MODELS, ALL_SCRAPERS } from '@/config/prompt-options';
+
+/**
+ * Resolve the scraper + model id sets a plan currently allows.
+ *
+ * Mirrors the gating logic in the onboarding wizard
+ * (`(onboarding)/dashboard/onboarding/page.tsx`): if `allowedScrapers` /
+ * `allowedModels` is **absent** on the plan, every engine / model is allowed
+ * (Growth, Enterprise, Self-hosted). If it's an **array** — even an empty
+ * one — only the listed ids are allowed (Starter ships
+ * `allowedScrapers: ['chatgpt-web', 'perplexity-web']` and
+ * `allowedModels: []`).
+ *
+ * Used by the Stripe success route to align onboarding-created prompts to
+ * the plan the user actually picks at step 6 — without this, a Growth
+ * trial-er ends up tracking only the 2 Starter engines (issue #78).
+ */
+export function getActiveEngineIdsForPlan(planId: PlanId | string | null | undefined): {
+ platforms: string[];
+ models: string[];
+} {
+ const plan = getPlan((planId ?? 'starter') as PlanId);
+
+ const allowedScrapers = plan.limits.allowedScrapers;
+ const platforms = allowedScrapers
+ ? ALL_SCRAPERS.filter((s) => allowedScrapers.includes(s.id)).map((s) => s.id)
+ : ALL_SCRAPERS.map((s) => s.id);
+
+ const allowedModels = plan.limits.allowedModels;
+ const models = allowedModels
+ ? ALL_MODELS.filter((m) => allowedModels.includes(m.id)).map((m) => m.id)
+ : ALL_MODELS.map((m) => m.id);
+
+ return { platforms, models };
+}