Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: add PostHog trial events for cloud billing trials
ArshBallagan0b012f086fb6
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.tsindex 3739747003..9744ebc1d9 100644--- a/backend/src/ee/routes/v1/license-v2-router.ts+++ b/backend/src/ee/routes/v1/license-v2-router.ts@@ -2,9 +2,11 @@ import { FastifyRequest } from "fastify";import { z } from "zod";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";import { isUserSessionAuth } from "@app/server/plugins/auth/inject-identity";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";// The license server joins this onto its configured portal origin, so it must be a single-rooted// relative path. Reject protocol-relative ("//host", "/\\host") values that browsers can normalize@@ -546,13 +548,30 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {// A trial has no Stripe customer yet, so the server needs an email. Take it from the authenticated// user (this route is JWT-only) rather than trusting a client-supplied value.const email = isUserSessionAuth(req.auth) ? (req.auth.user.email ?? undefined) : undefined;- return server.services.licenseV2.startTrial({+ const result = await server.services.licenseV2.startTrial({orgId: req.params.organizationId,actor: buildActor(req.permission),productId: req.body.productId,plan: req.body.plan,});++ // Split on outcome rather than passing it as a property: "awaiting_card" means no card was on+ // file and the trial was NOT granted, so folding it into a "Trial Started" would overcount+ // trials. The actual grant for that branch happens on the License Server after the card-setup+ // checkout completes, which this service never observes, so neither event tracks conversion.+ void server.services.telemetry.sendPostHogEvents({+ event:+ result.outcome === "trial_started" ? PostHogEventTypes.TrialStarted : PostHogEventTypes.TrialCardRequired,+ distinctId: getTelemetryDistinctId(req),+ organizationId: req.params.organizationId,+ properties: {+ productId: req.body.productId,+ plan: req.body.plan+ }+ });++ return result;}});diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.tsindex 56b1372977..58b64b1110 100644--- a/backend/src/services/telemetry/telemetry-types.ts+++ b/backend/src/services/telemetry/telemetry-types.ts@@ -320,7 +320,13 @@ export enum PostHogEventTypes {AgentVaultProxyEnrolled = "Agent Vault Proxy Enrolled",AgentVaultProductMemberAdded = "Agent Vault Product Member Added",AgentVaultProductMemberUpdated = "Agent Vault Product Member Updated",- AgentVaultProductMemberRemoved = "Agent Vault Product Member Removed"+ AgentVaultProductMemberRemoved = "Agent Vault Product Member Removed",++ // Billing trials. Cloud-only: the self-hosted license backend rejects startTrial outright.+ // "awaiting_card" gets its own event rather than an outcome property on TrialStarted, because it+ // does NOT grant a trial; a "Trial Started" that never started would poison every funnel built on it.+ TrialStarted = "Trial Started",+ TrialCardRequired = "Trial Card Required"}export type TSecretModifiedEvent = {@@ -2518,6 +2524,28 @@ export type TAgentVaultPostHogEvent =export type TAgentVaultActorPostHogEvent = Exclude<TAgentVaultPostHogEvent, TAgentVaultProxyEnrolledEvent>;+// A trial is burned per PRODUCT, not per (product, plan): the trial-history gate discards plan_key+// (see licenseV2Service.getOverview), and the license server 409s a repeat. So TrialStarted fires at+// most once per (org, product) for the lifetime of the org. TrialCardRequired carries no such+// guarantee: abandoning the card-setup checkout grants nothing and retrying is safe, so the same org+// can emit it repeatedly for one product. Anything consuming these downstream must account for that.+// `plan` is recorded on both anyway. It doesn't gate, but it says which tier they actually wanted.+export type TTrialStartedEvent = {+ event: PostHogEventTypes.TrialStarted;+ properties: {+ productId: string;+ plan: string;+ };+};++export type TTrialCardRequiredEvent = {+ event: PostHogEventTypes.TrialCardRequired;+ properties: {+ productId: string;+ plan: string;+ };+};+export type TPostHogEvent = {distinctId: string;organizationId?: string;@@ -2748,4 +2776,6 @@ export type TPostHogEvent = {| TSecretRotationV2FailedEvent| TProxiedServiceCreatedEvent| TAgentVaultPostHogEvent+ | TTrialStartedEvent+ | TTrialCardRequiredEvent);