Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): report each onboarding step to DataFast (#14186)

Nicholas Tindle70b98319e7c1
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/tracking.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/tracking.test.ts
new file mode 100644
index 0000000000..5cb887537f
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/__tests__/tracking.test.ts
@@ -0,0 +1,95 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+const { sendDatafastEvent } = vi.hoisted(() => ({
+ sendDatafastEvent: vi.fn(),
+}));
+
+vi.mock("@/services/analytics", () => ({
+ analytics: { sendDatafastEvent },
+}));
+
+import { NO_PAYWALL_STEPS, PAYWALL_FIRST_STEPS } from "../store";
+import { onboardingStepKey, trackOnboardingStep } from "../tracking";
+
+describe("onboardingStepKey", () => {
+ // Welcome is step 2 with the paywall first and step 1 without it, so the
+ // number alone can't identify a step across cohorts.
+ it("maps the same key across both step layouts", () => {
+ expect(
+ onboardingStepKey(PAYWALL_FIRST_STEPS, PAYWALL_FIRST_STEPS.welcome),
+ ).toBe("welcome");
+ expect(onboardingStepKey(NO_PAYWALL_STEPS, NO_PAYWALL_STEPS.welcome)).toBe(
+ "welcome",
+ );
+ expect(
+ onboardingStepKey(PAYWALL_FIRST_STEPS, PAYWALL_FIRST_STEPS.preparing),
+ ).toBe("preparing");
+ expect(
+ onboardingStepKey(NO_PAYWALL_STEPS, NO_PAYWALL_STEPS.preparing),
+ ).toBe("preparing");
+ });
+
+ // The paywall reports itself as `paywall_view`; reporting it again here would
+ // double-count the top of the funnel.
+ it("returns null for the subscription step", () => {
+ expect(
+ onboardingStepKey(PAYWALL_FIRST_STEPS, PAYWALL_FIRST_STEPS.subscription),
+ ).toBeNull();
+ });
+});
+
+describe("trackOnboardingStep", () => {
+ beforeEach(() => {
+ vi.restoreAllMocks();
+ sendDatafastEvent.mockReset();
+ sessionStorage.clear();
+ });
+
+ it("reports one goal per step name", () => {
+ trackOnboardingStep("welcome");
+ trackOnboardingStep("pain_points");
+
+ expect(sendDatafastEvent).toHaveBeenNthCalledWith(
+ 1,
+ "onboarding_welcome",
+ {},
+ );
+ expect(sendDatafastEvent).toHaveBeenNthCalledWith(
+ 2,
+ "onboarding_pain_points",
+ {},
+ );
+ });
+
+ it("reports each step at most once per session", () => {
+ trackOnboardingStep("role");
+ trackOnboardingStep("role");
+
+ expect(sendDatafastEvent).toHaveBeenCalledTimes(1);
+ });
+
+ it("does not let one step suppress another", () => {
+ trackOnboardingStep("role");
+ trackOnboardingStep("preparing");
+
+ expect(sendDatafastEvent).toHaveBeenCalledTimes(2);
+ });
+
+ it("still reports when sessionStorage is unavailable", () => {
+ vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => {
+ throw new Error("storage blocked");
+ });
+
+ trackOnboardingStep("welcome");
+
+ expect(sendDatafastEvent).toHaveBeenCalledTimes(1);
+ });
+
+ it("never throws when the DataFast script does", () => {
+ sendDatafastEvent.mockImplementation(() => {
+ throw new Error("datafast unavailable");
+ });
+
+ expect(() => trackOnboardingStep("welcome")).not.toThrow();
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/SubscriptionStep.tsx b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/SubscriptionStep.tsx
index 80d946a54d..0364458eb7 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/SubscriptionStep.tsx
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/SubscriptionStep.tsx
@@ -89,6 +89,7 @@ export function SubscriptionStep() {
loading={isUpdatingTier && selectedPlan === plan.key}
disabled={isUpdatingTier && selectedPlan !== plan.key}
priceCaption="billing-period"
+ ctaGoalSurface="onboarding_paywall"
className={cn(
plan.key === PLAN_KEYS.MAX && "order-1 md:order-none",
plan.key === PLAN_KEYS.PRO && "order-2 md:order-none",
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/tracking.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/tracking.ts
index c4980d241e..3c4f2b2dc1 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/tracking.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/tracking.ts
@@ -40,3 +40,32 @@ export function trackPaywallView() {
// into an error boundary. Analytics must never be able to take checkout down.
}
}
+
+const CHECKOUT_CANCELLED_SESSION_KEY = "paywall_checkout_cancelled_tracked";
+
+/**
+ * Reports that the user reached Stripe Checkout and came back without paying.
+ *
+ * Distinguishes "looked at the price and never clicked" from "picked a plan,
+ * saw the card form, and backed out" — two very different problems that
+ * `paywall_view` alone cannot separate, since Stripe is off-domain.
+ *
+ * Guarded per tab because the `subscription=cancelled` param persists after the
+ * return: the wizard's URL-sync effect only rewrites the query when the step
+ * changes, and on a cancel return the step is already correct, so a refresh
+ * would otherwise report the same abandonment again.
+ */
+export function trackPaywallCheckoutCancelled() {
+ try {
+ if (sessionStorage.getItem(CHECKOUT_CANCELLED_SESSION_KEY)) return;
+ sessionStorage.setItem(CHECKOUT_CANCELLED_SESSION_KEY, "1");
+ } catch {
+ // In-app browsers may block sessionStorage — double-counting beats dropping.
+ }
+
+ try {
+ analytics.sendDatafastEvent("paywall_checkout_cancelled", {});
+ } catch {
+ // Never let analytics take the checkout UI down; see trackPaywallView.
+ }
+}
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/useSubscriptionStep.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/useSubscriptionStep.ts
index e75617a094..3ddf58c87d 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/useSubscriptionStep.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/useSubscriptionStep.ts
@@ -7,6 +7,7 @@ import {
} from "@/services/analytics/google-ads";
import { environment } from "@/services/environment";
import { useState } from "react";
+import { useSearchParams } from "next/navigation";
import { PAYWALL_FIRST_STEPS, useOnboardingWizardStore } from "../../store";
import { COUNTRIES } from "@/components/molecules/PlanCard/countries";
import {
@@ -16,7 +17,7 @@ import {
} from "@/components/molecules/PlanCard/plans";
import { useSubscriptionPricingExperiment } from "./useSubscriptionPricingExperiment";
import { useMountEffect } from "@/hooks/useMountEffect";
-import { trackPaywallView } from "./tracking";
+import { trackPaywallCheckoutCancelled, trackPaywallView } from "./tracking";
const PLAN_TO_TIER: Record<
Exclude<PlanKey, typeof PLAN_KEYS.TEAM | typeof PLAN_KEYS.BUSINESS>,
@@ -44,12 +45,18 @@ export function useSubscriptionStep() {
const { mutateAsync: updateTier, isPending: isUpdatingTier } =
useUpdateSubscriptionTier();
const { billing, plans } = useSubscriptionPricingExperiment();
+ const searchParams = useSearchParams();
// This step only mounts once the paywall is genuinely on screen, so mount is
// the honest moment to report the impression — and the one moment it can't
// be missed, whatever the flags resolve to afterwards.
useMountEffect(() => {
trackPaywallView();
+ // Stripe sends the user back here with `subscription=cancelled` after they
+ // abandon checkout, so the return lands on this same mount.
+ if (searchParams.get("subscription") === "cancelled") {
+ trackPaywallCheckoutCancelled();
+ }
});
// Local guard that flips synchronously on first click so the profile-save
// phase (which runs before `isUpdatingTier` becomes true) can't be
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/tracking.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/tracking.ts
new file mode 100644
index 0000000000..e3e75d6dc7
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/tracking.ts
@@ -0,0 +1,67 @@
+import { analytics } from "@/services/analytics";
+import type { Step } from "./store";
+
+export type OnboardingStepKey =
+ | "welcome"
+ | "role"
+ | "pain_points"
+ | "preparing";
+
+const SENT_KEY_PREFIX = "onboarding_step_sent_";
+
+interface StepLayout {
+ welcome: number;
+ role: number;
+ painPoints: number;
+ preparing: number;
+}
+
+/**
+ * Maps a wizard step number to a stable key.
+ *
+ * Step numbers differ between the paywall-first and no-paywall layouts, so the
+ * number alone is meaningless across cohorts — Welcome is 2 for one and 1 for
+ * the other. Keying by name keeps a single funnel readable for both. The
+ * subscription step returns null: it is reported as `paywall_view` instead.
+ */
+export function onboardingStepKey(
+ steps: StepLayout,
+ step: Step,
+): OnboardingStepKey | null {
+ if (step === steps.welcome) return "welcome";
+ if (step === steps.role) return "role";
+ if (step === steps.painPoints) return "pain_points";
+ if (step === steps.preparing) return "preparing";
+ return null;
+}
+
+/**
+ * Reports that the user reached a wizard step, at most once per tab.
+ *
+ * The wizard's five steps share the `/onboarding` URL and the backend records
+ * only ONBOARDING_COMPLETE, so without this nothing distinguishes "abandoned on
+ * Role" from "abandoned on Preparing" — the drop between signup and copilot is
+ * a single opaque number.
+ *
+ * One goal per step rather than one goal carrying the step as metadata, because
+ * DataFast funnel steps match on goal name; metadata could not express an
+ * ordered funnel.
+ */
+export function trackOnboardingStep(key: OnboardingStepKey) {
+ const sentKey = `${SENT_KEY_PREFIX}${key}`;
+ try {
+ if (sessionStorage.getItem(sentKey)) return;
+ sessionStorage.setItem(sentKey, "1");
+ } catch {
+ // In-app browsers may block sessionStorage — double-counting a step beats
+ // dropping it, so fall through to report either way.
+ }
+
+ try {
+ analytics.sendDatafastEvent(`onboarding_${key}`, {});
+ } catch {
+ // sendDatafastEvent hands off to the third-party DataFast script, which it
+ // calls without a guard of its own. This runs inside the onboarding wizard,
+ // so an exception here would unmount the flow into an error boundary.
+ }
+}
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
index 5b4d19ec33..7feaedded6 100644
--- a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts
@@ -21,6 +21,7 @@ import {
Step,
useOnboardingWizardStore,
} from "./store";
+import { onboardingStepKey, trackOnboardingStep } from "./tracking";
const LD_INIT_TIMEOUT_SECONDS = 5;
@@ -143,6 +144,11 @@ export function useOnboardingPage() {
useState(true);
const hasSubmitted = useRef(false);
const hasInitialized = useRef(false);
+ // Distinct from the `hasInitialized` ref above: that guards init running
+ // once, this says the chosen step has landed. Set in the same batch as the
+ // init effect's `goToStep`, so the first render where it is true already
+ // carries the settled step.
+ const [isStepSettled, setIsStepSettled] = useState(false);
// Initialise store from URL on mount, clamp ?step= to the highest step
// the user has actually reached. No-step URL resumes from the highest
@@ -168,8 +174,22 @@ export function useOnboardingPage() {
urlStep === null ? ceiling : Math.min(urlStep, ceiling)
) as Step;
goToStep(target);
+ setIsStepSettled(true);
}, [isReady, searchParams, goToStep, preparingStep, steps]);
+ // Report the step the wizard is actually showing. `isOnboardingStateLoading`
+ // is the same gate the page renders on — it also covers the window holding
+ // the ONBOARDING_COMPLETE check that redirects finished users to /copilot —
+ // and `isStepSettled` means the step above has landed, so a user resuming
+ // at Preparing never reports the store's default of Welcome on the way past.
+ // Repeat visits to a step are dropped by `trackOnboardingStep` itself, so
+ // going back and forward reports nothing new.
+ useEffect(() => {
+ if (isOnboardingStateLoading || !isStepSettled) return;
+ const key = onboardingStepKey(steps, currentStep);
+ if (key) trackOnboardingStep(key);
+ }, [isOnboardingStateLoading, isStepSettled, currentStep, steps]);
+
// Sync store → URL when step changes; record the new ceiling.
useEffect(() => {
if (!isReady) return;
diff --git a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallModal.tsx b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallModal.tsx
index 89972b90cd..ed70e4ee7c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallModal.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/PaywallGate/PaywallModal.tsx
@@ -160,6 +160,7 @@ export function PaywallModal() {
loading={isPending && selectedTier === plan.key}
disabled={isPending && selectedTier !== plan.key}
priceCaption="billing-period"
+ ctaGoalSurface="upgrade_modal"
/>
))}
</div>
diff --git a/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx b/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx
index 13fc19f674..f65f42cde7 100644
--- a/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx
+++ b/autogpt_platform/frontend/src/components/molecules/PlanCard/PlanCard.tsx
@@ -25,6 +25,10 @@ interface Props {
// "charged-today" shows the prorated amount billed now; "billing-period"
// shows a plain "billed monthly/annually" caption instead (paywall surface).
priceCaption?: "charged-today" | "billing-period";
+ // Names the surface this card is rendered on to tag its CTA for DataFast.
+ // Omitted, the card reports nothing — each surface opts in so a shared goal
+ // never mixes clicks from the onboarding paywall and the upgrade modal.
+ ctaGoalSurface?: string;
}
export function PlanCard({
@@ -36,6 +40,7 @@ export function PlanCard({
loading = false,
disabled = false,
priceCaption = "charged-today",
+ ctaGoalSurface,
}: Props) {
const { primaryPrice, chargedToday } = computePlanPricing({
plan,
@@ -255,6 +260,12 @@ export function PlanCard({
className="w-full"
loading={loading}
disabled={disabled}
+ {...(ctaGoalSurface && {
+ "data-fast-goal": "plan_cta_click",
+ "data-fast-goal-plan": plan.key.toLowerCase(),
+ "data-fast-goal-cycle": isYearly ? "yearly" : "monthly",
+ "data-fast-goal-surface": ctaGoalSurface,
+ })}
>
{plan.cta}
</Button>