Posthog: drop $initial_person_info from outgoing events

This commit is contained in:
fkwp
2026-05-15 19:02:37 +02:00
parent 7e932d27da
commit a8c5f14037
2 changed files with 45 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import {
beforeAll,
afterAll,
} from "vitest";
import posthog, { type Properties } from "posthog-js";
import { PosthogAnalytics } from "./PosthogAnalytics";
import { mockConfig } from "../utils/test";
@@ -88,4 +89,45 @@ describe("PosthogAnalytics", () => {
expect(PosthogAnalytics.instance.isEnabled()).toBe(true);
});
});
describe("sanitizeProperties", () => {
beforeAll(() => {
vi.stubEnv("VITE_PACKAGE", "full");
});
beforeEach(() => {
mockConfig({
posthog: {
api_host: "https://api.example.com.localhost",
api_key: "api_key",
},
});
PosthogAnalytics.resetInstance();
});
afterAll(() => {
vi.unstubAllEnvs();
});
it("drops $initial_person_info from event properties", () => {
const initSpy = vi.spyOn(posthog, "init");
expect(PosthogAnalytics.instance.isEnabled()).toBe(true);
const sanitize = initSpy.mock.calls[0][1]?.sanitize_properties;
expect(sanitize).toBeDefined();
const sanitized = sanitize!(
{
$current_url: "https://call.example.com/some/private/path",
$initial_person_info: {
r: "https://example.com/referrer",
u: "https://call.example.com/some/private/path",
},
} as Properties,
"anyEvent",
);
expect(sanitized).not.toHaveProperty("$initial_person_info");
});
});
});

View File

@@ -173,6 +173,9 @@ export class PosthogAnalytics {
.slice(0, 3)
.join("");
// drop $initial_person_info for increased privacy.
delete properties["$initial_person_info"];
return properties;
};