Skip to content

Commit

Permalink
feat: Google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
avuenja committed Jul 21, 2022
1 parent b9a2fc3 commit ed4ec50
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import type { AppProps } from 'next/app'
import Script from 'next/script'
import { ChakraProvider } from '@chakra-ui/react'

import theme from '@/theme'
import Layout from '@/components/layout'

const App = ({ Component, pageProps }: AppProps) => {
return (
<ChakraProvider theme={theme}>
<Layout>
<Component {...pageProps} />
</Layout>
</ChakraProvider>
<>
<Script
strategy="lazyOnload"
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>
<Script id="g-tag" strategy="lazyOnload">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>

<ChakraProvider theme={theme}>
<Layout>
<Component {...pageProps} />
</Layout>
</ChakraProvider>
</>
)
}

Expand Down

1 comment on commit ed4ec50

@vercel
Copy link

@vercel vercel bot commented on ed4ec50 Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.