[portal][fix] fix GA loading for products

pull/460/head
Yangshun Tay 2 years ago
parent 69e5610323
commit 39b5a51aa2

@ -1,5 +1,5 @@
import Head from 'next/head';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import Script from 'next/script';
import { createContext, useContext, useEffect } from 'react'; import { createContext, useContext, useEffect } from 'react';
type Context = Readonly<{ type Context = Readonly<{
@ -78,25 +78,26 @@ export default function GoogleAnalytics({ children, measurementID }: Props) {
return ( return (
<GoogleAnalyticsContext.Provider value={{ event }}> <GoogleAnalyticsContext.Provider value={{ event }}>
{children} {children}
{/* Global Site Tag (gtag.js) - Google Analytics */} <Head>
<Script {/* TODO(yangshun): Change back to next/script in future. */}
src={`https://www.googletagmanager.com/gtag/js?id=${measurementID}`} {/* Global Site Tag (gtag.js) - Google Analytics */}
strategy="afterInteractive" <script
/> async={true}
<Script src={`https://www.googletagmanager.com/gtag/js?id=${measurementID}`}
dangerouslySetInnerHTML={{ />
__html: ` <script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);} window.gtag = function(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('js', new Date());
gtag('config', '${measurementID}', { gtag('config', '${measurementID}', {
page_path: window.location.pathname, page_path: window.location.pathname,
}); });
`, `,
}} }}
id="gtag-init" />
strategy="afterInteractive" </Head>
/>
</GoogleAnalyticsContext.Provider> </GoogleAnalyticsContext.Provider>
); );
} }

Loading…
Cancel
Save