Skip to content

Commit

Permalink
chore(explorer): add google analytics for multiple events (#2434)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Jul 23, 2024
1 parent d1ebdcf commit 52c211c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-sheep-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/explorer': patch
---

add google analytics events for multiple actions
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ValueLoader } from '@/components/LoadingSkeleton/ValueLoader/ValueLoader';
import type { IBlockData } from '@/services/block';
import { EVENT_NAMES, analyticsEvent } from '@/utils/analytics';
import { Stack, Text } from '@kadena/kode-ui';
import classNames from 'classnames';
import type { FC } from 'react';
Expand Down Expand Up @@ -32,6 +33,12 @@ export const BlockCell: FC<IProps> = ({

const handleOpenHeight = useCallback(() => {
if (isLoading) return;

analyticsEvent(EVENT_NAMES['click:open_blockheightpopup'], {
chainId: `${height.chainId}`,
height: `${height.height}`,
});

if (handleOpenHeightBlock) {
handleOpenHeightBlock(chainId, height);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/apps/explorer/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Link } from '@/components/Routing/Link';
import { EVENT_NAMES, analyticsEvent } from '@/utils/analytics';
import { menuConfig } from '@/utils/menuConfig';
import {
MonoLogoGithub,
Expand Down Expand Up @@ -27,6 +28,12 @@ export const Footer: FC = () => {
const handleToggleContent = () => {
setIsOpen((v) => !v);
};

const handleAnalyticsForSocial = (social: string) => {
analyticsEvent(EVENT_NAMES['click:nav_sociallink'], {
social,
});
};
return (
<Stack
as="footer"
Expand Down Expand Up @@ -63,6 +70,7 @@ export const Footer: FC = () => {
<Heading as="h6">Socials</Heading>
<Stack gap="sm">
<a
onClick={() => handleAnalyticsForSocial('twitter')}
className={socialLinkClass}
href="https://x.com/kadena_io"
target="_blank"
Expand All @@ -72,6 +80,7 @@ export const Footer: FC = () => {
</a>

<a
onClick={() => handleAnalyticsForSocial('linkedin')}
className={socialLinkClass}
href="https://www.linkedin.com/company/kadena-llc/mycompany/"
target="_blank"
Expand All @@ -80,6 +89,7 @@ export const Footer: FC = () => {
<MonoLogoLinkedin />
</a>
<a
onClick={() => handleAnalyticsForSocial('github')}
className={socialLinkClass}
href="https://github.com/kadena-community"
target="_blank"
Expand Down
11 changes: 10 additions & 1 deletion packages/apps/explorer/src/components/Footer/FooterColumn.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EVENT_NAMES, analyticsEvent } from '@/utils/analytics';
import { Heading, Stack } from '@kadena/kode-ui';
import classNames from 'classnames';
import type { FC } from 'react';
Expand All @@ -11,6 +12,10 @@ interface IProps {
}

export const FooterColumn: FC<IProps> = ({ data, isOpen }) => {
const handleAnalyticsForClick = (item: { url: string; label: string }) => {
analyticsEvent(EVENT_NAMES['click:nav_footerlink'], item);
};

return (
<Stack
className={classNames(footerColumnClass, {
Expand All @@ -23,7 +28,11 @@ export const FooterColumn: FC<IProps> = ({ data, isOpen }) => {
>
<Heading as="h6">{data.label}</Heading>
{data.children.map((item) => (
<FooterLink key={item.url} href={item.url}>
<FooterLink
onClick={() => handleAnalyticsForClick(item)}
key={item.url}
href={item.url}
>
{item.label}
</FooterLink>
))}
Expand Down
5 changes: 3 additions & 2 deletions packages/apps/explorer/src/components/Footer/FooterLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { footerLinkClass } from './style.css';

interface IProps extends PropsWithChildren {
href: string;
onClick: () => void;
}

export const FooterLink: FC<IProps> = ({ href, children }) => {
export const FooterLink: FC<IProps> = ({ onClick, href, children }) => {
return (
<a className={footerLinkClass} href={href} target="_bank">
<a onClick={onClick} className={footerLinkClass} href={href} target="_bank">
<Text>{children}</Text>
</a>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useNetwork } from '@/context/networksContext';
import { useQueryContext } from '@/context/queryContext';
import { EVENT_NAMES, analyticsEvent } from '@/utils/analytics';
import { MonoHub } from '@kadena/kode-icons/system';
import {
Box,
Expand All @@ -21,17 +22,21 @@ import { code } from './styles.css';
export const GraphQLQueryDialog = (): JSX.Element => {
const { queries } = useQueryContext();
const { activeNetwork } = useNetwork();

const [isOpen, setIsOpen] = useState(false);

const handlePress = () => {
setIsOpen(true);
analyticsEvent(EVENT_NAMES['click:open_graphDialog'], {});
};

return (
<>
<Button
className={buttonSizeClass}
startVisual={<MonoHub />}
title="Show the GraphQL query used."
variant="transparent"
onPress={() => setIsOpen(true)}
onPress={handlePress}
></Button>
<Dialog
isOpen={isOpen}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useNetwork } from '@/context/networksContext';
import { EVENT_NAMES, analyticsEvent } from '@/utils/analytics';
import { MonoSettings } from '@kadena/kode-icons/system';
import { Button, Select, SelectItem, Stack } from '@kadena/kode-ui';
import type { FC } from 'react';
Expand All @@ -14,6 +15,11 @@ export const SelectNetwork: FC = () => {
setActiveNetwork(value);
};

const handlePress = () => {
setIsOpen(true);
analyticsEvent(EVENT_NAMES['click:open_configDialog'], {});
};

if (!networks) return null;

return (
Expand Down Expand Up @@ -42,7 +48,7 @@ export const SelectNetwork: FC = () => {
</Select>
</Media>
<Button
onPress={() => setIsOpen(true)}
onPress={handlePress}
variant="transparent"
endVisual={<MonoSettings />}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EVENT_NAMES, analyticsEvent } from '@/utils/analytics';
import { MonoContrast } from '@kadena/kode-icons';
import { Button, Themes, useTheme } from '@kadena/kode-ui';
import classNames from 'classnames';
Expand All @@ -21,6 +22,11 @@ export const ThemeToggle: FC = () => {

const toggleTheme = useCallback((): void => {
const newTheme = theme === Themes.dark ? Themes.light : Themes.dark;

analyticsEvent(EVENT_NAMES['click:switch_theme'], {
theme: newTheme,
});

setTheme(newTheme);
}, [setTheme, theme]);

Expand Down
6 changes: 6 additions & 0 deletions packages/apps/explorer/src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const EVENT_NAMES = {
'click:add_network': 'click:add_network',
'click:remove_network': 'click:remove_network',
'click:change_network': 'click:change_network',
'click:switch_theme': 'click:switch_theme',
'click:open_graphDialog': 'click:open_graphDialog',
'click:open_configDialog': 'click:open_configDialog',
'click:nav_sociallink': 'click:nav_sociallink',
'click:nav_footerlink': 'click:nav_footerlink',
'click:open_blockheightpopup': 'click:open_blockheightpopup',
'event:stopserver': 'event:stopserver',
} as const;

Expand Down

0 comments on commit 52c211c

Please sign in to comment.