Skip to content

Instantly share code, notes, and snippets.

@popeating
Created July 13, 2023 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popeating/100f2dfab7471196f8b6fefc65137038 to your computer and use it in GitHub Desktop.
Save popeating/100f2dfab7471196f8b6fefc65137038 to your computer and use it in GitHub Desktop.
import './globals.css';
import { Inter } from 'next/font/google';
import Script from 'next/script';
import { cookies } from 'next/headers';
import Consent from './components/Consent';
const inter = Inter({ subsets: ['latin'] });
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};
export default function RootLayout({ children }) {
const cookieStore = cookies();
const consent = cookieStore.get('localConsent');
return (
<html lang="en">
<Script
id="gtag"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PR7FDL7');`,
}}
/>
{consent?.value === 'true' && (
<Script
id="consupd"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
gtag('consent', 'update', {
'ad_storage': 'granted',
'analytics_storage': 'granted'
});
`,
}}
/>
)}
<body className={inter.className}>
{children}
<Consent />
</body>
</html>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment