Skip to content

Commit

Permalink
feat: Add google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
moerabaya committed Apr 13, 2024
1 parent 4daf522 commit 3b93826
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,28 @@ import Cookies from "universal-cookie";
import consts from "consts";
import ThemeProvider from "templates/ThemeProvider";
import { getProjects } from "pages";
import Script from "next/script";
// prevent TypeScript errors on the css prop on arbitrary elements
// import {} from 'styled-components/cssprop'

function MyApp({ Component, pageProps }: AppProps) {
return (
<ThemeProvider {...pageProps}>
<Script
async
onError={(e: Error) => {
console.error("Script failed to load", e);
}}
src="https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_ANALYTICS_ID}"
/>
<Script id="gtag-init" strategy="afterInteractive">
{`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_ANALYTICS_ID}');
`}
</Script>
<Layout pageProps={pageProps}>
<Component {...pageProps} />
</Layout>
Expand Down

0 comments on commit 3b93826

Please sign in to comment.