Skip to content

Open source CapCut alternative.

TypeScript

feat(site): track signup and first edits

David Lef11584edb96d
diff --git a/site/src/app/_components/landing/AuthScreen.tsx b/site/src/app/_components/landing/AuthScreen.tsx
index 5ba8290a..811e019b 100644
--- a/site/src/app/_components/landing/AuthScreen.tsx
+++ b/site/src/app/_components/landing/AuthScreen.tsx
@@ -3,10 +3,11 @@
import Image from "next/image";
import Link from "next/link";
import { useTranslations } from "next-intl";
-import { useCallback, useState, type ReactNode } from "react";
+import { useCallback, useEffect, useState, type ReactNode } from "react";
import { TopNav } from "@/app/_components/landing/TopNav";
import { EmailAuthForm } from "@/app/_components/landing/EmailAuthForm";
+import { track } from "@/lib/analytics";
import { authClient } from "@/lib/auth-client";
import { cn } from "@/lib/utils";
@@ -68,10 +69,19 @@ export function AuthScreen({ mode, method = "google", callbackURL, authError, fo
if (callbackURL) alternateParams.set("callbackURL", callbackURL);
const alternateHref = `${screenCopy.alternateHref}${alternateParams.size ? `?${alternateParams}` : ""}`;
+ // A provider callback that came back refused lands here carrying its code.
+ useEffect(() => {
+ if (!authError) {
+ return;
+ }
+ track("auth_failed", { mode, method: "google", error: authError });
+ }, [authError, mode]);
+
const googleFailed = t("googleFailed");
const handleGoogleAuth = useCallback(async () => {
setIsPending(true);
setStatusMessage(null);
+ track("auth_started", { mode, method: "google" });
try {
await authClient.signIn.social({
@@ -83,11 +93,12 @@ export function AuthScreen({ mode, method = "google", callbackURL, authError, fo
provider: "google",
});
} catch {
+ track("auth_failed", { mode, method: "google", error: "request_failed" });
setStatusMessage(googleFailed);
} finally {
setIsPending(false);
}
- }, [callbackURL, googleFailed]);
+ }, [callbackURL, googleFailed, mode]);
const googleButtonWidth = Math.round(
(screenCopy.googleWidth * GOOGLE_BUTTON_HEIGHT) / 40,
diff --git a/site/src/app/_components/landing/EmailAuthForm.tsx b/site/src/app/_components/landing/EmailAuthForm.tsx
index f0802656..b55f58aa 100644
--- a/site/src/app/_components/landing/EmailAuthForm.tsx
+++ b/site/src/app/_components/landing/EmailAuthForm.tsx
@@ -2,6 +2,7 @@
import { useTranslations } from "next-intl";
import { useState, type FormEvent } from "react";
+import { track } from "@/lib/analytics";
import { authClient } from "@/lib/auth-client";
type Props = { mode: "sign-in" | "sign-up"; callbackURL?: string };
@@ -35,6 +36,7 @@ export function EmailAuthForm({ mode, callbackURL }: Props) {
const data = new FormData(event.currentTarget);
setPending(true);
setError(null);
+ track("auth_started", { mode, method: "email" });
try {
const credentials = {
email: String(data.get("email")),
@@ -45,12 +47,14 @@ export function EmailAuthForm({ mode, callbackURL }: Props) {
? await authClient.signUp.email({ ...credentials, name: String(data.get("name")) })
: await authClient.signIn.email(credentials);
if (result.error) {
+ track("auth_failed", { mode, method: "email", error: result.error.code ?? String(result.error.status ?? "unknown") });
setError(describe(result.error));
} else if (signingUp) {
// OAuth callbacks can be non-React endpoints, so complete signup with a full navigation.
window.location.href = credentials.callbackURL;
}
} catch {
+ track("auth_failed", { mode, method: "email", error: "request_failed" });
setError(t("form.requestFailed"));
} finally {
setPending(false);
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index e4e45df7..5d15d7a3 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -50,6 +50,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { apiJson, engineReady } from "@/cut/lib/api";
+import { track } from "@/lib/analytics";
import { useCutCaps, useLocalCompute } from "@/cut/lib/backend/hooks";
import { localBackend } from "@/cut/lib/backend/local";
import { setAssetDragData } from "@/cut/lib/assetDrag";
@@ -1957,7 +1958,9 @@ function ChatSession({
setSendError(unavailableMessage());
return;
}
- if (busy || requests.snapshot()) {
+ const queued = busy || requests.snapshot();
+ track("chat_message_sent", { provider: provider(currentModel()), attachments: all.length, queued });
+ if (queued) {
// A paused queue stays paused: parked rows fire only from the tray's
// resume button, never as a side effect of submitting something new.
// With the queue live, the triage places the row right away.
diff --git a/site/src/cut/components/AudioPanel.tsx b/site/src/cut/components/AudioPanel.tsx
index 90201387..65a0166d 100644
--- a/site/src/cut/components/AudioPanel.tsx
+++ b/site/src/cut/components/AudioPanel.tsx
@@ -63,6 +63,7 @@ import { useLocalPref } from "@/cut/lib/uiState";
import { DUCK_DEFAULT } from "@/cut/lib/voiceover";
import { useSpeakerVoice, useSpeechLanguage, VoicePicker } from "@/cut/components/VoicePicker";
import { GeneratedAssetMenu } from "@/cut/components/GeneratedAssetMenu";
+import { track } from "@/lib/analytics";
import { cn } from "@/lib/utils";
import { scrimIconButton } from "@/cut/components/iconButton";
import { ScrollArea } from "@/components/ui/scroll-area";
@@ -203,6 +204,7 @@ function MusicGenerator({ projectId }: { projectId: string }) {
if (!text) return;
setError(null);
const n = takes;
+ track("generation_started", { kind: "music", refs: 0 });
await Promise.all(
Array.from({ length: n }, async () => {
// Spins the Audio rail tile for the take's whole flight.
@@ -385,6 +387,7 @@ function VoiceGenerator({ projectId }: { projectId: string }) {
// before the voice lands.
const settle = useGenNotify.getState().begin("audio", "voice");
setError(null);
+ track("generation_started", { kind: "voiceover", refs: 0 });
try {
const playhead = playheadAt();
// Label with the spoken line, not just its first words, so the preview
diff --git a/site/src/cut/components/Editor.tsx b/site/src/cut/components/Editor.tsx
index bfbd003a..8cefb3fa 100644
--- a/site/src/cut/components/Editor.tsx
+++ b/site/src/cut/components/Editor.tsx
@@ -778,6 +778,9 @@ export function Editor({
// Typing is never interrupted: a focused text field keeps the keyboard.
focusShell();
setImporting((n) => n + list.length);
+ // What landed, by kind, for the one import report after the run.
+ const kinds = new Set<MediaAsset["type"]>();
+ let landed = 0;
// Files are probed one at a time, so a run lands in drop order. Their
// bytes go out in parallel, from the upload queue.
for (const file of list) {
@@ -853,6 +856,8 @@ export function Editor({
// drawn from those rather than downloaded back from storage.
void enrichAsset(asset, pending?.localUrl);
if (pending) startUpload(projectId, pending);
+ kinds.add(asset.type);
+ landed += 1;
opts?.onOutcome?.({ file, assetId: asset.id });
} catch (err) {
reportSwallowed("[cut] import failed", err, file.name);
@@ -861,6 +866,18 @@ export function Editor({
setImporting((n) => n - 1);
}
}
+
+ // The person's own files only: a recording or a copied frame carries
+ // an origin and is media the editor made.
+ if (opts?.origin || !list.length) {
+ return;
+ }
+ track("media_imported", {
+ count: landed,
+ failed: list.length - landed,
+ kinds: [...kinds],
+ target: opts?.mediaOnly ? "media" : "timeline",
+ });
},
[projectId, focusShell]
);
diff --git a/site/src/cut/components/GeneratePanel.tsx b/site/src/cut/components/GeneratePanel.tsx
index e88d78f7..3d666c0c 100644
--- a/site/src/cut/components/GeneratePanel.tsx
+++ b/site/src/cut/components/GeneratePanel.tsx
@@ -36,6 +36,7 @@ import {
} from "@/cut/lib/videoModels";
import { videoRenderMicros } from "@/lib/credits/price-sheet";
import { useLabels } from "@/i18n/labels";
+import { track } from "@/lib/analytics";
import { cn } from "@/lib/utils";
import { CopyHandlePill, MentionTextarea, RefChips } from "./AssetRefs";
import { DictationControl } from "./MicDictation";
@@ -127,6 +128,7 @@ export function GenerateVideoPanel({ projectId }: { projectId: string }) {
// same person delivers it.
const composed = character?.persona ? characterPrompt(character.persona, text) : text;
const seedRefs = character ? [refFromStockVideo(character)] : all;
+ track("generation_started", { kind: "video", refs: seedRefs.length });
void useGenerate.getState().generateVideo(projectId, composed, {
aspect: effAspect,
resolution: effResolution,
diff --git a/site/src/cut/components/ImageGenPanel.tsx b/site/src/cut/components/ImageGenPanel.tsx
index 738660cc..bb051c6e 100644
--- a/site/src/cut/components/ImageGenPanel.tsx
+++ b/site/src/cut/components/ImageGenPanel.tsx
@@ -25,6 +25,7 @@ import { refsFromDroppedFiles } from "@/cut/lib/refMedia";
import { useEditor } from "@/cut/lib/store";
import { nearestAspect, type MediaAsset } from "@/cut/lib/types";
import { imageMicros } from "@/lib/credits/price-sheet";
+import { track } from "@/lib/analytics";
import { cn } from "@/lib/utils";
import { CopyHandlePill, MentionTextarea, RefChips } from "./AssetRefs";
import { DictationControl } from "./MicDictation";
@@ -106,6 +107,7 @@ export function ImageGenPanel({ projectId }: { projectId: string }) {
const go = () => {
const { text, refs: all } = collectRefs(prompt.trim(), refs, candidates);
if (!text) return;
+ track("generation_started", { kind: "image", refs: all.length });
void useGenerate.getState().generateImage(projectId, text, { refs: all, aspect, resolution });
};
diff --git a/site/src/cut/components/NavUser.tsx b/site/src/cut/components/NavUser.tsx
index 2ebd618c..916de6b6 100644
--- a/site/src/cut/components/NavUser.tsx
+++ b/site/src/cut/components/NavUser.tsx
@@ -26,6 +26,7 @@ import { connectToEngine } from "@/cut/lib/connect";
import { cutInstallHref } from "@/cut/lib/install";
import { openOnboarding } from "@/cut/lib/onboarding";
import { useCutBase } from "@/cut/lib/nav";
+import { resetAnalytics } from "@/lib/analytics";
import { authClient, useSession } from "@/lib/auth-client";
import { useAccountProfile, visibleName } from "@/queries/accountProfile";
@@ -89,6 +90,7 @@ export function NavUser() {
await authClient.revokeSessions();
} finally {
forgetRememberedEngineUser();
+ resetAnalytics();
await authClient.signOut();
router.push("/");
}
diff --git a/site/src/cut/lib/exportStore.ts b/site/src/cut/lib/exportStore.ts
index f29f2b5a..a7997f55 100644
--- a/site/src/cut/lib/exportStore.ts
+++ b/site/src/cut/lib/exportStore.ts
@@ -2,6 +2,7 @@
import { useEffect, useMemo, useRef } from "react";
import { create } from "zustand";
+import { track } from "@/lib/analytics";
import { engineOrigin, servedFromEngine } from "./api";
import { getBackend, type CutBackend, type CutMode } from "./backend";
import { browserBackend } from "./backend/browser";
@@ -138,6 +139,11 @@ export const useExports = create<ExportsState>((set, get) => ({
const inBrowser = await canRenderInBrowser(doc, settings, doc.colorSpace ?? "sdr");
const tabOwned = backend.kind !== "local" || inBrowser;
const abort = tabOwned ? new AbortController() : undefined;
+ // Who ends up rendering, for the start and finish reports: the tab, or the
+ // machine behind the project when the tab can't or gives up.
+ let renderer: "tab" | "machine" = inBrowser ? "tab" : "machine";
+ const shape = { residency: backend.kind, width: settings.width, height: settings.height, fps: settings.fps, codec: settings.codec };
+ track("export_started", { ...shape, renderer });
set((s) => ({
local: [
...s.local,
@@ -190,8 +196,12 @@ export const useExports = create<ExportsState>((set, get) => ({
// The machine behind the project renders what the tab could not: the
// engine has a Mac project's media, the worker a cloud project's, and a
// browser project's goes up with the job.
+ // A job handed to the engine or the worker returns once queued; its file
+ // lands later, in the feed.
+ let queued = false;
const renderOnWorker = async () => {
release();
+ renderer = "machine";
if (backend.kind === "browser") {
await runBrowserExportInCloud(projectId, doc, settings, tabOpts);
return;
@@ -202,6 +212,7 @@ export const useExports = create<ExportsState>((set, get) => ({
),
}));
tabOpts.onClaimed(await createExportJob(projectId, doc, settings));
+ queued = true;
};
try {
if (inBrowser) {
@@ -224,6 +235,7 @@ export const useExports = create<ExportsState>((set, get) => ({
} else {
await renderOnWorker();
}
+ track("export_finished", { ...shape, renderer, result: queued ? "queued" : "done" });
// Pull the finished (or queued) job into the feed *before* retiring the
// placeholder — dropping the local row first left a round-trip with
// neither row on screen — and while the job row is still hidden, since
@@ -247,8 +259,10 @@ export const useExports = create<ExportsState>((set, get) => ({
// failure.
if (err instanceof DOMException && err.name === "AbortError") {
set((s) => ({ local: s.local.filter((r) => r.id !== localId) }));
+ track("export_finished", { ...shape, renderer, result: "cancelled" });
return;
}
+ track("export_finished", { ...shape, renderer, result: "failed", error: errorFields(err, String(err)).errorCode ?? "unknown" });
fail(err);
}
},
diff --git a/site/src/lib/analytics.ts b/site/src/lib/analytics.ts
index f0c32028..3f42b136 100644
--- a/site/src/lib/analytics.ts
+++ b/site/src/lib/analytics.ts
@@ -1,6 +1,8 @@
import posthog from "posthog-js";
import { useEffect } from "react";
+import type { CutMode } from "@/cut/lib/backend/types";
+import type { ExportCodec } from "@/cut/lib/exportClient";
import type { PerfLogBatch } from "@/cut/lib/perfLog";
import type { MainThreadSample, PerfSample } from "@/cut/lib/perfTrace";
import type { ShortcutDecline } from "@/cut/lib/shortcutGate";
@@ -13,6 +15,20 @@ import type {
// What the plans modal opened for: a limit hit, or the plans asked for.
type PlansReason = "projects" | "credits" | "storage" | "plans";
+type AuthMode = "sign-in" | "sign-up";
+type AuthMethod = "google" | "email";
+
+// What an export was asked for, and who renders it: the tab, or the machine
+// behind the project (the engine on this Mac, or the cloud worker).
+type ExportShape = {
+ residency: CutMode;
+ renderer: "tab" | "machine";
+ width: number;
+ height: number;
+ fps: number;
+ codec: ExportCodec;
+};
+
// Where a plan's checkout started: the plans modal, with what raised it and
// the button or limit that did; the onboarding's plans slide; or the storage
// grace banner on the projects home.
@@ -29,8 +45,15 @@ export type AnalyticsEvents = {
app_loaded: { app: "cut" | "settings" };
// Install prompts on the Cut app home's connect gate.
app_install_clicked: { source: "connect_gate_button" | "connect_gate_link" };
+ // A Google or email sign-in/sign-up began on the auth page, and one that
+ // came back refused (error is the provider's or the API's code).
+ auth_started: { mode: AuthMode; method: AuthMethod };
+ auth_failed: { mode: AuthMode; method: AuthMethod; error: string };
// The welcome sequence a new account sees, and its replay from settings.
onboarding_started: { source: OnboardingRun };
+ // Each slide as it comes up, so the drop between start and finish has a
+ // place. step is the slide's index among the ones this account sees.
+ onboarding_slide_viewed: { source: OnboardingRun; slide: string; step: number };
onboarding_referral_selected: {
referralSources: ReferralSource[];
referralOther?: string;
@@ -38,6 +61,18 @@ export type AnalyticsEvents = {
onboarding_completed: { source: OnboardingRun; skipped: boolean; step: number };
// The sequence's plans slide came up; intro as on the plans modal.
onboarding_plans_shown: { source: OnboardingRun; intro: number };
+ // The first things a new account does in the editor. An import reports
+ // once per run of files the person brought in: how many landed, how many
+ // didn't, and whether they went on the timeline or only into Media.
+ media_imported: { count: number; failed: number; kinds: string[]; target: "timeline" | "media" };
+ // A message sent from the chat composer; queued when a turn was running.
+ chat_message_sent: { provider: string; attachments: number; queued: boolean };
+ // A render started from a generate panel. Chat-started ones ride the chat.
+ generation_started: { kind: "video" | "image" | "music" | "voiceover"; refs: number };
+ // An export, and how it ended: done when its file is written, queued when
+ // the engine or the worker took it on, failed with the error code.
+ export_started: ExportShape;
+ export_finished: ExportShape & { result: "done" | "queued" | "cancelled" | "failed"; error?: string };
// Cut projects home.
project_created: { source: "projects_home" | "sidebar" | "file_import" | "chatgpt_card" };
folder_created: void;
@@ -103,6 +138,12 @@ export function useAppLoaded(
}, [app, id, email]);
}
+// Forgets the signed-out account on this browser, so whatever happens here
+// next counts as an anonymous visitor until the next sign-in binds one.
+export function resetAnalytics(): void {
+ posthog.reset();
+}
+
// Runs once per page load, after `identify`: every assignment becomes a super
// property so any later event breaks down by variant, and a first exposure is
// its own event with the variant pinned on the person. A property registered