Skip to content

Commit

Permalink
feat(web): Record time slider interactions with plausible (#6707)
Browse files Browse the repository at this point in the history
* feat(web): Record time slider interactions with plausible

* feat(web): include time average in time slider tracking

* feat(web): improve format
  • Loading branch information
tonypls committed May 2, 2024
1 parent 501dcc9 commit 6421e87
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion web/src/components/TimeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { scaleLinear } from 'd3-scale';
import { useNightTimes } from 'hooks/nightTimes';
import { useDarkMode } from 'hooks/theme';
import { useAtom } from 'jotai/react';
import trackEvent from 'utils/analytics';
import { TimeAverages } from 'utils/constants';
import { getZoneFromPath } from 'utils/helpers';
import { timeAverageAtom } from 'utils/state/atoms';
Expand Down Expand Up @@ -71,6 +72,12 @@ export const getThumbIcon = (
return isValueAtNight ? 'slider-thumb-night.svg' : 'slider-thumb-day.svg';
};

function trackTimeSliderEvent(selectedIndex: number, timeAverage: TimeAverages) {
trackEvent('Time Slider Button Interaction', {
selectedIndex: `${timeAverage}: ${selectedIndex}`,
});
}

export type TimeSliderBasicProps = TimeSliderProps & {
trackBackground: string;
thumbIcon: ThumbIconPath;
Expand All @@ -82,13 +89,17 @@ export function TimeSliderBasic({
trackBackground,
thumbIcon,
}: TimeSliderBasicProps) {
const [timeAverage] = useAtom(timeAverageAtom);
return (
<SliderPrimitive.Root
defaultValue={[0]}
max={numberOfEntries}
step={1}
value={selectedIndex && selectedIndex > 0 ? [selectedIndex] : [0]}
onValueChange={(value) => onChange(value[0])}
onValueChange={(value) => {
onChange(value[0]);
trackTimeSliderEvent(value[0], timeAverage);
}}
aria-label="choose time"
className="relative mb-2 flex h-5 w-full touch-none items-center hover:cursor-pointer"
>
Expand Down

0 comments on commit 6421e87

Please sign in to comment.