Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(analytics): track home footer menu clicks and exposure (#16088)

AmAzing-25d582827c83
diff --git a/src/routes/(main)/home/_layout/Footer/index.test.tsx b/src/routes/(main)/home/_layout/Footer/index.test.tsx
index 20f2e025c00..664df45b3ef 100644
--- a/src/routes/(main)/home/_layout/Footer/index.test.tsx
+++ b/src/routes/(main)/home/_layout/Footer/index.test.tsx
@@ -32,10 +32,12 @@ vi.mock('react-i18next', () => ({
interface RenderFooterOptions {
agentFinished?: boolean;
agentStarted?: boolean;
+ billboardItems?: unknown[];
classicFinished?: boolean;
desktop?: boolean;
enableBusinessFeatures?: boolean;
enabled?: boolean;
+ homeSidebar?: boolean;
mobile?: boolean;
readSlugs?: string[];
serverConfigInit?: boolean;
@@ -68,10 +70,12 @@ const createGlobalState = (readSlugs: string[] = []) => ({
const renderFooter = async ({
agentFinished = false,
agentStarted = false,
+ billboardItems = [],
classicFinished = true,
desktop = false,
enabled = true,
enableBusinessFeatures = false,
+ homeSidebar = false,
mobile = false,
readSlugs = [],
serverConfigInit = true,
@@ -160,7 +164,10 @@ const renderFooter = async ({
default: () => null,
}));
vi.doMock('@/features/Billboard/MenuItems', () => ({
- useBillboardMenuItems: () => [],
+ useBillboardMenuItems: () => billboardItems,
+ }));
+ vi.doMock('@/features/NavPanel', () => ({
+ useActiveNavKey: () => (homeSidebar ? 'home' : 'discover'),
}));
vi.doMock('@/features/User/UserPanel/ThemeButton', () => ({
default: () => null,
@@ -234,6 +241,7 @@ afterEach(() => {
vi.doUnmock('@/components/HighlightNotification');
vi.doUnmock('@/features/Billboard');
vi.doUnmock('@/features/Billboard/MenuItems');
+ vi.doUnmock('@/features/NavPanel');
vi.doUnmock('@/features/User/UserPanel/ThemeButton');
vi.doUnmock('@/features/Workspace/WorkspaceLink');
vi.doUnmock('@/hooks/useNavLayout');
@@ -318,3 +326,61 @@ describe('Footer agent onboarding promotion', () => {
expect(screen.queryByTestId('highlight-notification')).not.toBeInTheDocument();
});
});
+
+describe('Footer help menu tracking', () => {
+ it('tracks menu open with the visible item keys', async () => {
+ const user = userEvent.setup();
+ await renderFooter({ enableBusinessFeatures: true });
+
+ await user.click(screen.getByRole('button', { name: 'Help' }));
+
+ const openedCall = analyticsTrack.mock.calls.find(
+ ([event]) => event?.name === 'home_footer_menu_opened',
+ );
+ expect(openedCall).toBeTruthy();
+ expect((openedCall![0].properties.keys as string).split(',')).toContain('inviteFriend');
+ }, 20000);
+
+ it('tracks a unified click event when the invite friend entry is clicked', async () => {
+ const user = userEvent.setup();
+ await renderFooter({ enableBusinessFeatures: true });
+
+ await user.click(screen.getByRole('button', { name: 'Help' }));
+ await user.click(await screen.findByText('Invite a friend'));
+
+ expect(analyticsTrack).toHaveBeenCalledWith({
+ name: 'home_footer_menu_clicked',
+ properties: { key: 'inviteFriend', spm: 'homepage.footer.inviteFriend.clicked' },
+ });
+ }, 20000);
+
+ it('does not render the invite friend entry without business features', async () => {
+ const user = userEvent.setup();
+ await renderFooter({ enableBusinessFeatures: false });
+
+ await user.click(screen.getByRole('button', { name: 'Help' }));
+
+ expect(screen.queryByText('Invite a friend')).not.toBeInTheDocument();
+ }, 20000);
+
+ it('excludes billboard items from the opened keys to keep per-key CTR aligned', async () => {
+ const user = userEvent.setup();
+ await renderFooter({
+ billboardItems: [{ key: 'billboard-promo', label: 'Promo', onClick: vi.fn() }],
+ enableBusinessFeatures: true,
+ homeSidebar: true,
+ });
+
+ await user.click(screen.getByRole('button', { name: 'Help' }));
+
+ const openedCall = analyticsTrack.mock.calls.find(
+ ([event]) => event?.name === 'home_footer_menu_opened',
+ );
+ const keys = (openedCall![0].properties.keys as string).split(',');
+ // own items are tracked and reported as exposure...
+ expect(keys).toContain('inviteFriend');
+ // ...but billboard items (which emit their own billboard_* events) are not,
+ // so their CTR denominator never gets an orphaned exposure.
+ expect(keys).not.toContain('billboard-promo');
+ }, 20000);
+});
diff --git a/src/routes/(main)/home/_layout/Footer/index.tsx b/src/routes/(main)/home/_layout/Footer/index.tsx
index 2e0aca80352..3c5e8d83374 100644
--- a/src/routes/(main)/home/_layout/Footer/index.tsx
+++ b/src/routes/(main)/home/_layout/Footer/index.tsx
@@ -63,6 +63,45 @@ interface PromotionCard {
title: string;
}
+type FooterMenuItems = NonNullable<MenuProps['items']>;
+
+/**
+ * Wrap each clickable menu item with a unified click tracker, preserving any
+ * existing onClick. Skips dividers and items without a key. Used to measure
+ * which footer menu entries get clicked (breakdown by `key`).
+ */
+const injectMenuTracking = (
+ items: FooterMenuItems,
+ track: (key: string) => void,
+): FooterMenuItems =>
+ items.map((item) => {
+ if (!item || (item as { type?: string }).type === 'divider') return item;
+ const key = (item as { key?: string | number }).key;
+ if (!key) return item;
+ const originalOnClick = (item as { onClick?: (info: unknown) => void }).onClick;
+ return {
+ ...item,
+ onClick: (info: unknown) => {
+ track(String(key));
+ originalOnClick?.(info);
+ },
+ };
+ });
+
+/**
+ * Collect the keys of click-trackable items — the exact same set wrapped by
+ * `injectMenuTracking` (non-divider items with a key). Used so the menu-open
+ * exposure event reports only keys that can later emit `home_footer_menu_clicked`,
+ * keeping per-key CTR denominators and numerators aligned. Billboard items are
+ * excluded here (they emit their own `billboard_*` events).
+ */
+const collectMenuKeys = (items: FooterMenuItems): string[] =>
+ items
+ .filter((item) => item && (item as { type?: string }).type !== 'divider')
+ .map((item) => (item as { key?: string | number }).key)
+ .filter((key): key is string | number => Boolean(key))
+ .map(String);
+
const Footer = memo(() => {
const { t } = useTranslation('common');
const navigate = useNavigate();
@@ -139,6 +178,20 @@ const Footer = memo(() => {
[analytics],
);
+ const trackMenuClick = useCallback(
+ (key: string) => {
+ try {
+ analytics?.track({
+ name: 'home_footer_menu_clicked',
+ properties: { key, spm: `homepage.footer.${key}.clicked` },
+ });
+ } catch {
+ // silently ignore tracking errors to avoid affecting business logic
+ }
+ },
+ [analytics],
+ );
+
const markNotificationRead = useCallback(
(slug: string) => {
const currentSlugs = useGlobalStore.getState().status.readNotificationSlugs || [];
@@ -252,8 +305,11 @@ const Footer = memo(() => {
t,
]);
- const helpMenuItems: MenuProps['items'] = useMemo(
- () => [
+ const { helpMenuItems, trackedMenuKeys } = useMemo<{
+ helpMenuItems: MenuProps['items'];
+ trackedMenuKeys: string[];
+ }>(() => {
+ const ownItems: FooterMenuItems = [
...(footer.showSettingsEntry && !isDevMode
? [
{
@@ -342,25 +398,47 @@ const Footer = memo(() => {
},
]
: []),
- ...(isHomeSidebar && billboardMenuItems && billboardMenuItems.length > 0
- ? [{ type: 'divider' as const }, ...billboardMenuItems]
- : []),
- ],
- [
- footer.showSettingsEntry,
- footer.layout,
- footer.hideGitHub,
- footer.showEvalEntry,
- enableBusinessFeatures,
- handleOpenChangelogModal,
- handleOpenFeedbackModal,
- handleOpenProductHuntCard,
- isDevMode,
- shouldShowProductHuntMenuEntry,
- t,
- billboardMenuItems,
- isHomeSidebar,
- ],
+ ];
+
+ return {
+ helpMenuItems: [
+ ...injectMenuTracking(ownItems, trackMenuClick),
+ ...(isHomeSidebar && billboardMenuItems && billboardMenuItems.length > 0
+ ? [{ type: 'divider' as const }, ...billboardMenuItems]
+ : []),
+ ],
+ trackedMenuKeys: collectMenuKeys(ownItems),
+ };
+ }, [
+ trackMenuClick,
+ footer.showSettingsEntry,
+ footer.layout,
+ footer.hideGitHub,
+ footer.showEvalEntry,
+ enableBusinessFeatures,
+ handleOpenChangelogModal,
+ handleOpenFeedbackModal,
+ handleOpenProductHuntCard,
+ isDevMode,
+ shouldShowProductHuntMenuEntry,
+ t,
+ billboardMenuItems,
+ isHomeSidebar,
+ ]);
+
+ const handleMenuOpenChange = useCallback(
+ (open: boolean) => {
+ if (!open) return;
+ try {
+ analytics?.track({
+ name: 'home_footer_menu_opened',
+ properties: { keys: trackedMenuKeys.join(','), spm: 'homepage.footer.opened' },
+ });
+ } catch {
+ // silently ignore tracking errors to avoid affecting business logic
+ }
+ },
+ [analytics, trackedMenuKeys],
);
return (
@@ -368,7 +446,11 @@ const Footer = memo(() => {
{footer.layout === 'expanded' ? (
<Flexbox horizontal align={'center'} gap={2} justify={'space-between'} padding={8}>
<Flexbox horizontal align={'center'} flex={1} gap={2}>
- <DropdownMenu items={helpMenuItems} placement="topLeft">
+ <DropdownMenu
+ items={helpMenuItems}
+ placement="topLeft"
+ onOpenChange={handleMenuOpenChange}
+ >
<ActionIcon
aria-label={t('userPanel.help')}
data-billboard-anchor=""
@@ -389,7 +471,11 @@ const Footer = memo(() => {
</Flexbox>
) : (
<Flexbox horizontal align={'center'} gap={2} padding={8}>
- <DropdownMenu items={helpMenuItems} placement="topLeft">
+ <DropdownMenu
+ items={helpMenuItems}
+ placement="topLeft"
+ onOpenChange={handleMenuOpenChange}
+ >
<ActionIcon aria-label={t('userPanel.help')} icon={CircleHelp} size={16} />
</DropdownMenu>
{isDevMode && (