From 76c782c64c2bd803d52bb1a9836d5ba3ced74120 Mon Sep 17 00:00:00 2001 From: James Salter Date: Wed, 15 Sep 2021 12:58:26 +0100 Subject: [PATCH] Remove all room data from tracking Always redact room fragments entirely; remove room utils --- src/PosthogAnalytics.ts | 22 +++------------------- test/PosthogAnalytics-test.ts | 15 --------------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/src/PosthogAnalytics.ts b/src/PosthogAnalytics.ts index ca0d321e7c..a5ddfbdad4 100644 --- a/src/PosthogAnalytics.ts +++ b/src/PosthogAnalytics.ts @@ -101,17 +101,13 @@ export async function getRedactedCurrentLocation( if (hash == "") { hashStr = ""; } else { - let [beforeFirstSlash, screen, ...parts] = hash.split("/"); + let [beforeFirstSlash, screen] = hash.split("/"); if (!whitelistedScreens.has(screen)) { screen = ""; } - for (let i = 0; i < parts.length; i++) { - parts[i] = anonymity === Anonymity.Anonymous ? `` : await hashHex(parts[i]); - } - - hashStr = `${beforeFirstSlash}/${screen}/${parts.join("/")}`; + hashStr = `${beforeFirstSlash}/${screen}/`; } return origin + pathname + hashStr; } @@ -133,7 +129,7 @@ export class PosthogAnalytics { * * To pass an event to Posthog: * - * 1. Declare a type for the event, extending IAnonymousEvent, IPseudonymousEvent or IRoomEvent. + * 1. Declare a type for the event, extending IAnonymousEvent or IPseudonymousEvent. * 2. Call the appropriate track*() method. Pseudonymous events will be dropped when anonymity is * Anonymous or Disabled; Anonymous events will be dropped when anonymity is Disabled. */ @@ -333,18 +329,6 @@ export class PosthogAnalytics { await this.capture(eventName, properties); } - public async trackRoomEvent( - eventName: E["eventName"], - roomId: string, - properties: Omit, - ): Promise { - const updatedProperties = { - ...properties, - hashedRoomId: roomId ? await hashHex(roomId) : null, - }; - await this.trackPseudonymousEvent(eventName, updatedProperties); - } - public async trackPageView(durationMs: number): Promise { const hash = window.location.hash; diff --git a/test/PosthogAnalytics-test.ts b/test/PosthogAnalytics-test.ts index 2832fbe92e..f8bf79702a 100644 --- a/test/PosthogAnalytics-test.ts +++ b/test/PosthogAnalytics-test.ts @@ -136,18 +136,6 @@ describe("PosthogAnalytics", () => { expect(fakePosthog.capture.mock.calls[0][1]["foo"]).toEqual("bar"); }); - it("Should pass trackRoomEvent to posthog", async () => { - analytics.setAnonymity(Anonymity.Pseudonymous); - const roomId = "42"; - await analytics.trackRoomEvent("jest_test_event", roomId, { - foo: "bar", - }); - expect(fakePosthog.capture.mock.calls[0][0]).toBe("jest_test_event"); - expect(fakePosthog.capture.mock.calls[0][1]["foo"]).toEqual("bar"); - expect(fakePosthog.capture.mock.calls[0][1]["hashedRoomId"]) - .toEqual("73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049"); - }); - it("Should pass trackPseudonymousEvent() to posthog", async () => { analytics.setAnonymity(Anonymity.Pseudonymous); await analytics.trackPseudonymousEvent("jest_test_pseudo_event", { @@ -173,9 +161,6 @@ describe("PosthogAnalytics", () => { await analytics.trackAnonymousEvent("jest_test_event", { foo: "bar", }); - await analytics.trackRoomEvent("room id", "foo", { - foo: "bar", - }); await analytics.trackPageView(200); expect(fakePosthog.capture.mock.calls.length).toBe(0); });