35 lines
655 B
TypeScript
35 lines
655 B
TypeScript
// file: components/util-tracked-button.tsx
|
|
"use client";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import React from "react";
|
|
|
|
interface TrackedButtonProps extends React.ComponentProps<typeof Button> {
|
|
eventName: string;
|
|
}
|
|
|
|
|
|
export const TrackedButton = ({
|
|
eventName,
|
|
onClick,
|
|
children,
|
|
...rest
|
|
}: TrackedButtonProps) => {
|
|
const handleTrackedClick = (
|
|
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
) => {
|
|
if (window.umami) {
|
|
window.umami.track(eventName);
|
|
}
|
|
|
|
if (onClick) {
|
|
onClick(e);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Button onClick={handleTrackedClick} {...rest}>
|
|
{children}
|
|
</Button>
|
|
);
|
|
}; |