Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(web): track the cloud signup funnel

Andrejabacad71bee5
diff --git a/apps/web/index.html b/apps/web/index.html
index 86f577fcd..6b4996005 100644
--- a/apps/web/index.html
+++ b/apps/web/index.html
@@ -43,10 +43,13 @@
}
if (window.location.hostname === 'cloud.kaneo.app') {
+ window.plausible = window.plausible || function () {
+ (window.plausible.q = window.plausible.q || []).push(arguments);
+ };
const script = document.createElement('script');
script.defer = true;
script.setAttribute('data-domain', 'cloud.kaneo.app');
- script.src = 'https://plausible.kaneo.app/js/script.js';
+ script.src = 'https://plausible.kaneo.app/js/script.revenue.js';
document.head.appendChild(script);
}
</script>
diff --git a/apps/web/src/components/onboarding/onboarding-flow.tsx b/apps/web/src/components/onboarding/onboarding-flow.tsx
index 120c70e2e..d66029ec2 100644
--- a/apps/web/src/components/onboarding/onboarding-flow.tsx
+++ b/apps/web/src/components/onboarding/onboarding-flow.tsx
@@ -22,6 +22,7 @@ import {
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { useFadeTransition } from "@/hooks/use-fade-transition";
+import { track } from "@/lib/analytics/track";
import { Spinner } from "@/components/ui/spinner";
import useGetConfig from "@/hooks/queries/config/use-get-config";
import {
@@ -91,6 +92,7 @@ export function OnboardingFlow() {
description: data.description?.trim() || "",
userId: user?.id,
});
+ track("Workspace Created", { props: { usage } });
await queryClient.invalidateQueries({ queryKey: ["workspaces"] });
await authClient.organization.setActive({
diff --git a/apps/web/src/constants/billing.ts b/apps/web/src/constants/billing.ts
index 145af12ee..1e3633cfb 100644
--- a/apps/web/src/constants/billing.ts
+++ b/apps/web/src/constants/billing.ts
@@ -11,6 +11,7 @@ export type BillingPlan = {
monthly: string;
annual: string;
annualPerMonth: string;
+ amount: Record<BillingIntervalKey, number>;
features: string[];
};
@@ -20,6 +21,7 @@ export const BILLING_PLANS: BillingPlan[] = [
monthly: "$4",
annual: "$40",
annualPerMonth: "$3.33",
+ amount: { monthly: 4, annual: 40 },
features: ["singleUser", "unlimitedProjects", "backups", "emailSupport"],
},
{
@@ -27,6 +29,7 @@ export const BILLING_PLANS: BillingPlan[] = [
monthly: "$5",
annual: "$50",
annualPerMonth: "$4.17",
+ amount: { monthly: 5, annual: 50 },
features: [
"unlimitedMembers",
"unlimitedProjects",
diff --git a/apps/web/src/hooks/mutations/billing/use-billing-actions.ts b/apps/web/src/hooks/mutations/billing/use-billing-actions.ts
index ac5ef73eb..34759df62 100644
--- a/apps/web/src/hooks/mutations/billing/use-billing-actions.ts
+++ b/apps/web/src/hooks/mutations/billing/use-billing-actions.ts
@@ -6,12 +6,16 @@ import {
createBillingCheckout,
createBillingPortal,
} from "@/fetchers/billing/create-checkout";
+import { savePendingPurchase } from "@/lib/analytics/pending-purchase";
+import { track } from "@/lib/analytics/track";
export function useCreateCheckout(workspaceId: string | undefined) {
return useMutation({
mutationFn: (input: { plan: BillingPlan; interval: BillingInterval }) =>
createBillingCheckout({ workspaceId: workspaceId as string, ...input }),
- onSuccess: ({ checkoutUrl }) => {
+ onSuccess: ({ checkoutUrl }, { plan, interval }) => {
+ track("Checkout Started", { props: { plan, interval } });
+ savePendingPurchase({ plan, interval });
window.location.href = checkoutUrl;
},
onError: (error) => {
diff --git a/apps/web/src/hooks/mutations/task/use-create-task.ts b/apps/web/src/hooks/mutations/task/use-create-task.ts
index a15f4ba71..d67b92476 100644
--- a/apps/web/src/hooks/mutations/task/use-create-task.ts
+++ b/apps/web/src/hooks/mutations/task/use-create-task.ts
@@ -2,6 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import createTask, {
type CreateTaskRequest,
} from "@/fetchers/task/create-task";
+import { trackFirstTask } from "@/lib/analytics/activation";
function useCreateTask() {
const queryClient = useQueryClient();
@@ -32,6 +33,7 @@ function useCreateTask() {
draftAssetIds,
),
onSuccess: (_data, variables) => {
+ trackFirstTask();
void queryClient.invalidateQueries({
queryKey: ["tasks", variables.projectId],
});
diff --git a/apps/web/src/hooks/mutations/workspace-user/use-invite-workspace-user.ts b/apps/web/src/hooks/mutations/workspace-user/use-invite-workspace-user.ts
index 656f4dec1..bd035d944 100644
--- a/apps/web/src/hooks/mutations/workspace-user/use-invite-workspace-user.ts
+++ b/apps/web/src/hooks/mutations/workspace-user/use-invite-workspace-user.ts
@@ -1,5 +1,6 @@
import { useMutation } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
+import { track } from "@/lib/analytics/track";
import { authClient } from "@/lib/auth-client";
import queryClient from "@/query-client";
@@ -35,6 +36,9 @@ function useInviteWorkspaceUser() {
return data;
},
+ onSuccess: (_data, { resend }) => {
+ if (!resend) track("Invite Sent");
+ },
onSettled: (_, _error, { workspaceId }) => {
queryClient.invalidateQueries({
queryKey: ["workspace-invites", workspaceId],
diff --git a/apps/web/src/hooks/use-track-signup.ts b/apps/web/src/hooks/use-track-signup.ts
new file mode 100644
index 000000000..9abfbbafc
--- /dev/null
+++ b/apps/web/src/hooks/use-track-signup.ts
@@ -0,0 +1,20 @@
+import { useEffect } from "react";
+import { trackSignup } from "@/lib/analytics/activation";
+import { isNewSignup } from "@/lib/analytics/is-new-signup";
+
+type SessionUser = {
+ id: string;
+ createdAt: Date | string;
+ isAnonymous?: boolean | null;
+};
+
+export function useTrackSignup(user: SessionUser | undefined) {
+ const id = user?.id;
+ const createdAt = user?.createdAt;
+ const isAnonymous = user?.isAnonymous;
+
+ useEffect(() => {
+ if (!id || !createdAt || !isNewSignup(createdAt)) return;
+ trackSignup({ id, isAnonymous });
+ }, [id, createdAt, isAnonymous]);
+}
diff --git a/apps/web/src/hooks/use-track-subscription.ts b/apps/web/src/hooks/use-track-subscription.ts
new file mode 100644
index 000000000..7d309a90d
--- /dev/null
+++ b/apps/web/src/hooks/use-track-subscription.ts
@@ -0,0 +1,19 @@
+import { useEffect } from "react";
+import { takePendingPurchase } from "@/lib/analytics/pending-purchase";
+import { subscriptionRevenue } from "@/lib/analytics/subscription-revenue";
+import { track } from "@/lib/analytics/track";
+
+export function useTrackSubscription(
+ checkout: string | undefined,
+ seats: number | undefined,
+) {
+ useEffect(() => {
+ if (checkout !== "success" || seats === undefined) return;
+ const purchase = takePendingPurchase();
+ if (!purchase) return;
+ track("Subscribed", {
+ props: purchase,
+ revenue: subscriptionRevenue(purchase.plan, purchase.interval, seats),
+ });
+ }, [checkout, seats]);
+}
diff --git a/apps/web/src/lib/analytics/activation.test.ts b/apps/web/src/lib/analytics/activation.test.ts
new file mode 100644
index 000000000..a906c6bba
--- /dev/null
+++ b/apps/web/src/lib/analytics/activation.test.ts
@@ -0,0 +1,65 @@
+import {
+ afterEach,
+ beforeEach,
+ describe,
+ expect,
+ it,
+ vi,
+} from "vite-plus/test";
+import { trackFirstTask, trackSignup } from "./activation";
+
+const plausible = vi.fn();
+
+beforeEach(() => {
+ window.plausible = plausible;
+});
+
+afterEach(() => {
+ delete window.plausible;
+ localStorage.clear();
+ plausible.mockReset();
+});
+
+describe("trackSignup", () => {
+ it("records a signup once per user on this device", () => {
+ trackSignup({ id: "user-1" });
+ trackSignup({ id: "user-1" });
+
+ expect(plausible).toHaveBeenCalledTimes(1);
+ expect(plausible).toHaveBeenCalledWith("Signup", {
+ props: { guest: false },
+ });
+ });
+
+ it("marks guest accounts", () => {
+ trackSignup({ id: "guest-1", isAnonymous: true });
+
+ expect(plausible).toHaveBeenCalledWith("Signup", {
+ props: { guest: true },
+ });
+ });
+
+ it("stores nothing when analytics is not loaded", () => {
+ delete window.plausible;
+
+ trackSignup({ id: "user-1" });
+
+ expect(localStorage.length).toBe(0);
+ });
+});
+
+describe("trackFirstTask", () => {
+ it("records the first task only after a signup on this device", () => {
+ trackFirstTask();
+ expect(plausible).not.toHaveBeenCalled();
+
+ trackSignup({ id: "user-1" });
+ trackFirstTask();
+ trackFirstTask();
+
+ expect(plausible).toHaveBeenCalledWith("First Task", undefined);
+ expect(
+ plausible.mock.calls.filter(([event]) => event === "First Task"),
+ ).toHaveLength(1);
+ });
+});
diff --git a/apps/web/src/lib/analytics/activation.ts b/apps/web/src/lib/analytics/activation.ts
new file mode 100644
index 000000000..01c4aec3a
--- /dev/null
+++ b/apps/web/src/lib/analytics/activation.ts
@@ -0,0 +1,30 @@
+import { isTrackingEnabled, track } from "./track";
+
+const SIGNUP_KEY = "kaneo:tracked-signup:";
+const FIRST_TASK_KEY = "kaneo:first-task-pending";
+
+export function trackSignup(user: {
+ id: string;
+ isAnonymous?: boolean | null;
+}) {
+ if (!isTrackingEnabled()) return;
+ try {
+ if (localStorage.getItem(SIGNUP_KEY + user.id)) return;
+ localStorage.setItem(SIGNUP_KEY + user.id, "1");
+ localStorage.setItem(FIRST_TASK_KEY, "1");
+ } catch {
+ return;
+ }
+ track("Signup", { props: { guest: Boolean(user.isAnonymous) } });
+}
+
+export function trackFirstTask() {
+ if (!isTrackingEnabled()) return;
+ try {
+ if (!localStorage.getItem(FIRST_TASK_KEY)) return;
+ localStorage.removeItem(FIRST_TASK_KEY);
+ } catch {
+ return;
+ }
+ track("First Task");
+}
diff --git a/apps/web/src/lib/analytics/is-new-signup.test.ts b/apps/web/src/lib/analytics/is-new-signup.test.ts
new file mode 100644
index 000000000..ae2c5f012
--- /dev/null
+++ b/apps/web/src/lib/analytics/is-new-signup.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from "vite-plus/test";
+import { isNewSignup } from "./is-new-signup";
+
+const now = Date.parse("2026-10-05T09:00:00Z");
+
+describe("isNewSignup", () => {
+ it("treats an account created moments ago as a new signup", () => {
+ expect(isNewSignup("2026-10-05T08:59:30Z", now)).toBe(true);
+ });
+
+ it("accepts Date values from the session", () => {
+ expect(isNewSignup(new Date("2026-10-05T08:40:00Z"), now)).toBe(true);
+ });
+
+ it("ignores accounts older than thirty minutes", () => {
+ expect(isNewSignup("2026-10-05T08:29:59Z", now)).toBe(false);
+ });
+
+ it("ignores invalid and future timestamps", () => {
+ expect(isNewSignup("not a date", now)).toBe(false);
+ expect(isNewSignup("2026-10-05T09:05:00Z", now)).toBe(false);
+ });
+});
diff --git a/apps/web/src/lib/analytics/is-new-signup.ts b/apps/web/src/lib/analytics/is-new-signup.ts
new file mode 100644
index 000000000..febc6ef8a
--- /dev/null
+++ b/apps/web/src/lib/analytics/is-new-signup.ts
@@ -0,0 +1,7 @@
+const NEW_SIGNUP_WINDOW_MS = 30 * 60 * 1000;
+
+export function isNewSignup(createdAt: Date | string, now = Date.now()) {
+ const created = new Date(createdAt).getTime();
+ if (Number.isNaN(created)) return false;
+ return now - created >= 0 && now - created <= NEW_SIGNUP_WINDOW_MS;
+}
diff --git a/apps/web/src/lib/analytics/pending-purchase.test.ts b/apps/web/src/lib/analytics/pending-purchase.test.ts
new file mode 100644
index 000000000..8d9d48fd1
--- /dev/null
+++ b/apps/web/src/lib/analytics/pending-purchase.test.ts
@@ -0,0 +1,21 @@
+import { afterEach, describe, expect, it } from "vite-plus/test";
+import { savePendingPurchase, takePendingPurchase } from "./pending-purchase";
+
+afterEach(() => {
+ sessionStorage.clear();
+});
+
+describe("pending purchase", () => {
+ it("returns the saved purchase once", () => {
+ savePendingPurchase({ plan: "team", interval: "annual" });
+
+ expect(takePendingPurchase()).toEqual({ plan: "team", interval: "annual" });
+ expect(takePendingPurchase()).toBeNull();
+ });
+
+ it("rejects unknown values", () => {
+ sessionStorage.setItem("kaneo:pending-purchase", "enterprise-weekly");
+
+ expect(takePendingPurchase()).toBeNull();
+ });
+});
diff --git a/apps/web/src/lib/analytics/pending-purchase.ts b/apps/web/src/lib/analytics/pending-purchase.ts
new file mode 100644
index 000000000..5f9ec7268
--- /dev/null
+++ b/apps/web/src/lib/analytics/pending-purchase.ts
@@ -0,0 +1,31 @@
+import type { BillingIntervalKey, BillingPlanKey } from "@/constants/billing";
+
+const KEY = "kaneo:pending-purchase";
+const PLANS = new Set<string>(["personal", "team"]);
+const INTERVALS = new Set<string>(["monthly", "annual"]);
+
+export type PendingPurchase = {
+ plan: BillingPlanKey;
+ interval: BillingIntervalKey;
+};
+
+export function savePendingPurchase(purchase: PendingPurchase) {
+ try {
+ sessionStorage.setItem(KEY, `${purchase.plan}-${purchase.interval}`);
+ } catch {}
+}
+
+export function takePendingPurchase(): PendingPurchase | null {
+ try {
+ const value = sessionStorage.getItem(KEY);
+ sessionStorage.removeItem(KEY);
+ const [plan, interval] = value?.split("-") ?? [];
+ if (!PLANS.has(plan) || !INTERVALS.has(interval)) return null;
+ return {
+ plan: plan as BillingPlanKey,
+ interval: interval as BillingIntervalKey,
+ };
+ } catch {
+ return null;
+ }
+}
diff --git a/apps/web/src/lib/analytics/subscription-revenue.test.ts b/apps/web/src/lib/analytics/subscription-revenue.test.ts
new file mode 100644
index 000000000..f7e47b093
--- /dev/null
+++ b/apps/web/src/lib/analytics/subscription-revenue.test.ts
@@ -0,0 +1,30 @@
+import { describe, expect, it } from "vite-plus/test";
+import { subscriptionRevenue } from "./subscription-revenue";
+
+describe("subscriptionRevenue", () => {
+ it("prices the personal plan as a single seat", () => {
+ expect(subscriptionRevenue("personal", "monthly", 3)).toEqual({
+ currency: "USD",
+ amount: 4,
+ });
+ expect(subscriptionRevenue("personal", "annual", 1)).toEqual({
+ currency: "USD",
+ amount: 40,
+ });
+ });
+
+ it("multiplies the team price by seats", () => {
+ expect(subscriptionRevenue("team", "monthly", 6)).toEqual({
+ currency: "USD",
+ amount: 30,
+ });
+ expect(subscriptionRevenue("team", "annual", 3)).toEqual({
+ currency: "USD",
+ amount: 150,
+ });
+ });
+
+ it("counts at least one team seat", () => {
+ expect(subscriptionRevenue("team", "monthly", 0)?.amount).toBe(5);
+ });
+});
diff --git a/apps/web/src/lib/analytics/subscription-revenue.ts b/apps/web/src/lib/analytics/subscription-revenue.ts
new file mode 100644
index 000000000..fa51e7819
--- /dev/null
+++ b/apps/web/src/lib/analytics/subscription-revenue.ts
@@ -0,0 +1,18 @@
+import {
+ BILLING_PLANS,
+ type BillingIntervalKey,
+ type BillingPlanKey,
+} from "@/constants/billing";
+
+export function subscriptionRevenue(
+ plan: BillingPlanKey,
+ interval: BillingIntervalKey,
+ seats: number,
+) {
+ const price = BILLING_PLANS.find((entry) => entry.plan === plan)?.amount[
+ interval
+ ];
+ if (price === undefined) return undefined;
+ const units = plan === "team" ? Math.max(1, Math.floor(seats) || 1) : 1;
+ return { currency: "USD", amount: price * units };
+}
diff --git a/apps/web/src/lib/analytics/track.test.ts b/apps/web/src/lib/analytics/track.test.ts
new file mode 100644
index 000000000..18723d349
--- /dev/null
+++ b/apps/web/src/lib/analytics/track.test.ts
@@ -0,0 +1,36 @@
+import { afterEach, describe, expect, it, vi } from "vite-plus/test";
+import { isTrackingEnabled, track } from "./track";
+
+afterEach(() => {
+ delete window.plausible;
+});
+
+describe("track", () => {
+ it("does nothing when Plausible is not loaded, as on self-hosted instances", () => {
+ expect(isTrackingEnabled()).toBe(false);
+ expect(() => track("Signup")).not.toThrow();
+ });
+
+ it("forwards the event, props, and revenue to Plausible", () => {
+ const plausible = vi.fn();
+ window.plausible = plausible;
+
+ track("Subscribed", {
+ props: { plan: "team", interval: "annual" },
+ revenue: { currency: "USD", amount: 150 },
+ });
+
+ expect(plausible).toHaveBeenCalledWith("Subscribed", {
+ props: { plan: "team", interval: "annual" },
+ revenue: { currency: "USD", amount: 150 },
+ });
+ });
+
+ it("never lets an analytics failure reach the caller", () => {
+ window.plausible = () => {
+ throw new Error("blocked");
+ };
+
+ expect(() => track("Invite Sent")).not.toThrow();
+ });
+});
diff --git a/apps/web/src/lib/analytics/track.ts b/apps/web/src/lib/analytics/track.ts
new file mode 100644
index 000000000..3877893ee
--- /dev/null
+++ b/apps/web/src/lib/analytics/track.ts
@@ -0,0 +1,31 @@
+export type AnalyticsEvent =
+ | "Signup"
+ | "Workspace Created"
+ | "First Task"
+ | "Invite Sent"
+ | "Checkout Started"
+ | "Subscribed";
+
+export type TrackOptions = {
+ props?: Record<string, string | number | boolean>;
+ revenue?: { currency: string; amount: number };
+};
+
+declare global {
+ interface Window {
+ plausible?: (event: string, options?: TrackOptions) => void;
+ }
+}
+
+export function isTrackingEnabled() {
+ return (
+ typeof window !== "undefined" && typeof window.plausible === "function"
+ );
+}
+
+export function track(event: AnalyticsEvent, options?: TrackOptions) {
+ if (!isTrackingEnabled()) return;
+ try {
+ window.plausible?.(event, options);
+ } catch {}
+}
diff --git a/apps/web/src/routes/_layout/_authenticated.tsx b/apps/web/src/routes/_layout/_authenticated.tsx
index ecfb36d98..13c621348 100644
--- a/apps/web/src/routes/_layout/_authenticated.tsx
+++ b/apps/web/src/routes/_layout/_authenticated.tsx
@@ -1,4 +1,5 @@
import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";
+import { useTrackSignup } from "@/hooks/use-track-signup";
import { useUserWebSocket } from "@/hooks/use-user-websocket";
import { authClient } from "@/lib/auth-client";
@@ -34,6 +35,8 @@ export const Route = createFileRoute("/_layout/_authenticated")({
});
function AuthenticatedLayout() {
+ const { session } = Route.useRouteContext();
useUserWebSocket();
+ useTrackSignup(session?.user);
return <Outlet />;
}
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/billing.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/billing.tsx
index f1906da9a..ff296c762 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/billing.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/billing.tsx
@@ -8,12 +8,16 @@ import { TrialStatusCard } from "@/components/billing/trial-status-card";
import PageTitle from "@/components/page-title";
import { Spinner } from "@/components/ui/spinner";
import { useGetBilling } from "@/hooks/queries/billing/use-get-billing";
+import { useTrackSubscription } from "@/hooks/use-track-subscription";
import { useWorkspacePermission } from "@/hooks/use-workspace-permission";
export const Route = createFileRoute(
"/_layout/_authenticated/dashboard/settings/workspace/billing",
)({
component: RouteComponent,
+ validateSearch: (search: Record<string, unknown>) => ({
+ checkout: typeof search.checkout === "string" ? search.checkout : undefined,
+ }),
});
function RouteComponent() {
@@ -21,6 +25,8 @@ function RouteComponent() {
const { workspace, isAdmin } = useWorkspacePermission();
const workspaceId = workspace?.id;
const { data: billing, isLoading } = useGetBilling(workspaceId);
+ const { checkout } = Route.useSearch();
+ useTrackSubscription(checkout, billing?.seats);
if (isLoading) {
return (