Skip to content

Commit

Permalink
feat: Add Google Analytics component
Browse files Browse the repository at this point in the history
Add a new component, GoogleAnalytics, to handle the integration of Google Analytics into the application. This component includes the necessary scripts and configuration to track user interactions and page views.

This commit also updates the layout.jsx file to import and use the GoogleAnalytics component, adding the Google Analytics tracking code to the application's HTML.
  • Loading branch information
guillecro committed Aug 6, 2024
1 parent 40411af commit 979847c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/app/_components/common/google-analytics.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Script from "next/script";

const GoogleAnalytics = ({ ga_id }) => (
<>
<Script
async
src={`https://www.googletagmanager.com/gtag/js?
id=${ga_id}`}
></Script>
<Script
id="google-analytics"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${ga_id}');
`,
}}
></Script>
</>
);
export default GoogleAnalytics;
5 changes: 2 additions & 3 deletions src/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Overlay from '@/app/_components/common/overlay'
import { createTheme } from '@mui/material'
import Navbar from '@/app/_components/layout/navbar'
import Footer from '@/app/_components/layout/footer'

import GoogleAnalytics from "@/app/_components/common/google-analytics";

const karla = Karla({
weight: ['200', '300', '400', '500', '600', '700', '800'],
Expand Down Expand Up @@ -44,15 +44,14 @@ export default function RootLayout({ children}) {
return (
<html lang="es" className={karla.className}>
<body>
<GoogleAnalytics ga_id="G-DJJZSS3LVE"/>
<Providers>
<Navbar />
<main>
{children}
</main>
<Footer />
<Overlay />


</Providers>
</body>
</html>
Expand Down

0 comments on commit 979847c

Please sign in to comment.