File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed
Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 11import { FC , useEffect } from "react" ;
2+ import Script from "next/script" ;
23
34export const GoogleAnalytics :FC = ( ) => {
4- useEffect ( ( ) => {
5- window [ `dataLayer` ] = window [ `dataLayer` ] ?? [ ] ;
6-
7- function gtag ( ...rest ) {
8- window [ `dataLayer` ] . push ( arguments ) ;
9- }
10-
11- gtag ( 'js' , new Date ( ) ) ;
12- gtag ( 'config' , 'G-K2BJ26CT7F' ) ;
13- } , [ ] ) ;
145 return (
156 < >
16- < script async src = "https://www.googletagmanager.com/gtag/js?id=G-K2BJ26CT7F" > </ script >
7+ < Script src = "https://www.googletagmanager.com/gtag/js?id=G-K2BJ26CT7F" strategy = "afterInteractive" />
8+ < Script id = "google-analytics" strategy = "afterInteractive" >
9+ { `
10+ window.dataLayer = window.dataLayer || [];
11+ function gtag(){window.dataLayer.push(arguments);}
12+ gtag('js', new Date());
13+
14+ gtag('config', 'G-K2BJ26CT7F');
15+ ` }
16+ </ Script >
1717 </ >
1818 )
1919}
You can’t perform that action at this time.
0 commit comments