Skip to content

Commit 4b44fba

Browse files
María Paz Arrieta LandazuriMaría Paz Arrieta Landazuri
authored andcommitted
refactor: simplify analytics implementation and remove redundant code
1 parent 490c0b5 commit 4b44fba

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed
Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11
import Script from 'next/script';
22

3-
declare global {
4-
interface Window {
5-
gtag: (...args: any[]) => void;
6-
}
7-
}
8-
9-
const GoogleAnalytics = () => {
10-
return (
11-
<>
12-
<Script
13-
strategy="afterInteractive"
14-
src="https://www.googletagmanager.com/gtag/js?id=G-G1T9SRFV67"
15-
async
16-
/>
17-
<Script
18-
id="google-analytics"
19-
strategy="afterInteractive"
20-
dangerouslySetInnerHTML={{
21-
__html: `
22-
window.dataLayer = window.dataLayer || [];
23-
function gtag(){dataLayer.push(arguments);}
24-
gtag('js', new Date());
25-
gtag('config', 'G-G1T9SRFV67');
26-
`,
27-
}}
28-
/>
29-
</>
30-
);
31-
};
3+
const GoogleAnalytics = () => (
4+
<>
5+
<Script
6+
strategy="afterInteractive"
7+
src="https://www.googletagmanager.com/gtag/js?id=G-G1T9SRFV67"
8+
async
9+
/>
10+
<Script
11+
id="google-analytics"
12+
strategy="afterInteractive"
13+
dangerouslySetInnerHTML={{
14+
__html: `
15+
window.dataLayer = window.dataLayer || [];
16+
function gtag(){dataLayer.push(arguments);}
17+
gtag('js', new Date());
18+
gtag('config', 'G-G1T9SRFV67');
19+
`,
20+
}}
21+
/>
22+
</>
23+
);
3224

3325
export default GoogleAnalytics;

frontend/src/app/layout.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { Metadata } from "next";
22
import { Inter, Roboto } from "next/font/google";
33
import "./globals.css";
4-
import Header from "@/components/Header";
4+
import Header from "./components/header/Header";
55
import Footer from "@/components/Footer";
66
import GoogleAnalytics from "./components/GoogleAnalytics";
7-
import GoogleTagManager from "./components/GoogleTagManager";
87

98
const inter = Inter({
109
variable: "--font-inter",
@@ -29,12 +28,7 @@ export default function RootLayout({
2928
}>) {
3029
return (
3130
<html lang="es">
32-
<head>
33-
<GoogleTagManager gtmId="GTM-XXXXXXX" />
34-
</head>
35-
<body
36-
className={`${inter.variable} ${roboto.variable} antialiased`}
37-
>
31+
<body className={`${inter.variable} ${roboto.variable} antialiased`}>
3832
<GoogleAnalytics />
3933
<Header />
4034
{children}

frontend/src/app/utils/analytics.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
declare global {
2+
interface Window {
3+
gtag: (...args: any[]) => void;
4+
}
5+
}
6+
17
// Track page views
28
export const pageview = (url: string) => {
39
if (typeof window.gtag !== 'undefined') {
4-
window.gtag('config', process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID as string, {
10+
window.gtag('config', 'G-G1T9SRFV67', {
511
page_path: url,
612
});
713
}

0 commit comments

Comments
 (0)