Skip to content

Commit

Permalink
feat(repo:components): add google analytics component
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rondio authored and David Rondio committed Sep 27, 2024
1 parent 3684241 commit 9720ed8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
NODE_ENV=development

# GOOGLE ANALYTICS
# Copiez ici l'ID de mesure (formaté comme G-XXXXXXXXXX)
# NEXT_PUBLIC_GOOGLE_ANALYTICS=G-XXXXXXXXXX

# DATABASE
DB_HOST=localhost
DB_USER=dbusername
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ pour améliorer votre productivité.
préconfigurés pour maintenir une base de code cohérente et lisible.
- **Husky et Lint-Staged** : Des hooks de Git pour exécuter automatiquement les
vérifications de lint et de formatage avant chaque commit.
- **Docker** :

- **Zod** :
- **Docker** : Un outil de conteneurisation pour faciliter le déploiement et la
gestion des environnements de développement.
- **Zod** : Un schéma de validation de données puissant et simple à utiliser.
- **Google Analytics** : Un outil de suivi des performances pour analyser le
comportement des utilisateurs et améliorer l'expérience utilisateur.

## Utilisation

Expand Down
3 changes: 3 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { Metadata } from 'next';
import localFont from 'next/font/local';
import React from 'react';

import GoogleAnalytics from '@/components/GoogleAnalytics';

import './globals.css';
import siteConfig from '@/config/site';

Expand Down Expand Up @@ -72,6 +74,7 @@ export default function RootLayout({
>
{children}
</body>
<GoogleAnalytics />
</html>
);
}
25 changes: 25 additions & 0 deletions components/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Script from 'next/script';

const GoogleAnalytics = () => {
return (
<>
<Script
strategy="lazyOnload"
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>

<Script id="google-analytics" strategy="lazyOnload">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
);
};

export default GoogleAnalytics;

0 comments on commit 9720ed8

Please sign in to comment.