https://github.com/danilo-89/next-app-directory-gtag
https://github.com/danilo-89/next-app-directory-gtag
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/danilo-89/next-app-directory-gtag
- Owner: danilo-89
- License: mit
- Created: 2023-12-09T13:55:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-19T14:24:46.000Z (over 2 years ago)
- Last Synced: 2025-01-16T22:26:07.624Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://next-app-directory-gtag.vercel.app
- Size: 121 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NextJS (with App Router) gtag example
This project serves as a basic showcase for implementing Next.js (App Router) with the incorporation of Google Tag Manager to handle Google Tag and Cookie Consent functionalities.
Approach used in this example ensures that gtm script is not injected and no data is sent to google tag manager until user consent for cookies has been granted
## Environment Variable
Set the GTAG_ID environment variable in your project with your Google Tag Manager ID.
## Basic usage example
**layout.tsx**
```javascript
export default function RootLayout({
children,
}: {
children: React.ReactNode,
}) {
return (
{children}
);
}
```
**template.tsx**
```javascript
import { type ReactNode } from 'react';
import ConsentDialog from '@/components/ConsentDialog';
function template({ children }: { children: ReactNode }) {
return (
{children}
);
}
export default template;
```