Skip to content

Commit

Permalink
chore: timeline plausible tracking (#8338)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleek authored Oct 3, 2024
1 parent c1dde76 commit 9b1d9f5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 (
<StyledEvent position={position}>
<StyledEvent position={position} onMouseEnter={trackHover}>
<HtmlTooltip
title={<EventTimelineEventTooltip group={group} />}
maxWidth={350}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => ({
Expand Down Expand Up @@ -50,6 +51,7 @@ export const EventTimelineHeader = ({
() => environments.filter(({ enabled }) => enabled),
[environments],
);
const { trackEvent } = usePlausibleTracker();

useEffect(() => {
if (activeEnvironments.length > 0 && !environment) {
Expand Down Expand Up @@ -117,7 +119,10 @@ export const EventTimelineHeader = ({
<IconButton
aria-label='close'
size='small'
onClick={() => setOpen(false)}
onClick={() => {
trackEvent('event-timeline-close');
setOpen(false);
}}
>
<CloseIcon />
</IconButton>
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/component/menu/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -197,9 +199,14 @@ const Header = () => {
arrow
>
<StyledIconButton
onClick={() =>
setShowTimeline(!showTimeline)
}
onClick={() => {
trackEvent(
showTimeline
? 'event-timeline-close'
: 'event-timeline-open',
);
setShowTimeline(!showTimeline);
}}
size='large'
>
<LinearScaleIcon />
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/hooks/usePlausibleTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9b1d9f5

Please sign in to comment.