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.

feat(analytics): identify users universally + instrument onboarding funnel (#30)

Gökhan Geyikb80f9e87e380
diff --git a/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx b/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx
index e661fd227..07feddc90 100644
--- a/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx
+++ b/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx
@@ -13,7 +13,16 @@ import { useBrandStore } from '@/stores/use-brand-store';
import { REGIONS, LANGUAGES } from '@/config/prompt-options';
import { ALL_MODELS, ALL_SCRAPERS } from '@/config/prompt-options';
import { isCloud, PLANS, SUBSCRIBABLE_PLANS, getPlan, type PlanId } from '@/config/plans';
-import { track } from '@/lib/analytics';
+import { setPersonProperties, track } from '@/lib/analytics';
+
+const ONBOARDING_STEP_NAMES: Record<number, string> = {
+ 1: 'brand_setup',
+ 2: 'brand_details',
+ 3: 'topics',
+ 4: 'prompts',
+ 5: 'competitors',
+ 6: 'plan',
+};
import type { Brand } from '@/types';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
@@ -460,6 +469,16 @@ export default function OnboardingPage() {
checkResume();
}, [router, addBrand, setActiveBrand]);
+ // Fire `onboarding_step_viewed` whenever the wizard advances (or resumes).
+ // This is the funnel surface — PostHog will compute drop-off between any
+ // two adjacent step_viewed events without us needing per-step columns.
+ useEffect(() => {
+ const stepName = ONBOARDING_STEP_NAMES[step];
+ if (stepName) {
+ track('onboarding_step_viewed', { step, step_name: stepName });
+ }
+ }, [step]);
+
const domain = website
.replace(/^https?:\/\//, '')
.replace(/\/.*$/, '')
@@ -541,6 +560,16 @@ export default function OnboardingPage() {
addBrand(brand);
setActiveBrand(brand.id);
track('onboarding_brand_created', { region: brand.region });
+ track('onboarding_step_completed', {
+ step: 2,
+ step_name: 'brand_details',
+ region: brand.region,
+ language: brand.language,
+ });
+ setPersonProperties({
+ region: brand.region,
+ language: brand.language,
+ });
}
setStep(3);
@@ -666,6 +695,11 @@ export default function OnboardingPage() {
}),
),
);
+ track('onboarding_step_completed', {
+ step: 3,
+ step_name: 'topics',
+ topic_count: selectedTopics.size,
+ });
setStep(4);
} catch (err) {
console.error('Prompt generation error:', err);
@@ -703,6 +737,12 @@ export default function OnboardingPage() {
prompts: allPrompts,
});
track('onboarding_prompts_saved', { count: allPrompts.length });
+ track('onboarding_step_completed', {
+ step: 4,
+ step_name: 'prompts',
+ prompt_count: allPrompts.length,
+ topic_count: topicPrompts.length,
+ });
setStep(5);
fetchCompetitorSuggestions();
@@ -810,6 +850,16 @@ export default function OnboardingPage() {
.eq('id', user.id);
}
+ const competitorCount = selected.length;
+ track('onboarding_step_completed', {
+ step: 5,
+ step_name: 'competitors',
+ competitor_count: competitorCount,
+ });
+ setPersonProperties({
+ onboarding_completed: true,
+ });
+
// Cloud mode → proceed to subscription step (tracking triggered after payment)
if (isCloud()) {
toast.success('Almost done! Choose a plan to start your free trial.');
@@ -818,6 +868,8 @@ export default function OnboardingPage() {
return;
}
+ track('onboarding_finished', { paid: false });
+
// Self-hosted: trigger tracking immediately
try {
const { jobId } = await triggerTrackingCheck(createdBrand.id);
@@ -851,6 +903,15 @@ export default function OnboardingPage() {
const handleCheckout = async (planId: PlanId) => {
if (!organizationId) return;
setCheckoutLoading(planId);
+ track('onboarding_step_completed', {
+ step: 6,
+ step_name: 'plan',
+ plan_id: planId,
+ });
+ track('onboarding_plan_selected', { plan_id: planId });
+ setPersonProperties({
+ intended_plan: planId,
+ });
try {
const res = await fetch('/api/stripe/checkout', {
method: 'POST',
@@ -975,7 +1036,19 @@ export default function OnboardingPage() {
<Button
className="w-full"
disabled={!brandName.trim() || !website.trim()}
- onClick={() => setStep(2)}
+ onClick={() => {
+ track('onboarding_step_completed', {
+ step: 1,
+ step_name: 'brand_setup',
+ brand_name: brandName.trim(),
+ brand_domain: domain,
+ has_description: description.trim().length > 0,
+ });
+ setPersonProperties({
+ company_url: domain,
+ });
+ setStep(2);
+ }}
>
Continue
</Button>
diff --git a/web/src/components/auth/sign-in-form.tsx b/web/src/components/auth/sign-in-form.tsx
index 88312667d..260fb7374 100644
--- a/web/src/components/auth/sign-in-form.tsx
+++ b/web/src/components/auth/sign-in-form.tsx
@@ -12,7 +12,7 @@ import { toast } from "sonner";
import { Loader2 } from "lucide-react";
import { OAuthButtons } from "@/components/auth/oauth-buttons";
import { Separator } from "@/components/ui/separator";
-import { identify, track } from "@/lib/analytics";
+import { track } from "@/lib/analytics";
export function SignInForm() {
const t = useTranslations("auth");
@@ -47,9 +47,8 @@ export function SignInForm() {
return;
}
- if (data.user) {
- identify(data.user.id, { email: data.user.email });
- }
+ // identify() runs centrally in AuthProvider on the SIGNED_IN auth event,
+ // so the form just needs to capture the funnel event.
track("signin_completed", { source: "email" });
router.push(nextPath && nextPath.startsWith("/") ? nextPath : "/dashboard");
diff --git a/web/src/components/providers/auth-provider.tsx b/web/src/components/providers/auth-provider.tsx
index c282a3a39..0a6bf1bcd 100644
--- a/web/src/components/providers/auth-provider.tsx
+++ b/web/src/components/providers/auth-provider.tsx
@@ -3,6 +3,8 @@
import { useEffect } from "react";
import type { User } from "@supabase/supabase-js";
import { useAuthStore } from "@/stores/use-auth-store";
+import { createClient } from "@/lib/supabase/client";
+import { identify, reset as resetAnalytics } from "@/lib/analytics";
interface AuthProviderProps {
user: User | null;
@@ -16,5 +18,30 @@ export function AuthProvider({ user }: AuthProviderProps) {
setLoading(false);
}, [user, setUser, setLoading]);
+ // Bridge Supabase auth state to PostHog so the analytics identity stays in
+ // sync with whoever is signed in, regardless of how they got there (form
+ // submit, OAuth redirect, page reload with a valid cookie, email-confirm
+ // callback, etc.). Without this, only users coming through the sign-in
+ // form get a person profile in PostHog and everyone else shows up as a
+ // random anonymous distinct_id.
+ useEffect(() => {
+ const supabase = createClient();
+ const {
+ data: { subscription },
+ } = supabase.auth.onAuthStateChange((event, session) => {
+ if (
+ (event === "INITIAL_SESSION" || event === "SIGNED_IN") &&
+ session?.user
+ ) {
+ identify(session.user.id, {
+ email: session.user.email,
+ });
+ } else if (event === "SIGNED_OUT") {
+ resetAnalytics();
+ }
+ });
+ return () => subscription.unsubscribe();
+ }, []);
+
return null;
}