|
@@ -1,13 +1,17 @@
|
|
|
import { SWRConfig } from "swr";
|
|
import { SWRConfig } from "swr";
|
|
|
|
|
+import Script from "next/script";
|
|
|
import type { NextPage } from "next";
|
|
import type { NextPage } from "next";
|
|
|
|
|
+import { useRouter } from "next/router";
|
|
|
import type { AppProps } from "next/app";
|
|
import type { AppProps } from "next/app";
|
|
|
import App, { AppContext } from "next/app";
|
|
import App, { AppContext } from "next/app";
|
|
|
-import type { ReactElement, ReactNode } from "react";
|
|
|
|
|
|
|
+import { ReactElement, ReactNode, useEffect } from "react";
|
|
|
|
|
|
|
|
import { Context } from "../libs/context";
|
|
import { Context } from "../libs/context";
|
|
|
import Layout from "../components/common/Layout";
|
|
import Layout from "../components/common/Layout";
|
|
|
|
|
|
|
|
import "../styles/globals.scss";
|
|
import "../styles/globals.scss";
|
|
|
|
|
+import { pageview } from "../libs/gtag";
|
|
|
|
|
+import { GA_TRACKING_ID } from "../libs/config";
|
|
|
|
|
|
|
|
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
|
|
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
|
|
|
getLayout?: (page: ReactElement) => ReactNode;
|
|
getLayout?: (page: ReactElement) => ReactNode;
|
|
@@ -25,19 +29,38 @@ type AppPropsWithLayout = AppProps & {
|
|
|
|
|
|
|
|
const MyApp = ({ Component, pageProps }: AppPropsWithLayout) => {
|
|
const MyApp = ({ Component, pageProps }: AppPropsWithLayout) => {
|
|
|
const { fallback, genre, ...otherProps } = pageProps;
|
|
const { fallback, genre, ...otherProps } = pageProps;
|
|
|
|
|
+ const router = useRouter();
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ const handleRouteChange = (url: string) => {
|
|
|
|
|
+ pageview(url);
|
|
|
|
|
+ };
|
|
|
|
|
+ router.events.on("routeChangeComplete", handleRouteChange);
|
|
|
|
|
+ router.events.on("hashChangeComplete", handleRouteChange);
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ router.events.off("routeChangeComplete", handleRouteChange);
|
|
|
|
|
+ router.events.off("hashChangeComplete", handleRouteChange);
|
|
|
|
|
+ };
|
|
|
|
|
+ }, [router.events]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <Context.Provider value={{ genre }}>
|
|
|
|
|
- <SWRConfig value={{ fallback, revalidateIfStale: false }}>
|
|
|
|
|
- {Component.getLayout ? (
|
|
|
|
|
- Component.getLayout(<Component {...otherProps} />)
|
|
|
|
|
- ) : (
|
|
|
|
|
- <Layout>
|
|
|
|
|
- <Component {...otherProps} />
|
|
|
|
|
- </Layout>
|
|
|
|
|
- )}
|
|
|
|
|
- </SWRConfig>
|
|
|
|
|
- </Context.Provider>
|
|
|
|
|
|
|
+ <>
|
|
|
|
|
+ <Script
|
|
|
|
|
+ strategy="afterInteractive"
|
|
|
|
|
+ src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Context.Provider value={{ genre }}>
|
|
|
|
|
+ <SWRConfig value={{ fallback, revalidateIfStale: false }}>
|
|
|
|
|
+ {Component.getLayout ? (
|
|
|
|
|
+ Component.getLayout(<Component {...otherProps} />)
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Layout>
|
|
|
|
|
+ <Component {...otherProps} />
|
|
|
|
|
+ </Layout>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </SWRConfig>
|
|
|
|
|
+ </Context.Provider>
|
|
|
|
|
+ </>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|