Skip to content

Commit

Permalink
send cta clicks to plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Feb 5, 2024
1 parent d77eb9b commit 1531dfc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/components/home/Announcement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { HomePageAnnouncement } from '../../../contentful/homePageAnnouncement'
// import { ChevronRightIcon } from '@heroicons/react/20/solid'
import { ReactNode } from 'react'
import Link from 'next/link'
import { usePlausible } from 'next-plausible'

const classNames =
'border border-th-bkg-4 py-3 px-4 rounded-lg flex items-center justify-between md:hover:bg-th-bkg-3'

const AnnouncementWrapper = ({
children,
Expand All @@ -13,14 +17,27 @@ const AnnouncementWrapper = ({
isExternal: boolean
path: string
}) => {
const classNames =
'border border-th-bkg-4 py-3 px-4 rounded-lg flex items-center justify-between md:hover:bg-th-bkg-3'
const telemetry = usePlausible()

const trackClick = () => {
telemetry('homeAnnouncement', {
props: {
path: path,
},
})
}

return isExternal ? (
<a className={classNames} href={path} rel="noopener noreferrer">
<a
className={classNames}
href={path}
rel="noopener noreferrer"
onClick={trackClick}
>
{children}
</a>
) : (
<Link className={classNames} href={path} shallow>
<Link className={classNames} href={path} onClick={trackClick} shallow>
{children}
</Link>
)
Expand Down
12 changes: 12 additions & 0 deletions app/components/shared/ButtonLink.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { usePlausible } from 'next-plausible'
import { FunctionComponent, ReactNode } from 'react'

interface ButtonLinkProps {
Expand All @@ -17,6 +18,16 @@ const ButtonLink: FunctionComponent<ButtonLinkProps> = ({
size,
target,
}) => {
const telemetry = usePlausible()

const trackClick = () => {
telemetry('ctaClick', {
props: {
path: path,
},
})
}

return (
<a
className={`flex w-max items-center justify-center rounded-md ${
Expand All @@ -33,6 +44,7 @@ const ButtonLink: FunctionComponent<ButtonLinkProps> = ({
href={path}
rel="noopener noreferrer"
target={target ? target : undefined}
onClick={trackClick}
>
{linkText}
</a>
Expand Down

0 comments on commit 1531dfc

Please sign in to comment.