Skip to content

Commit 56d0cfe

Browse files
authored
feat: [LW-11885] add analytics to dapp explorer (#1644)
* feat: add analytics to dapp explorer * fix: improve properties name
1 parent 37ffbe2 commit 56d0cfe

File tree

4 files changed

+34
-2
lines changed
  • apps/browser-extension-wallet/src/views/browser-view/features/dapp/explorer/components
  • packages/common/src/analytics

4 files changed

+34
-2
lines changed

apps/browser-extension-wallet/src/views/browser-view/features/dapp/explorer/components/ProjectDetail/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { Drawer, DrawerNavigation, Button } from '@lace/common';
3+
import { Drawer, DrawerNavigation, Button, PostHogAction } from '@lace/common';
44
import { Tabs } from 'antd';
55
import { EDrawerAction, useDrawer } from './drawer';
66
import { ISectionCardItem } from '../../services/helpers/apis-formatter/types';
@@ -11,6 +11,7 @@ import LinkIcon from '../../assets/icons/link.component.svg';
1111

1212
import './styles.scss';
1313
import { Flex, Text } from '@input-output-hk/lace-ui-toolkit';
14+
import { useAnalyticsContext } from '@providers';
1415

1516
const shortenURL = (url?: string) => {
1617
if (!url) return '';
@@ -23,13 +24,22 @@ const ProjectDetail: React.FC = () => {
2324
state: { open, data },
2425
dispatch
2526
} = useDrawer<ISectionCardItem>();
27+
const analytics = useAnalyticsContext();
2628

2729
const { t } = useTranslation();
2830

2931
const handleClose = () => dispatch({ type: EDrawerAction.CLOSE });
3032

3133
const handleOpenUrl = () => {
3234
window.open(data?.companyWebsite, 'blank');
35+
void analytics.sendEventToPostHog(PostHogAction.DappExplorerDetailDrawerRedirectClick, {
36+
// eslint-disable-next-line camelcase
37+
dapp_explorer_selected_category_name: data?.category,
38+
// eslint-disable-next-line camelcase
39+
dapp_explorer_selected_dapp_name: data?.title,
40+
// eslint-disable-next-line camelcase
41+
dapp_explorer_selected_dapp_url: data?.link
42+
});
3343
};
3444

3545
const tabItems = [

apps/browser-extension-wallet/src/views/browser-view/features/dapp/explorer/components/SimpleView/SimpleViewContent/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { Skeleton } from 'antd';
1010
import useInfiniteScroll from 'react-infinite-scroll-hook';
1111
import type { ISimpleViewContent } from './types';
1212
import './styles.scss';
13+
import { useAnalyticsContext } from '@providers';
14+
import { PostHogAction } from '@lace/common';
1315

1416
// Defines pagination parameters for infinite scroll mechanism.
1517
const MAX_ITEMS_PER_PAGE = 20;
@@ -26,9 +28,18 @@ const SimpleViewContent: React.FC<ISimpleViewContent> = ({ selectedCategory, sea
2628
page: { offset: 0, limit: MAX_ITEMS_PER_PAGE },
2729
search
2830
});
31+
const analytics = useAnalyticsContext();
2932

3033
const handleOpenDrawer = (drawerData: ISectionCardItem) => {
3134
dispatch({ type: EDrawerAction.OPEN, data: drawerData });
35+
void analytics.sendEventToPostHog(PostHogAction.DappExplorerDappTileClick, {
36+
// eslint-disable-next-line camelcase
37+
dapp_explorer_selected_category_name: drawerData?.category,
38+
// eslint-disable-next-line camelcase
39+
dapp_explorer_selected_dapp_name: drawerData?.title,
40+
// eslint-disable-next-line camelcase
41+
dapp_explorer_selected_dapp_url: drawerData?.link
42+
});
3243
};
3344

3445
const showEmptyState = !loading && dapps?.length === 0;

apps/browser-extension-wallet/src/views/browser-view/features/dapp/explorer/components/SimpleView/SimpleViewFilters/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import CategoryChip from './CategoryChip';
1010
import './styles.scss';
1111
import { useCategoriesFetcher } from '../../../services/api/categories';
1212
import { formatFiltersResponse } from '../../../services/helpers/apis-formatter';
13+
import { PostHogAction } from '@lace/common';
14+
import { useAnalyticsContext } from '@providers';
1315

1416
const { useState, useEffect } = React;
1517

@@ -18,6 +20,7 @@ const SimpleViewFilters: React.FC<ISimpleViewFilters> = ({ onChangeCategory }) =
1820
const location = useLocation();
1921
const [active, setActive] = useState<string>('all');
2022
const { t } = useTranslation();
23+
const analytics = useAnalyticsContext();
2124

2225
const ALL_CATEGORIES_FILTER = [
2326
{
@@ -57,6 +60,10 @@ const SimpleViewFilters: React.FC<ISimpleViewFilters> = ({ onChangeCategory }) =
5760
const handleSetActive = (value: string) => {
5861
setActive(value.toLowerCase());
5962
if (onChangeCategory) onChangeCategory(value);
63+
void analytics.sendEventToPostHog(PostHogAction.DappExplorerCategoryClick, {
64+
// eslint-disable-next-line camelcase
65+
dapp_explorer_selected_category_name: value
66+
});
6067

6168
history.push({
6269
search: value !== 'all' ? `category=${value}` : ''

packages/common/src/analytics/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ export enum PostHogAction {
311311
SharedWalletsSendSomethingWentWrongView = 'shared wallets | send | something went wrong | view',
312312
SharedWalletsSendSomethingWentWrongBackClick = 'shared wallets | send | something went wrong | back | click',
313313
SharedWalletsSendSomethingWentWrongCancelClick = 'shared wallets | send | something went wrong | cancel | click',
314-
SharedWalletsSendSomethingWentWrongXClick = 'shared wallets | send | something went wrong | x | click'
314+
SharedWalletsSendSomethingWentWrongXClick = 'shared wallets | send | something went wrong | x | click',
315+
// dapp explorer
316+
DappExplorerCategoryClick = 'dapp explorer | category | click',
317+
DappExplorerDappTileClick = 'dapp explorer | dapp tile | click',
318+
DappExplorerDetailDrawerRedirectClick = 'dapp explorer | detail drawer | redirect | click'
315319
}
316320

317321
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)