Skip to content

Commit 862c520

Browse files
authored
feat: implement GTM analytics (#136)
2 parents df6ea6d + 21634f1 commit 862c520

File tree

11 files changed

+88
-50
lines changed

11 files changed

+88
-50
lines changed

.github/workflows/cd.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
else
4545
echo "NEXT_PUBLIC_FRONT_URL=$STAGING_PUBLIC_FRONT_URL" >> $GITHUB_ENV
4646
fi
47+
echo "NEXT_PUBLIC_GTM_ID=${{ secrets.GTM_ID }}" >> $GITHUB_ENV
4748
- name: Build Docker images
4849
uses: docker/bake-action@v5
4950
env:

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ COPY --link . .
4545
ARG WORDPRESS_API_URL
4646
# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser
4747
ARG NEXT_PUBLIC_FRONT_URL
48+
ARG NEXT_PUBLIC_GTM_ID
4849

4950
RUN pnpm install --frozen-lockfile --offline --prod && \
5051
pnpm run build

app/(pages)/contact/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function Contact() {
4848
</p>
4949

5050
<div className="text-orange font-bold text-3xl mt-2">
51-
06 82 96 38 89
51+
<a href="tel:06Je c82963889">06 82 96 38 89</a>
5252
</div>
5353
<div className="text-sm">du lundi au samedi de 09h à 18h</div>
5454
</div>

app/(pages)/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GoogleTagManager } from '@next/third-parties/google'
12
import { ReactNode } from 'react'
23

34
import Footer from '@layout/Footer'
@@ -60,6 +61,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
6061
}
6162
return (
6263
<html lang="fr">
64+
<GoogleTagManager gtmId={process.env.NEXT_PUBLIC_GTM_ID!} />
6365
<head />
6466
<body>
6567
<script

app/components/ContactForm.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React from 'react'
44

55
import { useForm } from 'react-hook-form'
6+
import { sendGTMEvent } from '@next/third-parties/google'
67

78
import Button from '@component/Button'
89
import { useFormState } from '@hook/useFormState'
@@ -37,6 +38,13 @@ export default function ContactForm({ lg = false }: { lg?: boolean }) {
3738
.then(() => {
3839
success()
3940
reset()
41+
42+
sendGTMEvent({
43+
event: 'contact_form_submit',
44+
form_location: window.location.pathname,
45+
form_source: document.referrer || 'direct'
46+
})
47+
4048
fetch('/api/hello-slack', {
4149
method: 'POST',
4250
body: JSON.stringify(data),

app/layouts/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default function Footer() {
107107
<span className="button">Demandez un devis</span>
108108
</Link>
109109
<div className="my-2 text-3xl font-bold text-orange">
110-
06 82 96 38 89
110+
<a href="tel:0682963889">06 82 96 38 89</a>
111111
</div>
112112
<div className="text-center md:text-right text-sm">
113113
SIRET : 813 430 592 00010

app/layouts/NavPrimary.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ReactNode, useCallback, useState } from 'react'
2-
31
import Image from 'next/image'
2+
import { ReactNode, useCallback, useState } from 'react'
3+
import { sendGTMEvent } from '@next/third-parties/google'
44
import { usePathname } from 'next/navigation'
55
import { useWindowSize } from 'react-use'
66

@@ -315,7 +315,10 @@ export default function NavPrimary({ isSticky = false }: Props) {
315315
/>
316316
<Link href={RouteLink.contact}>
317317
<span
318-
onClick={() => setOpen(false)}
318+
onClick={() => {
319+
sendGTMEvent({ event: 'contact', position: 'header' })
320+
setOpen(false)
321+
}}
319322
className="mt-2 lg:mt-0 inline-flex py-1 px-2 bg-orange uppercase text-gray-darker font-medium"
320323
>
321324
Contactez-moi

compose.prod.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
args:
88
NEXT_PUBLIC_FRONT_URL: ${NEXT_PUBLIC_FRONT_URL}
99
WORDPRESS_API_URL: ${WORDPRESS_API_URL}
10+
NEXT_PUBLIC_GTM_ID: ${NEXT_PUBLIC_GTM_ID}
1011
environment:
1112
WORDPRESS_API_URL: ${WORDPRESS_API_URL}
1213
healthcheck:

next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@mdx-js/loader": "^3.1.1",
1717
"@mdx-js/react": "^3.1.1",
1818
"@next/mdx": "^15.5.3",
19+
"@next/third-parties": "^15.5.3",
1920
"@tailwindcss/typography": "^0.5.16",
2021
"@types/mdx": "^2.0.13",
2122
"@types/prismjs": "^1.26.5",
@@ -27,7 +28,7 @@
2728
"gsap": "^3.13.0",
2829
"moment": "^2.30.1",
2930
"motion": "^12.23.12",
30-
"next": "15.4.7",
31+
"next": "15.5.3",
3132
"next-sitemap": "^4.2.3",
3233
"postcss": "^8.5.6",
3334
"prismjs": "^1.30.0",

0 commit comments

Comments
 (0)