Skip to content

Commit

Permalink
feat(matomo): add twitter share tracking using matomo (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadeciman authored Nov 24, 2022
1 parent ac4ecd8 commit 279709f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libs/shared/ui/src/lib/constants/tracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum LogTypes {
trackEvent = "trackEvent"
}

export const LogPayload = {
twitterShare: [LogTypes.trackEvent, "share", "twitter"]
}
8 changes: 8 additions & 0 deletions libs/shared/ui/src/lib/share-twitter/share-twitter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TwitterIcon, TwitterShareButton } from 'next-share'
import { useCallback } from 'react'
import { push } from "@socialgouv/matomo-next";
import { LogPayload } from '../constants/tracking';

export interface ShareTwitterProps {
websiteUrl: string
Expand All @@ -11,9 +14,14 @@ export function ShareTwitter(props: ShareTwitterProps) {
const showResultButton = props.showResult
? `transition-opacity duration-300 delay-700 !opacity-100`
: `opacity-0 pointer-events-none`

const onTwitterShare = useCallback(() => {
push([...LogPayload.twitterShare, questionSlug]);
}, [])

return (
<TwitterShareButton
onClick={onTwitterShare}
url={`${websiteUrl}/question/${questionSlug}/`}
title={`You won't believe what people voted on this one...`}
>
Expand Down

0 comments on commit 279709f

Please sign in to comment.