1
1
"use client"
2
2
3
+ import { sendGAEvent } from "@next/third-parties/google"
3
4
import { motion , useCycle } from "motion/react"
4
5
import { useMemo } from "react"
5
6
import { makeStyles } from "tss-react/mui"
@@ -17,6 +18,7 @@ interface ScrollButtonProps extends Omit<ButtonProps, "color"> {
17
18
disabled ?: boolean
18
19
whiteButton ?: boolean
19
20
download ?: boolean
21
+ gaEvent ?: { event : string ; label : string }
20
22
21
23
// compatibility
22
24
target ?: string
@@ -154,7 +156,7 @@ const maskMobile = {
154
156
} ,
155
157
}
156
158
const 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
158
160
const { classes, cx } = useStyles ( {
159
161
color,
160
162
width,
@@ -176,6 +178,16 @@ const Button = (props: ScrollButtonProps) => {
176
178
setIsHover ( )
177
179
}
178
180
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
+
179
191
return (
180
192
// TODO: allow sx, allow size=small/medium
181
193
// avoid setting both 'disabled' and 'loading' to true.
@@ -212,6 +224,7 @@ const Button = (props: ScrollButtonProps) => {
212
224
) ,
213
225
} }
214
226
disabled = { innerDisabled || gloomy || loading }
227
+ onClick = { handleClick }
215
228
{ ...restProps }
216
229
>
217
230
{ children } { loading && < CircularProgress sx = { { color : "inherit" } } size = { isMobile ? 18 : 24 } thickness = { 4 } > </ CircularProgress > }
0 commit comments