quivr/frontend/app/(home)/hooks/useHomepageTracking.ts
2023-10-24 13:55:42 +02:00

34 lines
759 B
TypeScript

import { useRouter } from "next/navigation";
import { MouseEvent } from "react";
import { useEventTracking } from "@/services/analytics/june/useEventTracking";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useHomepageTracking = () => {
const { track } = useEventTracking();
const router = useRouter();
const onLinkClick = ({
href,
label,
event,
}: {
href: string;
label: string;
event: MouseEvent<HTMLAnchorElement>;
}) => {
event.preventDefault();
void track(`HOMEPAGE-${label}`);
router.push(href);
};
const onButtonClick = ({ label }: { label: string }) => {
void track(`HOMEPAGE-${label}`);
};
return {
onLinkClick,
onButtonClick,
};
};