From 8af064b663784d23afa818e001a34abe59cfd343 Mon Sep 17 00:00:00 2001 From: pengx17 Date: Sun, 12 May 2024 12:39:59 +0000 Subject: [PATCH] fix: should not reset identity on app start (#6895) --- .../modules/telemetry/services/telemetry.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/frontend/core/src/modules/telemetry/services/telemetry.ts b/packages/frontend/core/src/modules/telemetry/services/telemetry.ts index da55a8e04f..c2bb5832c8 100644 --- a/packages/frontend/core/src/modules/telemetry/services/telemetry.ts +++ b/packages/frontend/core/src/modules/telemetry/services/telemetry.ts @@ -7,10 +7,12 @@ import { type AuthAccountInfo, type AuthService, } from '../../cloud'; +import { AccountLoggedOut } from '../../cloud/services/auth'; import { UserQuotaChanged } from '../../cloud/services/user-quota'; @OnEvent(ApplicationStarted, e => e.onApplicationStart) -@OnEvent(AccountChanged, e => e.onAccountChanged) +@OnEvent(AccountChanged, e => e.updateIdentity) +@OnEvent(AccountLoggedOut, e => e.onAccountLoggedOut) @OnEvent(UserQuotaChanged, e => e.onUserQuotaChanged) export class TelemetryService extends Service { private prevQuota: NonNullable['quota'] | null = @@ -28,21 +30,23 @@ export class TelemetryService extends Service { }); } const account = this.auth.session.account$.value; - this.onAccountChanged(account); + this.updateIdentity(account); } - onAccountChanged(account: AuthAccountInfo | null) { - if (account === null) { - mixpanel.reset(); - } else { - mixpanel.reset(); - mixpanel.identify(account.id); - mixpanel.people.set({ - $email: account.email, - $name: account.label, - $avatar: account.avatar, - }); + updateIdentity(account: AuthAccountInfo | null) { + if (!account) { + return; } + mixpanel.identify(account.id); + mixpanel.people.set({ + $email: account.email, + $name: account.label, + $avatar: account.avatar, + }); + } + + onAccountLoggedOut() { + mixpanel.reset(); } onUserQuotaChanged(quota: NonNullable['quota']) {