Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(frontend): identify new accounts in PostHog at signup completion (#7787)

claude[bot]0dd1b7238eda
diff --git a/frontend/src/components/auth/UserInfoStep.tsx b/frontend/src/components/auth/UserInfoStep.tsx
index 4490a4f802..1356929507 100644
--- a/frontend/src/components/auth/UserInfoStep.tsx
+++ b/frontend/src/components/auth/UserInfoStep.tsx
@@ -33,6 +33,7 @@ import { fetchOrganizations } from "@app/hooks/api/organization/queries";
import { GenericResourceNameSchema } from "@app/lib/schemas";
import SecurityClient from "../utilities/SecurityClient";
+import Telemetry from "../utilities/telemetry/Telemetry";
import { AuthPagePanel } from "./AuthPagePanel";
const createUserInfoFormSchema = (isInvite: boolean, passwordPolicy: TPasswordPolicy) =>
@@ -108,6 +109,8 @@ export default function UserInfoStep({
const submitLabel = isInvite ? String(t("signup.signup")) : "Continue";
const onSubmit = async (formData: UserInfoFormData) => {
+ const telemetry = new Telemetry().getInstance();
+
const latestBreachStatus = await validatePassword(formData.password);
if (latestBreachStatus === "breached") {
setError("password", {
@@ -130,6 +133,11 @@ export default function UserInfoStep({
SecurityClient.setSignupToken("");
SecurityClient.setToken(response.token);
+ // The distinct id has to match the one the backend captures signup events with, which is
+ // user.username: the lowercased email.
+ const signupEmail = email.toLowerCase();
+ telemetry.identify(signupEmail, signupEmail);
+
if (isInfisicalCloud()) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: "signup_completed" });
diff --git a/frontend/src/pages/auth/SelectOrgPage/route.tsx b/frontend/src/pages/auth/SelectOrgPage/route.tsx
index f21539fd1d..e1c21fed08 100644
--- a/frontend/src/pages/auth/SelectOrgPage/route.tsx
+++ b/frontend/src/pages/auth/SelectOrgPage/route.tsx
@@ -4,6 +4,7 @@ import { addSeconds, formatISO } from "date-fns";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
+import Telemetry from "@app/components/utilities/telemetry/Telemetry";
import { SessionStorageKeys } from "@app/const";
import { isInfisicalCloud } from "@app/helpers/platform";
import { consumeLoginRedirectUrl } from "@app/helpers/sessionStorage";
@@ -17,6 +18,7 @@ import {
} from "@app/hooks/api/organization/queries";
import { onRequestError, setAuthToken } from "@app/hooks/api/reactQuery";
import { fetchUserDetails, logoutUser } from "@app/hooks/api/users/queries";
+import { userKeys } from "@app/hooks/api/users/query-keys";
import { getSsoEnforcementError } from "./SelectOrg.utils";
import { SelectOrgPage } from "./SelectOrgPage";
@@ -55,6 +57,20 @@ export const Route = createFileRoute("/_restrict-login-signup/login/select-organ
window.dataLayer.push({ event: "signup_completed" });
}
+ // posthog-js never initializes on the signup path, so the anonymous marketing-site visitor
+ // is never merged into the new account. Identify on user.username, the distinct id the
+ // backend captures signup events with.
+ try {
+ const user = await context.queryClient.ensureQueryData({
+ queryKey: userKeys.getUser,
+ queryFn: fetchUserDetails
+ });
+ const telemetry = new Telemetry().getInstance();
+ telemetry.identify(user.username, user.email ?? user.username);
+ } catch {
+ // best-effort attribution; it must never block the signup redirect
+ }
+
// Provider-verified signups arrive with no org; send them to org setup instead of the
// personal-org fallback. Fetch errors fall through to the strip-redirect, whose main
// flow re-fetches and surfaces them.
diff --git a/frontend/src/pages/auth/SignUpSsoPage/SignUpSsoPage.tsx b/frontend/src/pages/auth/SignUpSsoPage/SignUpSsoPage.tsx
index bd7e7c026b..6b83100606 100644
--- a/frontend/src/pages/auth/SignUpSsoPage/SignUpSsoPage.tsx
+++ b/frontend/src/pages/auth/SignUpSsoPage/SignUpSsoPage.tsx
@@ -8,6 +8,7 @@ import { AuthPageLayout } from "@app/components/auth/AuthPageLayout";
import { AuthPagePanel } from "@app/components/auth/AuthPagePanel";
import { createNotification } from "@app/components/notifications";
import SecurityClient from "@app/components/utilities/SecurityClient";
+import Telemetry from "@app/components/utilities/telemetry/Telemetry";
import {
Button,
CardContent,
@@ -52,6 +53,8 @@ export const SignupSsoPage = () => {
}, [token]);
const handleSubmit = async () => {
+ const telemetry = new Telemetry().getInstance();
+
const { token: accessToken } = await completeAccountSignup.mutateAsync({
type: "alias",
code,
@@ -62,6 +65,11 @@ export const SignupSsoPage = () => {
SecurityClient.setToken(accessToken);
const { organizationId } = jwtDecode(accessToken) as { organizationId?: string };
+ if (decoded.email) {
+ const signupEmail = decoded.email.toLowerCase();
+ telemetry.identify(signupEmail, signupEmail);
+ }
+
if (isInfisicalCloud()) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: "signup_completed" });