mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 11:06:25 +08:00
chore(core): add mixpanel track (#6202)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export * from './create-emotion-cache';
|
||||
export * from './intl-formatter';
|
||||
export * from './mixpanel';
|
||||
export * from './string2color';
|
||||
export * from './toast';
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import mixpanelBrowser, { type OverridedMixpanel } from 'mixpanel-browser';
|
||||
|
||||
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, property) => {
|
||||
return new Proxy(
|
||||
function () {} as unknown as OverridedMixpanel,
|
||||
createProxyHandler(property)
|
||||
);
|
||||
},
|
||||
apply: (_target, _thisArg, args) => {
|
||||
console.info(
|
||||
`Mixpanel is not initialized, calling ${property ? String(property) : 'mixpanel'} with args: ${JSON.stringify(args)}`
|
||||
);
|
||||
},
|
||||
} as ProxyHandler<OverridedMixpanel>;
|
||||
return handler;
|
||||
}
|
||||
Reference in New Issue
Block a user