add gtag
This commit is contained in:
parent
db99489d2b
commit
86fb4eed1d
@ -6,6 +6,7 @@ import useRouteChange from "@/lib/hooks/useRouteChange";
|
||||
import { NDKProvider } from "./ndk";
|
||||
import SignerProvider from "./signer";
|
||||
import { RELAYS } from "@/constants";
|
||||
import { GoogleAnalyticsInit } from "@/lib/analytics";
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
const handleRouteChange = (url: string) => {
|
||||
@ -24,6 +25,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
||||
<ModalProvider>{children}</ModalProvider>
|
||||
</SignerProvider>
|
||||
</NDKProvider>
|
||||
<GoogleAnalyticsInit />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
22
lib/analytics/InitScript.tsx
Normal file
22
lib/analytics/InitScript.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import Script from "next/script";
|
||||
|
||||
export default function Init() {
|
||||
return (
|
||||
<>
|
||||
<Script
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_TRACKING_ID}`}
|
||||
strategy="lazyOnload"
|
||||
/>
|
||||
<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_GA_TRACKING_ID}', {
|
||||
page_path: window.location.pathname,
|
||||
});
|
||||
`}
|
||||
</Script>
|
||||
</>
|
||||
);
|
||||
}
|
1
lib/analytics/index.ts
Normal file
1
lib/analytics/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { default as GoogleAnalyticsInit } from "./InitScript";
|
Loading…
x
Reference in New Issue
Block a user