old_contents: import '@docsearch/css';
  import '../styles/index.css';
  import Script from 'next/script';
  import Head from 'next/head';
  import { useRouter } from 'next/router';
  import { useEffect } from 'react';
  import * as gtag from 'utils/analytics';
  
  export function reportWebVitals({ id, name, label, value }) {
    // Use `window.gtag` if you initialized Google Analytics as this example:
    // https://github.com/vercel/next.js/blob/canary/examples/with-google-analytics/pages/_document.js
    window.gtag('event', name, {
      event_category:
        label === 'web-vital' ? 'Web Vitals' : 'Next.js custom metric',
      value: Math.round(name === 'CLS' ? value * 1000 : value), // values must be integers
      event_label: id, // id unique to current page load
      non_interaction: true, // avoids affecting bounce rate.
    });
  }
  
  function MyApp({ Component, pageProps }) {
    const router = useRouter();
    useEffect(() => {
      const handleRouteChange = url => {
        gtag.pageview(url);
      };
      router.events.on('routeChangeComplete', handleRouteChange);
      return () => {
        router.events.off('routeChangeComplete', handleRouteChange);
      };
    }, [router.events]);
  
    return (
      <>
        <Script
          strategy="afterInteractive"
          src="https://buttons.github.io/buttons.js"
        />
        <Script
          strategy="afterInteractive"
          src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
        />
        <Script
          strategy="afterInteractive"
          dangerouslySetInnerHTML={{
            __html: `
              window.dataLayer = window.dataLayer || [];
              function gtag(){dataLayer.push(arguments);}
              gtag('js', new Date());
              gtag('config', '${gtag.GA_TRACKING_ID}', {
                page_path: window.location.pathname,
              });
            `,
          }}
        />
        <Component {...pageProps} />
      </>
    );
  }
  
  export default MyApp;
  
new_contents: import '@docsearch/css';
  import '../styles/index.css';
  import Script from 'next/script';
  import Head from 'next/head';
  import { useRouter } from 'next/router';
  import { useEffect } from 'react';
  import * as gtag from 'utils/analytics';
  
  export function reportWebVitals({ id, name, label, value }) {
    // Use `window.gtag` if you initialized Google Analytics as this example:
    // https://github.com/vercel/next.js/blob/canary/examples/with-google-analytics/pages/_document.js
    typeof window != 'undefined' &&
      window.gtag &&
      window.gtag('event', name, {
        event_category:
          label === 'web-vital' ? 'Web Vitals' : 'Next.js custom metric',
        value: Math.round(name === 'CLS' ? value * 1000 : value), // values must be integers
        event_label: id, // id unique to current page load
        non_interaction: true, // avoids affecting bounce rate.
      });
  }
  
  function MyApp({ Component, pageProps }) {
    const router = useRouter();
    useEffect(() => {
      const handleRouteChange = url => {
        gtag.pageview(url);
      };
      router.events.on('routeChangeComplete', handleRouteChange);
      return () => {
        router.events.off('routeChangeComplete', handleRouteChange);
      };
    }, [router.events]);
  
    return (
      <>
        <Script
          strategy="afterInteractive"
          src="https://buttons.github.io/buttons.js"
        />
        <Script
          strategy="afterInteractive"
          src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
        />
        <Script
          strategy="afterInteractive"
          dangerouslySetInnerHTML={{
            __html: `
              window.dataLayer = window.dataLayer || [];
              function gtag(){dataLayer.push(arguments);}
              gtag('js', new Date());
              gtag('config', '${gtag.GA_TRACKING_ID}', {
                page_path: window.location.pathname,
              });
            `,
          }}
        />
        <Component {...pageProps} />
      </>
    );
  }
  
  export default MyApp;
  
subject: Tweak web vitals code