-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
|
||
import { TrackingEvents, track } from "lib/tracking"; | ||
import { ElementType, ReactNode } from "react"; | ||
|
||
type Props<TEventKey extends keyof TrackingEvents> = { | ||
as?: ElementType; | ||
children: ReactNode; | ||
className?: string; | ||
event: TEventKey; | ||
} & (TrackingEvents[TEventKey] extends null | ||
? {} | ||
: { data: TrackingEvents[TEventKey] }); | ||
|
||
export const Track = <TEventKey extends keyof TrackingEvents>({ | ||
children, | ||
as: Element = "div", | ||
className, | ||
event, | ||
...rest | ||
}: Props<TEventKey>) => { | ||
const data = | ||
"data" in rest ? (rest.data as TrackingEvents[TEventKey]) : undefined; | ||
|
||
return ( | ||
<Element | ||
className={className} | ||
onClick={() => { | ||
// @ts-expect-error Didn't find a way to type the component properly so it fits with the function | ||
track(event, data); | ||
}} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters