fix(core): event flow handle (#14256)

This commit is contained in:
DarkSky
2026-01-15 00:04:32 +08:00
committed by GitHub
parent 7c24b2521a
commit 13907f7234
18 changed files with 389 additions and 30 deletions

View File

@@ -1,4 +1,4 @@
import { mixpanel, track } from '@affine/track';
import { track, tracker } from '@affine/track';
import type { EditorHost } from '@blocksuite/affine/std';
import type { GfxPrimitiveElementModel } from '@blocksuite/affine/std/gfx';
import type { BlockModel } from '@blocksuite/affine/store';
@@ -73,7 +73,7 @@ const trackAction = ({
eventName: AIActionEventName;
properties: AIActionEventProperties;
}) => {
mixpanel.track(eventName, properties);
tracker.track(eventName, properties);
};
const inferPageMode = (host: EditorHost) => {

View File

@@ -24,7 +24,7 @@ import { AffineThemeViewExtension } from '@affine/core/blocksuite/view-extension
import { TurboRendererViewExtension } from '@affine/core/blocksuite/view-extensions/turbo-renderer';
import { PeekViewService } from '@affine/core/modules/peek-view';
import { DebugLogger } from '@affine/debug';
import { mixpanel } from '@affine/track';
import { tracker } from '@affine/track';
import { DatabaseViewExtension } from '@blocksuite/affine/blocks/database/view';
import { ParagraphViewExtension } from '@blocksuite/affine/blocks/paragraph/view';
import type {
@@ -162,7 +162,7 @@ class ViewProvider {
this._manager.configure(FoundationViewExtension, {
telemetry: {
track: (eventName, props) => {
mixpanel.track(eventName, props);
tracker.track(eventName, props);
},
},
fontConfig: AffineCanvasTextFonts.map(font => ({

View File

@@ -1,7 +1,7 @@
import { mixpanel, sentry } from '@affine/track';
import { ga4, sentry, tracker } from '@affine/track';
import { APP_SETTINGS_STORAGE_KEY } from '@toeverything/infra/atom';
mixpanel.init();
tracker.init();
sentry.init();
if (typeof localStorage !== 'undefined') {
@@ -18,5 +18,6 @@ if (typeof localStorage !== 'undefined') {
// see: https://docs.mixpanel.com/docs/privacy/protecting-user-data
// mixpanel.opt_out_tracking();
sentry.disable();
ga4.setEnabled(false);
}
}

View File

@@ -1,4 +1,4 @@
import { enableAutoTrack, mixpanel, sentry } from '@affine/track';
import { enableAutoTrack, sentry, tracker } from '@affine/track';
import { appSettingAtom } from '@toeverything/infra';
import { useAtomValue } from 'jotai/react';
import { useEffect } from 'react';
@@ -9,12 +9,12 @@ export function Telemetry() {
useEffect(() => {
if (settings.enableTelemetry === false) {
sentry.disable();
mixpanel.opt_out_tracking();
tracker.opt_out_tracking();
return;
} else {
sentry.enable();
mixpanel.opt_in_tracking();
return enableAutoTrack(document.body, mixpanel.track);
tracker.opt_in_tracking();
return enableAutoTrack(document.body, tracker.track);
}
}, [settings.enableTelemetry]);

View File

@@ -1,5 +1,5 @@
import { type CreateCheckoutSessionInput } from '@affine/graphql';
import { mixpanel } from '@affine/track';
import { tracker } from '@affine/track';
import { OnEvent, Service } from '@toeverything/infra';
import { Subscription } from '../entities/subscription';
@@ -18,7 +18,7 @@ export class SubscriptionService extends Service {
.map(sub => !!sub)
.distinctUntilChanged()
.subscribe(ai => {
mixpanel.people.set({
tracker.people.set({
ai,
});
});
@@ -26,7 +26,7 @@ export class SubscriptionService extends Service {
.map(sub => !!sub)
.distinctUntilChanged()
.subscribe(pro => {
mixpanel.people.set({
tracker.people.set({
pro,
});
});

View File

@@ -1,4 +1,4 @@
import { mixpanel } from '@affine/track';
import { tracker } from '@affine/track';
import { OnEvent, Service } from '@toeverything/infra';
import { UserQuota } from '../entities/user-quota';
@@ -13,7 +13,7 @@ export class UserQuotaService extends Service {
.map(q => q?.humanReadable.name)
.distinctUntilChanged()
.subscribe(quota => {
mixpanel.people.set({
tracker.people.set({
quota,
});
});

View File

@@ -1,6 +1,6 @@
import { shallowEqual } from '@affine/component';
import { ServerDeploymentType } from '@affine/graphql';
import { mixpanel } from '@affine/track';
import { tracker } from '@affine/track';
import { LiveData, OnEvent, Service } from '@toeverything/infra';
import type { AuthAccountInfo, Server, ServersService } from '../../cloud';
@@ -47,19 +47,19 @@ export class TelemetryService extends Service {
const unsubscribe = this.currentAccount$.subscribe(
({ account, selfHosted }) => {
if (prevAccount) {
mixpanel.reset();
tracker.reset();
}
// the isSelfHosted property from environment is not reliable
if (selfHosted !== prevSelfHosted) {
mixpanel.register({
tracker.register({
isSelfHosted: selfHosted,
});
}
prevSelfHosted = selfHosted;
prevAccount = account ?? null;
if (account) {
mixpanel.identify(account.id);
mixpanel.people.set({
tracker.identify(account.id);
tracker.people.set({
$email: account.email,
$name: account.label,
$avatar: account.avatar,
@@ -78,7 +78,7 @@ export class TelemetryService extends Service {
registerMiddlewares() {
this.disposables.push(
mixpanel.middleware((_event, parameters) => {
tracker.middleware((_event, parameters) => {
const extraContext = this.extractGlobalContext();
return {
...extraContext,

View File

@@ -1,4 +1,4 @@
import { mixpanel } from '@affine/track';
import { tracker } from '@affine/track';
import { createEvent, Service } from '@toeverything/infra';
import { combineLatest, distinctUntilChanged, map, skip } from 'rxjs';
@@ -19,7 +19,7 @@ export class WorkbenchService extends Service {
)
.subscribe(newLocation => {
this.eventBus.root.emit(WorkbenchLocationChanged, newLocation);
mixpanel.track_pageview({
tracker.track_pageview({
location: newLocation,
});
});