feat(SW-395): Added tracking to header and footer

This commit is contained in:
Erik Tiekstra
2025-01-08 14:18:12 +01:00
parent 9c2d9ec528
commit d11b9e8aee
7 changed files with 83 additions and 38 deletions

View File

@@ -0,0 +1,29 @@
"use client"
import { getIconByIconName } from "@/components/Icons/get-icon-by-icon-name"
import { trackSocialMediaClick } from "@/utils/tracking"
import type { SocialIconsProps } from "@/types/components/footer/socialIcons"
import type { SocialLinkProps } from "@/types/components/footer/socialLink"
import type { IconName } from "@/types/components/icon"
function SocialIcon({ iconName }: SocialIconsProps) {
const SocialIcon = getIconByIconName(iconName as IconName)
return SocialIcon ? <SocialIcon color="white" /> : <span>{iconName}</span>
}
export default function SocialLink({ link }: SocialLinkProps) {
const { href, title } = link
return (
<a
color="white"
href={href}
key={title}
target="_blank"
aria-label={title}
onClick={() => trackSocialMediaClick(title)}
>
<SocialIcon iconName={title} />
</a>
)
}

View File

@@ -1,6 +1,5 @@
import { getFooter, getLanguageSwitcher } from "@/lib/trpc/memoizedRequests"
import { getIconByIconName } from "@/components/Icons/get-icon-by-icon-name"
import Image from "@/components/Image"
import LanguageSwitcher from "@/components/LanguageSwitcher"
import SkeletonShimmer from "@/components/SkeletonShimmer"
@@ -9,16 +8,10 @@ import Footnote from "@/components/TempDesignSystem/Text/Footnote"
import { getIntl } from "@/i18n"
import { getLang } from "@/i18n/serverContext"
import SocialLink from "./SocialLink"
import styles from "./details.module.css"
import type { SocialIconsProps } from "@/types/components/footer/socialIcons"
import type { IconName } from "@/types/components/icon"
function SocialIcon({ iconName }: SocialIconsProps) {
const SocialIcon = getIconByIconName(iconName as IconName)
return SocialIcon ? <SocialIcon color="white" /> : <span>{iconName}</span>
}
export default async function FooterDetails() {
const lang = getLang()
const intl = await getIntl()
@@ -40,18 +33,7 @@ export default async function FooterDetails() {
</Link>
<nav className={styles.socialNav}>
{footer?.socialMedia.links.map(
(link) =>
link.href && (
<a
color="white"
href={link.href.href}
key={link.href.title}
target="_blank"
aria-label={link.href.title}
>
<SocialIcon iconName={link.href.title} />
</a>
)
({ href }) => href && <SocialLink link={href} key={href.title} />
)}
</nav>
</div>

View File

@@ -1,7 +1,10 @@
"use client"
import { ArrowRightIcon } from "@/components/Icons"
import SkeletonShimmer from "@/components/SkeletonShimmer"
import Link from "@/components/TempDesignSystem/Link"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import { trackFooterClick } from "@/utils/tracking"
import styles from "./mainnav.module.css"
@@ -19,9 +22,9 @@ export default function FooterMainNav({ mainLinks }: FooterMainNavProps) {
href={link.url}
className={styles.mainNavigationLink}
target={link.openInNewTab ? "_blank" : undefined}
onClick={() => trackFooterClick("main", link.title)}
>
{link.title}
<ArrowRightIcon color="peach80" />
</Link>
</Subtitle>

View File

@@ -1,8 +1,11 @@
"use client"
import Image from "@/components/Image"
import SkeletonShimmer from "@/components/SkeletonShimmer"
import Link from "@/components/TempDesignSystem/Link"
import Caption from "@/components/TempDesignSystem/Text/Caption"
import { getLang } from "@/i18n/serverContext"
import useLang from "@/hooks/useLang"
import { trackFooterClick, trackSocialMediaClick } from "@/utils/tracking"
import styles from "./secondarynav.module.css"
@@ -13,7 +16,7 @@ export default function FooterSecondaryNav({
secondaryLinks,
appDownloads,
}: FooterSecondaryNavProps) {
const lang = getLang()
const lang = useLang()
return (
<div className={styles.secondaryNavigation}>
@@ -28,18 +31,19 @@ export default function FooterSecondaryNav({
</Caption>
<ul className={styles.secondaryNavigationList}>
{appDownloads.links.map(
(link) =>
link.href && (
<li key={link.type} className={styles.appDownloadItem}>
({ href, type }) =>
href && (
<li key={type} className={styles.appDownloadItem}>
<a
href={link.href.href}
href={href.href}
target="_blank"
aria-label={link.href.title}
aria-label={href.title}
onClick={() => trackSocialMediaClick(href.title)}
>
<Image
src={
AppDownLoadLinks[
`${link.type}_${lang}` as keyof typeof AppDownLoadLinks
`${type}_${lang}` as keyof typeof AppDownLoadLinks
]
}
alt=""
@@ -53,22 +57,23 @@ export default function FooterSecondaryNav({
</ul>
</nav>
)}
{secondaryLinks.map((link) => (
<nav className={styles.secondaryNavigationGroup} key={link.title}>
{secondaryLinks.map((group) => (
<nav className={styles.secondaryNavigationGroup} key={group.title}>
<Caption
color="textMediumContrast"
textTransform="uppercase"
type="label"
>
{link.title}
{group.title}
</Caption>
<ul className={styles.secondaryNavigationList}>
{link?.links?.map((link) => (
{group?.links?.map((link) => (
<li key={link.title} className={styles.secondaryNavigationItem}>
<Link
href={link.url}
target={link.openInNewTab ? "_blank" : undefined}
color="burgundy"
onClick={() => trackFooterClick(group.title, link.title)}
>
{link.title}
</Link>

View File

@@ -1,7 +1,5 @@
"use client"
import { type PropsWithChildren } from "react"
import { login } from "@/constants/routes/handleAuth"
import Link from "@/components/TempDesignSystem/Link"
@@ -9,6 +7,8 @@ import useLang from "@/hooks/useLang"
import { useLazyPathname } from "@/hooks/useLazyPathname"
import { trackLoginClick } from "@/utils/tracking"
import type { PropsWithChildren } from "react"
import type { TrackingPosition } from "@/types/components/tracking"
import type { LinkProps } from "@/components/TempDesignSystem/Link/link"

View File

@@ -0,0 +1,6 @@
export interface SocialLinkProps {
link: {
href: string
title: string
}
}

View File

@@ -19,7 +19,7 @@ export function trackPageViewStart() {
}
export function trackLoginClick(position: TrackingPosition) {
const loginEvent = {
const event = {
event: "loginStart",
login: {
position,
@@ -27,7 +27,27 @@ export function trackLoginClick(position: TrackingPosition) {
ctaName: "login",
},
}
pushToDataLayer(loginEvent)
pushToDataLayer(event)
}
export function trackSocialMediaClick(socialMediaName: string) {
const event = {
event: "social media",
social: {
socialIconClicked: socialMediaName,
},
}
pushToDataLayer(event)
}
export function trackFooterClick(group: string, name: string) {
const event = {
event: "footer link",
footer: {
footerLinkClicked: `${group}:${name}`,
},
}
pushToDataLayer(event)
}
export function trackUpdatePaymentMethod(hotelId: string, method: string) {