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 a DataFast `paywall_view` goal from onboarding (#14184)

Nicholas Tindle534b70e07ffe
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 519031820d..80d946a54d 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
@@ -50,6 +50,12 @@ export function SubscriptionStep() {
key={cycle}
type="button"
onClick={() => setBilling(cycle)}
+ // Read by DataFast's script directly (delegated click listener on
+ // document), the same way the marketing site tags its CTAs — no
+ // JS needed. The `-cycle` suffix becomes the `cycle` metadata key.
+ data-fast-goal="paywall_billing_toggle"
+ data-fast-goal-cycle={cycle}
+ data-fast-goal-surface="onboarding_paywall"
className={cn(
"rounded-full border-none px-4 py-1.5 text-xs font-medium transition-all",
billing === cycle
diff --git a/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/__tests__/tracking.test.ts b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/__tests__/tracking.test.ts
new file mode 100644
index 0000000000..46664035e0
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/__tests__/tracking.test.ts
@@ -0,0 +1,57 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+const { sendDatafastEvent } = vi.hoisted(() => ({
+ sendDatafastEvent: vi.fn(),
+}));
+
+vi.mock("@/services/analytics", () => ({
+ analytics: { sendDatafastEvent },
+}));
+
+import { trackPaywallView } from "../tracking";
+
+describe("trackPaywallView", () => {
+ beforeEach(() => {
+ vi.restoreAllMocks();
+ sendDatafastEvent.mockReset();
+ sessionStorage.clear();
+ });
+
+ it("reports the paywall impression", () => {
+ trackPaywallView();
+
+ expect(sendDatafastEvent).toHaveBeenCalledTimes(1);
+ expect(sendDatafastEvent).toHaveBeenCalledWith("paywall_view", {});
+ });
+
+ // Cancelling Stripe checkout returns to `?step=1&subscription=cancelled` as a
+ // full navigation, remounting the paywall. Without the session guard that
+ // second mount would inflate the funnel's denominator.
+ it("reports at most once per session", () => {
+ trackPaywallView();
+ trackPaywallView();
+
+ expect(sendDatafastEvent).toHaveBeenCalledTimes(1);
+ });
+
+ it("still reports when sessionStorage is unavailable", () => {
+ vi.spyOn(Storage.prototype, "getItem").mockImplementation(() => {
+ throw new Error("storage blocked");
+ });
+
+ trackPaywallView();
+
+ expect(sendDatafastEvent).toHaveBeenCalledTimes(1);
+ });
+
+ // This runs in a mount effect on the screen users pay from: if a third-party
+ // script failure escaped, React would unmount the paywall into an error
+ // boundary and there would be nothing to buy.
+ it("never throws when the DataFast script does", () => {
+ sendDatafastEvent.mockImplementation(() => {
+ throw new Error("datafast unavailable");
+ });
+
+ expect(() => trackPaywallView()).not.toThrow();
+ });
+});
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
new file mode 100644
index 0000000000..c4980d241e
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(no-navbar)/onboarding/steps/SubscriptionStep/tracking.ts
@@ -0,0 +1,42 @@
+import { analytics } from "@/services/analytics";
+
+const PAYWALL_VIEW_SESSION_KEY = "paywall_view_tracked";
+
+/**
+ * Reports that the user was actually shown the paywall.
+ *
+ * Onboarding's steps all share the `/onboarding` URL (the `?step=` param is
+ * stripped by DataFast), so without this event the funnel can't tell "never
+ * reached the subscription screen" from "saw the price and declined" — which
+ * is the only question that matters between signup and payment.
+ *
+ * Deliberately untagged by pricing arm. `posthog.init` runs in an effect with
+ * no bootstrap, so the experiment variant is still unresolved when this step
+ * mounts and would record "control" for everyone; PostHog records arm
+ * assignment itself, so segmentation belongs there rather than here.
+ *
+ * Fires at most once per tab. Two paths would otherwise double-count:
+ * cancelling Stripe checkout returns to `?step=1&subscription=cancelled` as a
+ * full navigation that remounts this step, and a render committed before the
+ * wizard's init effect corrects `currentStep` can briefly mount the paywall at
+ * the store default of step 1. A genuinely new view (new tab or session) finds
+ * the key unset and reports normally.
+ */
+export function trackPaywallView() {
+ try {
+ if (sessionStorage.getItem(PAYWALL_VIEW_SESSION_KEY)) return;
+ sessionStorage.setItem(PAYWALL_VIEW_SESSION_KEY, "1");
+ } catch {
+ // In-app browsers may block sessionStorage — double-counting a view beats
+ // dropping it, so fall through to report either way.
+ }
+
+ try {
+ analytics.sendDatafastEvent("paywall_view", {});
+ } catch {
+ // sendDatafastEvent hands the event to the third-party DataFast script,
+ // which it calls without a guard of its own. This runs in a mount effect on
+ // the screen users pay from, so an exception here would unmount the paywall
+ // into an error boundary. Analytics must never be able to take checkout down.
+ }
+}
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 94fdd9a409..e75617a094 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
@@ -15,6 +15,8 @@ import {
TEAM_INTAKE_FORM_URL,
} from "@/components/molecules/PlanCard/plans";
import { useSubscriptionPricingExperiment } from "./useSubscriptionPricingExperiment";
+import { useMountEffect } from "@/hooks/useMountEffect";
+import { trackPaywallView } from "./tracking";
const PLAN_TO_TIER: Record<
Exclude<PlanKey, typeof PLAN_KEYS.TEAM | typeof PLAN_KEYS.BUSINESS>,
@@ -42,6 +44,13 @@ export function useSubscriptionStep() {
const { mutateAsync: updateTier, isPending: isUpdatingTier } =
useUpdateSubscriptionTier();
const { billing, plans } = useSubscriptionPricingExperiment();
+
+ // 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();
+ });
// Local guard that flips synchronously on first click so the profile-save
// phase (which runs before `isUpdatingTier` becomes true) can't be
// re-entered by a fast double-click queueing duplicate POSTs.