Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update gtag config #1191

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions apps/app/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { type AppProps, type NextWebVitalsMetric } from 'next/app'
import dynamic from 'next/dynamic'
import Head from 'next/head'
import { useRouter } from 'next/router'
import Script from 'next/script'
import { type Session } from 'next-auth'
import { appWithTranslation, type UserConfig } from 'next-i18next'
import { appWithTranslation } from 'next-i18next'
import { DefaultSeo, type DefaultSeoProps } from 'next-seo'
import { GoogleAnalytics } from 'nextjs-google-analytics'

Expand Down Expand Up @@ -51,27 +52,24 @@ export function reportWebVitals(stats: NextWebVitalsMetric) {
appEvent.webVitals(stats)
}

const PageContent = ({ Component, ...pageProps }: AppPropsWithGridSwitch) => {
const router = useRouter()
const autoResetState = Component.autoResetState ? { key: router.asPath } : {}
return Component.omitGrid ? (
<Component {...autoResetState} {...pageProps} />
) : (
<BodyGrid>
<Component {...autoResetState} {...pageProps} />
</BodyGrid>
)
}

const MyApp = (appProps: AppPropsWithGridSwitch) => {
const {
Component,
pageProps: { session, ...pageProps },
pageProps: { session },
} = appProps

const router = useRouter()

const { isMobile, isTablet } = useScreenSize()

const autoResetState = Component.autoResetState ? { key: router.asPath } : {}

const PageContent = () =>
Component.omitGrid ? (
<Component {...autoResetState} {...pageProps} />
) : (
<BodyGrid>
<Component {...autoResetState} {...pageProps} />
</BodyGrid>
)

return (
<>
<Head>
Expand All @@ -80,9 +78,14 @@ const MyApp = (appProps: AppPropsWithGridSwitch) => {
<Providers session={session}>
<DefaultSeo {...defaultSEO} />
<GoogleAnalytics trackPageViews defaultConsent='granted' />
<Script id='gtm_conversion'>
{`
gtag?.('config','G-RL8CR7T4EP')
`}
</Script>
<PageLoadProgress />
<Navbar />
<PageContent />
<PageContent {...appProps} />
{(isMobile || isTablet) && <Space h={80} />}
<Footer />
<Notifications transitionDuration={500} />
Expand Down
8 changes: 4 additions & 4 deletions apps/app/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createStylesServer, ServerStyles } from '@mantine/next'
import Document, { type DocumentContext, Head, Html, Main, NextScript } from 'next/document'
import NextDocument, { type DocumentContext, Head, Html, Main, NextScript } from 'next/document'
import Script from 'next/script'

import { appCache } from '@weareinreach/ui/theme'

import i18nextConfig from '../../next-i18next.config.mjs'

const stylesServer = createStylesServer(appCache)
export default class _Document extends Document {
export default class Document extends NextDocument {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx)
const initialProps = await NextDocument.getInitialProps(ctx)
return {
...initialProps,
styles: [
Expand All @@ -20,7 +20,7 @@ export default class _Document extends Document {
}

render() {
const currentLocale = this.props.__NEXT_DATA__.locale || i18nextConfig.i18n.defaultLocale
const currentLocale = this.props.__NEXT_DATA__.locale ?? i18nextConfig.i18n.defaultLocale
return (
<Html lang={currentLocale}>
<Head>
Expand Down
Loading