Skip to content

Commit

Permalink
add mixpanel event for swap button
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaleks committed Feb 27, 2024
1 parent d806732 commit c6133dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mixpanel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export enum EventTypes {
PAGE_WIDGET = 'Page widget',
TX_INTERPRETATION_INTERACTION = 'Transaction interpratetion interaction',
EXPERIMENT_STARTED = 'Experiment started',
FILTERS = 'Filters'
FILTERS = 'Filters',
BUTTON_CLICK = 'Button click',
}

/* eslint-disable @typescript-eslint/indent */
Expand Down Expand Up @@ -107,5 +108,9 @@ Type extends EventTypes.FILTERS ? {
'Source': 'Marketplace';
'Filter name': string;
} :
Type extends EventTypes.BUTTON_CLICK ? {
'Content': 'Swap button';
'Source': string;
} :
undefined;
/* eslint-enable @typescript-eslint/indent */
11 changes: 11 additions & 0 deletions ui/snippets/topBar/SwapButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { Button, Box } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import React from 'react';

import { route } from 'nextjs-routes';

import config from 'configs/app';
import getPageType from 'lib/mixpanel/getPageType';
import * as mixpanel from 'lib/mixpanel/index';
import IconSvg from 'ui/shared/IconSvg';

const feature = config.features.swapButton;

const SwapButton = () => {
const router = useRouter();
const source = getPageType(router.pathname);

const handleClick = React.useCallback(() => {
mixpanel.logEvent(mixpanel.EventTypes.BUTTON_CLICK, { Content: 'Swap button', Source: source });
}, [ source ]);

if (!feature.isEnabled) {
return null;
}
Expand All @@ -27,6 +37,7 @@ const SwapButton = () => {
borderRadius="sm"
height={ 5 }
px={ 1.5 }
onClick={ handleClick }
>
<IconSvg name="swap" boxSize={ 3 } mr={{ base: 0, sm: 1 }}/>
<Box display={{ base: 'none', sm: 'inline' }}>
Expand Down

0 comments on commit c6133dc

Please sign in to comment.