Skip to content

Commit

Permalink
fix: fix incompatibility of amplitude and ssr (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeojinSeojin authored Mar 1, 2024
1 parent 65bac92 commit 321f456
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { AppProps } from 'next/app';
import Head from 'next/head';
import { useRouter } from 'next/router';
import { Global } from '@emotion/react';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query/devtools';
import SEO from '@src/components/common/SEO';
Expand All @@ -28,12 +28,19 @@ export const queryClient = new QueryClient({
});

amplitude.add(pageViewTrackingEnrichment());
amplitude.init(AMPLITUDE_API_KEY, {
logLevel: amplitude.Types.LogLevel.Warn,
defaultTracking: true,
});

function MyApp({ Component, pageProps }: AppProps) {
const [isAmplitudeInitialized, setIsAmplitudeInitialized] = useState(false);
useEffect(() => {
if (!isAmplitudeInitialized) {
amplitude.init(AMPLITUDE_API_KEY, {
logLevel: amplitude.Types.LogLevel.Warn,
defaultTracking: true,
});
setIsAmplitudeInitialized(true);
}
}, [isAmplitudeInitialized]);

const router = useRouter();
useEffect(() => {
router.events.on('routeChangeComplete', gtm.pageview);
Expand Down

0 comments on commit 321f456

Please sign in to comment.