From 9b1d9f57d3483e409f5dc7a442f539f3fc2b9e33 Mon Sep 17 00:00:00 2001 From: David Leek Date: Thu, 3 Oct 2024 07:58:58 +0200 Subject: [PATCH] chore: timeline plausible tracking (#8338) --- .../EventTimelineEventGroup.tsx | 7 ++++++- .../EventTimelineHeader/EventTimelineHeader.tsx | 7 ++++++- frontend/src/component/menu/Header/Header.tsx | 13 ++++++++++--- frontend/src/hooks/usePlausibleTracker.ts | 5 ++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/frontend/src/component/events/EventTimeline/EventTimelineEventGroup/EventTimelineEventGroup.tsx b/frontend/src/component/events/EventTimeline/EventTimelineEventGroup/EventTimelineEventGroup.tsx index 14e6287837..638870814c 100644 --- a/frontend/src/component/events/EventTimeline/EventTimelineEventGroup/EventTimelineEventGroup.tsx +++ b/frontend/src/component/events/EventTimeline/EventTimelineEventGroup/EventTimelineEventGroup.tsx @@ -3,6 +3,7 @@ import { HtmlTooltip } from 'component/common/HtmlTooltip/HtmlTooltip'; import { EventTimelineEventTooltip } from './EventTimelineEventTooltip/EventTimelineEventTooltip'; import type { TimelineEventGroup } from '../EventTimeline'; import { EventTimelineEventCircle } from './EventTimelineEventCircle'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; const StyledEvent = styled('div', { shouldForwardProp: (prop) => prop !== 'position', @@ -27,13 +28,17 @@ export const EventTimelineEventGroup = ({ startTime, endTime, }: IEventTimelineEventProps) => { + const { trackEvent } = usePlausibleTracker(); const timelineDuration = endTime - startTime; const eventTime = group[0].timestamp; const position = `${((eventTime - startTime) / timelineDuration) * 100}%`; + const trackHover = () => { + trackEvent('event-timeline-event-hover'); + }; return ( - + } maxWidth={350} diff --git a/frontend/src/component/events/EventTimeline/EventTimelineHeader/EventTimelineHeader.tsx b/frontend/src/component/events/EventTimeline/EventTimelineHeader/EventTimelineHeader.tsx index c6218e50d6..b44f63c891 100644 --- a/frontend/src/component/events/EventTimeline/EventTimelineHeader/EventTimelineHeader.tsx +++ b/frontend/src/component/events/EventTimeline/EventTimelineHeader/EventTimelineHeader.tsx @@ -11,6 +11,7 @@ import { useEffect, useMemo } from 'react'; import { timeSpanOptions } from '../EventTimelineProvider'; import CloseIcon from '@mui/icons-material/Close'; import { useEventTimelineContext } from '../EventTimelineContext'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; import { EventTimelineHeaderTip } from './EventTimelineHeaderTip'; const StyledCol = styled('div')(({ theme }) => ({ @@ -50,6 +51,7 @@ export const EventTimelineHeader = ({ () => environments.filter(({ enabled }) => enabled), [environments], ); + const { trackEvent } = usePlausibleTracker(); useEffect(() => { if (activeEnvironments.length > 0 && !environment) { @@ -117,7 +119,10 @@ export const EventTimelineHeader = ({ setOpen(false)} + onClick={() => { + trackEvent('event-timeline-close'); + setOpen(false); + }} > diff --git a/frontend/src/component/menu/Header/Header.tsx b/frontend/src/component/menu/Header/Header.tsx index 53cb5e830d..40a36c2e19 100644 --- a/frontend/src/component/menu/Header/Header.tsx +++ b/frontend/src/component/menu/Header/Header.tsx @@ -35,6 +35,7 @@ import { useUiFlag } from 'hooks/useUiFlag'; import { CommandBar } from 'component/commandBar/CommandBar'; import LinearScaleIcon from '@mui/icons-material/LinearScale'; import { useEventTimelineContext } from 'component/events/EventTimeline/EventTimelineContext'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; const HeaderComponent = styled(AppBar)(({ theme }) => ({ backgroundColor: theme.palette.background.paper, @@ -111,6 +112,7 @@ const Header = () => { const eventTimeline = useUiFlag('eventTimeline') && !isOss(); const { open: showTimeline, setOpen: setShowTimeline } = useEventTimelineContext(); + const { trackEvent } = usePlausibleTracker(); const routes = getRoutes(); const adminRoutes = useAdminRoutes(); @@ -197,9 +199,14 @@ const Header = () => { arrow > - setShowTimeline(!showTimeline) - } + onClick={() => { + trackEvent( + showTimeline + ? 'event-timeline-close' + : 'event-timeline-open', + ); + setShowTimeline(!showTimeline); + }} size='large' > diff --git a/frontend/src/hooks/usePlausibleTracker.ts b/frontend/src/hooks/usePlausibleTracker.ts index 8ae1095310..7430cde70d 100644 --- a/frontend/src/hooks/usePlausibleTracker.ts +++ b/frontend/src/hooks/usePlausibleTracker.ts @@ -66,7 +66,10 @@ export type CustomEvents = | 'new-in-unleash-click' | 'new-in-unleash-dismiss' | 'search-opened' - | 'events-exported'; + | 'events-exported' + | 'event-timeline-open' + | 'event-timeline-close' + | 'event-timeline-event-hover'; export const usePlausibleTracker = () => { const plausible = useContext(PlausibleContext);