feat(infra): framework
This commit is contained in:
8
packages/frontend/core/src/modules/telemetry/index.ts
Normal file
8
packages/frontend/core/src/modules/telemetry/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { Framework } from '@toeverything/infra';
|
||||
|
||||
import { AuthService } from '../cloud';
|
||||
import { TelemetryService } from './services/telemetry';
|
||||
|
||||
export function configureTelemetryModule(framework: Framework) {
|
||||
framework.service(TelemetryService, [AuthService]);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { mixpanel } from '@affine/core/utils';
|
||||
import { ApplicationStarted, OnEvent, Service } from '@toeverything/infra';
|
||||
|
||||
import {
|
||||
AccountChanged,
|
||||
type AuthAccountInfo,
|
||||
type AuthService,
|
||||
} from '../../cloud';
|
||||
|
||||
@OnEvent(ApplicationStarted, e => e.onApplicationStart)
|
||||
@OnEvent(AccountChanged, e => e.onAccountChanged)
|
||||
export class TelemetryService extends Service {
|
||||
constructor(private readonly auth: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
onApplicationStart() {
|
||||
const account = this.auth.session.account$.value;
|
||||
if (account) {
|
||||
mixpanel.identify(account.id);
|
||||
}
|
||||
}
|
||||
|
||||
onAccountChanged(account: AuthAccountInfo | null) {
|
||||
if (account === null) {
|
||||
mixpanel.reset();
|
||||
} else {
|
||||
mixpanel.reset();
|
||||
mixpanel.identify(account.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user