Commit 2c18ad2f authored by tom's avatar tom

manually generate uuid

parent 88dc01d5
...@@ -13,7 +13,8 @@ export enum NAMES { ...@@ -13,7 +13,8 @@ export enum NAMES {
INDEXING_ALERT='indexing_alert', INDEXING_ALERT='indexing_alert',
ADBLOCK_DETECTED='adblock_detected', ADBLOCK_DETECTED='adblock_detected',
MIXPANEL_DEBUG='_mixpanel_debug', MIXPANEL_DEBUG='_mixpanel_debug',
ADDRESS_NFT_DISPLAY_TYPE='address_nft_display_type' ADDRESS_NFT_DISPLAY_TYPE='address_nft_display_type',
UUID='uuid',
} }
export function get(name?: NAMES | undefined | null, serverCookie?: string) { export function get(name?: NAMES | undefined | null, serverCookie?: string) {
......
import { GrowthBook } from '@growthbook/growthbook-react'; import { GrowthBook } from '@growthbook/growthbook-react';
import mixpanel from 'mixpanel-browser';
import config from 'configs/app'; import config from 'configs/app';
import * as mixpanel from 'lib/mixpanel';
export const growthBook = (() => { export const growthBook = (() => {
const feature = config.features.growthBook; const feature = config.features.growthBook;
...@@ -14,11 +14,15 @@ export const growthBook = (() => { ...@@ -14,11 +14,15 @@ export const growthBook = (() => {
apiHost: 'https://cdn.growthbook.io', apiHost: 'https://cdn.growthbook.io',
clientKey: feature.clientKey, clientKey: feature.clientKey,
enableDevMode: config.app.isDev, enableDevMode: config.app.isDev,
attributes: {
id: mixpanel.getUuid(),
chain_id: config.chain.id,
},
trackingCallback: (experiment, result) => { trackingCallback: (experiment, result) => {
mixpanel.track('$experiment_started', { mixpanel.logEvent(mixpanel.EventTypes.EXPERIMENT_STARTED, {
'Experiment name': experiment.key, 'Experiment name': experiment.key,
'Variant name': result.variationId, 'Variant name': result.value,
$source: 'growthbook', Source: 'growthbook',
}); });
}, },
}); });
......
import * as cookies from 'lib/cookies';
export default function getUuid() {
const cookie = cookies.get(cookies.NAMES.UUID);
if (cookie) {
return cookie;
}
const uuid = crypto.randomUUID();
cookies.set(cookies.NAMES.UUID, uuid);
return uuid;
}
import getPageType from './getPageType'; import getPageType from './getPageType';
import getUuid from './getUuid';
import logEvent from './logEvent'; import logEvent from './logEvent';
import useInit from './useInit'; import useInit from './useInit';
import useLogPageView from './useLogPageView'; import useLogPageView from './useLogPageView';
...@@ -9,4 +10,5 @@ export { ...@@ -9,4 +10,5 @@ export {
useLogPageView, useLogPageView,
logEvent, logEvent,
getPageType, getPageType,
getUuid,
}; };
...@@ -10,6 +10,8 @@ import * as cookies from 'lib/cookies'; ...@@ -10,6 +10,8 @@ import * as cookies from 'lib/cookies';
import { growthBook } from 'lib/growthbook/init'; import { growthBook } from 'lib/growthbook/init';
import getQueryParamString from 'lib/router/getQueryParamString'; import getQueryParamString from 'lib/router/getQueryParamString';
import getUuid from './getUuid';
export default function useMixpanelInit() { export default function useMixpanelInit() {
const [ isInited, setIsInited ] = React.useState(false); const [ isInited, setIsInited ] = React.useState(false);
const router = useRouter(); const router = useRouter();
...@@ -25,13 +27,11 @@ export default function useMixpanelInit() { ...@@ -25,13 +27,11 @@ export default function useMixpanelInit() {
const mixpanelConfig: Partial<Config> = { const mixpanelConfig: Partial<Config> = {
debug: Boolean(debugFlagQuery.current || debugFlagCookie), debug: Boolean(debugFlagQuery.current || debugFlagCookie),
loaded: function(mixpanel) { loaded: function() {
growthBook?.setAttributes({ growthBook?.setAttributes({
...growthBook.getAttributes(), ...growthBook.getAttributes(),
id: mixpanel.get_distinct_id(),
time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone, time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
language: mixpanel.get_property('Language'), language: window.navigator.language,
chain_id: mixpanel.get_property('Chain id'),
}); });
}, },
}; };
...@@ -46,6 +46,7 @@ export default function useMixpanelInit() { ...@@ -46,6 +46,7 @@ export default function useMixpanelInit() {
'Viewport height': window.innerHeight, 'Viewport height': window.innerHeight,
Language: window.navigator.language, Language: window.navigator.language,
'Device type': _capitalize(deviceType), 'Device type': _capitalize(deviceType),
'User id': getUuid(),
}); });
setIsInited(true); setIsInited(true);
......
...@@ -13,7 +13,8 @@ export enum EventTypes { ...@@ -13,7 +13,8 @@ export enum EventTypes {
CONTRACT_VERIFICATION = 'Contract verification', CONTRACT_VERIFICATION = 'Contract verification',
QR_CODE = 'QR code', QR_CODE = 'QR code',
PAGE_WIDGET = 'Page widget', PAGE_WIDGET = 'Page widget',
TX_INTERPRETATION_INTERACTION = 'Transaction interpratetion interaction' TX_INTERPRETATION_INTERACTION = 'Transaction interpratetion interaction',
EXPERIMENT_STARTED = 'Experiment started',
} }
/* eslint-disable @typescript-eslint/indent */ /* eslint-disable @typescript-eslint/indent */
...@@ -82,5 +83,10 @@ Type extends EventTypes.PAGE_WIDGET ? { ...@@ -82,5 +83,10 @@ Type extends EventTypes.PAGE_WIDGET ? {
Type extends EventTypes.TX_INTERPRETATION_INTERACTION ? { Type extends EventTypes.TX_INTERPRETATION_INTERACTION ? {
'Type': 'Address click' | 'Token click'; 'Type': 'Address click' | 'Token click';
} : } :
Type extends EventTypes.EXPERIMENT_STARTED ? {
'Experiment name': string;
'Variant name': string;
'Source': 'growthbook';
} :
undefined; undefined;
/* eslint-enable @typescript-eslint/indent */ /* eslint-enable @typescript-eslint/indent */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment