-
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.
Add custom events for button clicks on homepage
- Loading branch information
Sebastian Herrmann
committed
Aug 21, 2023
1 parent
60dafff
commit 2de0e85
Showing
4 changed files
with
30 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import styled from "@emotion/styled"; | ||
import { useTranslations } from "next-intl"; | ||
import { borderWidths, colors, spacings } from "../../../common/styleVariables"; | ||
import { trackEvent } from "../../../services/analytics"; | ||
import ButtonWithIcon from "../../ButtonWithIcon"; | ||
import Spacer from "../../Spacer"; | ||
import Text from "../../Text"; | ||
|
@@ -21,8 +22,15 @@ const TextContainer = styled.div({ | |
flex: "1 1 auto", | ||
}); | ||
|
||
export default function NewsletterSection() { | ||
type Props = { | ||
trackingPosition: string; | ||
}; | ||
|
||
export default function NewsletterSection({ trackingPosition }: Props) { | ||
const t = useTranslations("Home.newsletter-section"); | ||
const trackButtonClick = () => { | ||
trackEvent("Homepage", "Click 'Contact us' button", trackingPosition); | ||
}; | ||
return ( | ||
<Container> | ||
<ImageContainer> | ||
|
@@ -34,7 +42,7 @@ export default function NewsletterSection() { | |
{t("title")} | ||
</Text> | ||
<Spacer size={16} /> | ||
<ButtonWithIcon as="a" icon="mail" href="mailto:[email protected]"> | ||
<ButtonWithIcon as="a" icon="mail" href="mailto:[email protected]" onClick={trackButtonClick}> | ||
{t("button")} | ||
</ButtonWithIcon> | ||
</TextContainer> | ||
|
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,14 @@ | ||
import { push } from "@socialgouv/matomo-next"; | ||
|
||
type EventCategory = "Homepage"; | ||
|
||
/** | ||
* Track a custom analytics event via Matomo. | ||
* Docs: https://matomo.org/faq/reports/implement-event-tracking-with-matomo/ | ||
*/ | ||
export function trackEvent(eventCategory: EventCategory, eventAction: string, eventName?: string, eventValue?: number) { | ||
const filledParameters = ["trackEvent", eventCategory, eventAction, eventName, eventValue].filter( | ||
(parameter) => parameter !== undefined | ||
); | ||
push(filledParameters); | ||
} |