11"use client"
22
3+ import { sendGAEvent } from "@next/third-parties/google"
34import { motion , useCycle } from "motion/react"
45import { useMemo } from "react"
56import { makeStyles } from "tss-react/mui"
@@ -17,6 +18,7 @@ interface ScrollButtonProps extends Omit<ButtonProps, "color"> {
1718 disabled ?: boolean
1819 whiteButton ?: boolean
1920 download ?: boolean
21+ gaEvent ?: { event : string ; label : string }
2022
2123 // compatibility
2224 target ?: string
@@ -154,7 +156,7 @@ const maskMobile = {
154156 } ,
155157}
156158const Button = ( props : ScrollButtonProps ) => {
157- const { id, className, width, sx, color, loading, disabled, gloomy, children, whiteButton, ...restProps } = props
159+ const { id, className, width, sx, color, loading, disabled, gloomy, children, whiteButton, gaEvent , onClick , ...restProps } = props
158160 const { classes, cx } = useStyles ( {
159161 color,
160162 width,
@@ -176,6 +178,16 @@ const Button = (props: ScrollButtonProps) => {
176178 setIsHover ( )
177179 }
178180
181+ const handleClick = e => {
182+ if ( gaEvent ) {
183+ const { event, ...props } = gaEvent
184+ sendGAEvent ( "event" , event , { ...props } )
185+ }
186+ if ( onClick ) {
187+ onClick ( e )
188+ }
189+ }
190+
179191 return (
180192 // TODO: allow sx, allow size=small/medium
181193 // avoid setting both 'disabled' and 'loading' to true.
@@ -212,6 +224,7 @@ const Button = (props: ScrollButtonProps) => {
212224 ) ,
213225 } }
214226 disabled = { innerDisabled || gloomy || loading }
227+ onClick = { handleClick }
215228 { ...restProps }
216229 >
217230 { children } { loading && < CircularProgress sx = { { color : "inherit" } } size = { isMobile ? 18 : 24 } thickness = { 4 } > </ CircularProgress > }
0 commit comments