Skip to content

Commit

Permalink
Add Gtag component and script
Browse files Browse the repository at this point in the history
  • Loading branch information
giovamuge committed Mar 21, 2024
1 parent 49e813e commit 9dea2c6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/components/Gtag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Script from "next/script"

export default function Gtag() {
return <Script src="/gtag.js" />
}
22 changes: 21 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Metadata } from "next"
import { Inter } from "next/font/google"
import "./globals.css"
import { ThemeContextProvider } from "@/context/ThemeContext"
import Head from "next/head"
import Gtag from "./components/Gtag"
import Script from "next/script"

const inter = Inter({ subsets: ["latin"] })

Expand Down Expand Up @@ -43,8 +46,25 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<Head>
<Gtag />
</Head>
<ThemeContextProvider>
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<noscript>
<iframe
src="https://www.googletagmanager.com/ns.html?id=GTM-MQMVBV4W"
height="0"
width="0"
style={{
display: "none",
visibility: "hidden",
}}
></iframe>
</noscript>

{children}
</body>
</ThemeContextProvider>
</html>
)
Expand Down
10 changes: 10 additions & 0 deletions public/gtag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;(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-MQMVBV4W")

0 comments on commit 9dea2c6

Please sign in to comment.