Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixpanel - add Theme parameter to Page view event #2193

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/mixpanel/useLogPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import type { ColorMode } from '@chakra-ui/react';
import { useColorMode } from '@chakra-ui/react';
import { usePathname } from 'next/navigation';
import { useRouter } from 'next/router';
import React from 'react';

import config from 'configs/app';
import * as cookies from 'lib/cookies';
import getQueryParamString from 'lib/router/getQueryParamString';
import { COLOR_THEMES } from 'lib/settings/colorTheme';

import getPageType from './getPageType';
import getTabName from './getTabName';
import logEvent from './logEvent';
import { EventTypes } from './utils';

function getColorTheme(hex: string | undefined, colorMode: ColorMode) {
const colorTheme = COLOR_THEMES.find((theme) => theme.hex === hex) ||
COLOR_THEMES.filter((theme) => theme.colorMode === colorMode).slice(-1)[0];

return colorTheme.id;
}

export default function useLogPageView(isInited: boolean) {
const router = useRouter();
const pathname = usePathname();
Expand All @@ -24,11 +34,14 @@ export default function useLogPageView(isInited: boolean) {
return;
}

const cookieColorModeHex = cookies.get(cookies.NAMES.COLOR_MODE_HEX);

logEvent(EventTypes.PAGE_VIEW, {
'Page type': getPageType(router.pathname),
Tab: getTabName(tab),
Page: page || undefined,
'Color mode': colorMode,
'Color theme': getColorTheme(cookieColorModeHex, colorMode),
});
// these are only deps that should trigger the effect
// in some scenarios page type is not changing (e.g navigation from one address page to another),
Expand Down
2 changes: 2 additions & 0 deletions lib/mixpanel/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { WalletType } from 'types/client/wallets';
import type { ColorThemeId } from 'types/settings';

export enum EventTypes {
PAGE_VIEW = 'Page view',
Expand Down Expand Up @@ -31,6 +32,7 @@ Type extends EventTypes.PAGE_VIEW ?
'Tab': string;
'Page'?: string;
'Color mode': 'light' | 'dark';
'Color theme': ColorThemeId | undefined;
} :
Type extends EventTypes.SEARCH_QUERY ? {
'Search query': string;
Expand Down
Loading