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

feat: add metrics to carousel banner #30405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ export enum MetaMetricsEventName {
BannerDisplay = 'Banner Display',
BannerCloseAll = 'Banner Close All',
BannerSelect = 'Banner Select',
BannerNavigated = 'Banner Navigated',
BridgeLinkClicked = 'Bridge Link Clicked',
BitcoinSupportToggled = 'Bitcoin Support Toggled',
BitcoinTestnetSupportToggled = 'Bitcoin Testnet Support Toggled',
Expand Down
27 changes: 26 additions & 1 deletion ui/components/multichain/carousel/carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useContext } from 'react';
import { Carousel as ResponsiveCarousel } from 'react-responsive-carousel';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { Box, BoxProps, BannerBase } from '../../component-library';
Expand All @@ -9,6 +9,11 @@ import {
FontWeight,
BorderColor,
} from '../../../helpers/constants/design-system';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import type { CarouselProps } from './carousel.types';
import { BANNER_STYLES, MAX_SLIDES } from './constants';
import {
Expand All @@ -31,6 +36,7 @@ export const Carousel = React.forwardRef(
) => {
const [selectedIndex, setSelectedIndex] = useState(0);
const t = useI18nContext();
const trackEvent = useContext(MetaMetricsContext);

const visibleSlides = slides
.filter((slide) => !slide.dismissed || slide.undismissable)
Expand Down Expand Up @@ -82,6 +88,25 @@ export const Carousel = React.forwardRef(
};

const handleChange = (index: number) => {
const previousSlide = visibleSlides[selectedIndex];
const nextSlide = visibleSlides[index];

// Only track navigation when there's an actual change
if (selectedIndex !== index) {
trackEvent({
event: MetaMetricsEventName.BannerNavigated,
category: MetaMetricsEventCategory.Banner,
properties: {
from_banner: previousSlide.id,
to_banner: nextSlide.id,
from_banner_title: previousSlide.title,
to_banner_title: nextSlide.title,
navigation_method:
Math.abs(selectedIndex - index) === 1 ? 'swipe' : 'dot',
},
});
}

setSelectedIndex(index);
};

Expand Down
Loading