feat(analytics): add behavior and payment funnel tracking

This commit is contained in:
2026-07-14 16:54:13 +08:00
parent ca55723e48
commit 81d6489978
70 changed files with 1576 additions and 81 deletions
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import {
getDefaultPaymentAnalyticsContext,
parsePaymentAnalyticsContext,
} from "../payment_analytics_context";
describe("payment analytics context", () => {
it("keeps supported payment entry and reason values", () => {
expect(
parsePaymentAnalyticsContext({
entryPoint: "chat_unlock",
triggerReason: "ad_landing",
subscriptionType: "topup",
}),
).toEqual({
entryPoint: "chat_unlock",
triggerReason: "ad_landing",
});
});
it("falls back independently for invalid query values", () => {
expect(
parsePaymentAnalyticsContext({
entryPoint: "unsafe-entry",
triggerReason: "unsafe-reason",
subscriptionType: "topup",
}),
).toEqual(getDefaultPaymentAnalyticsContext("topup"));
expect(
parsePaymentAnalyticsContext({
entryPoint: "sidebar",
triggerReason: null,
subscriptionType: "vip",
}),
).toEqual({ entryPoint: "sidebar", triggerReason: "vip_cta" });
});
});