[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}
<Head>
{/* TODO(yangshun): Change back to next/script in future. */}
{/* Global Site Tag (gtag.js) - Google Analytics */} {/* Global Site Tag (gtag.js) - Google Analytics */}
<Script <script
async={true}
src={`https://www.googletagmanager.com/gtag/js?id=${measurementID}`} src={`https://www.googletagmanager.com/gtag/js?id=${measurementID}`}
strategy="afterInteractive"
/> />
<Script <script
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: ` __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