mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
feat(core): improve mixpanel (#7652)
move @affine/core/utils/mixpanel -> @affine/core/mixpanel now you can debug mixpanel on browser devtool 
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
export * from './create-emotion-cache';
|
||||
export * from './fractional-indexing';
|
||||
export * from './mixpanel';
|
||||
export * from './popup';
|
||||
export * from './string2color';
|
||||
export * from './toast';
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { OverridedMixpanel } from 'mixpanel-browser';
|
||||
import mixpanelBrowser from 'mixpanel-browser';
|
||||
|
||||
import type { MixpanelEvents } from '../mixpanel';
|
||||
|
||||
const logger = new DebugLogger('affine:mixpanel');
|
||||
|
||||
export const mixpanel = process.env.MIXPANEL_TOKEN
|
||||
? mixpanelBrowser
|
||||
: new Proxy(
|
||||
function () {} as unknown as OverridedMixpanel,
|
||||
createProxyHandler()
|
||||
);
|
||||
|
||||
function createProxyHandler(property?: string | symbol) {
|
||||
const handler = {
|
||||
get: (_target, childProperty) => {
|
||||
const path = property
|
||||
? String(property) + '.' + String(childProperty)
|
||||
: String(childProperty);
|
||||
return new Proxy(
|
||||
function () {} as unknown as OverridedMixpanel,
|
||||
createProxyHandler(path)
|
||||
);
|
||||
},
|
||||
apply: (_target, _thisArg, args) => {
|
||||
logger.debug(
|
||||
`mixpanel.${property ? String(property) : 'mixpanel'}`,
|
||||
...args
|
||||
);
|
||||
},
|
||||
} as ProxyHandler<OverridedMixpanel>;
|
||||
return handler;
|
||||
}
|
||||
|
||||
export function mixpanelTrack<T extends keyof MixpanelEvents>(
|
||||
event: T,
|
||||
properties?: MixpanelEvents[T]
|
||||
) {
|
||||
return mixpanel.track(event, properties);
|
||||
}
|
||||
Reference in New Issue
Block a user