chore(core): add mixpanel track (#6202)

This commit is contained in:
Brooooooklyn
2024-03-22 09:24:40 +00:00
parent 10af0ab48d
commit 150c22936d
21 changed files with 229 additions and 67 deletions
@@ -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;
}