Skip to content

Commit

Permalink
fix: moving script to conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
accassid committed Jan 9, 2025
1 parent 15b80c4 commit 819b9d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 19 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import type { AppProps } from 'next/app';
import 'react-tooltip/dist/react-tooltip.css';
import { pageview } from '../lib/googleAnalytics';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import NextNProgress from 'nextjs-progressbar';
import { config } from '@fortawesome/fontawesome-svg-core';
import '@fortawesome/fontawesome-svg-core/styles.css';
import PageWrapper from 'components/layout/PageWrapper/PageWrapper';
import Script from 'next/script';

config.autoAddCss = false;

export default function App({ Component, pageProps }: AppProps) {
const router = useRouter();
const [isClient, setIsClient] = useState(false);

useEffect(() => {
const handleRouteChange = (url: string) => {
pageview(url);
Expand All @@ -23,9 +26,24 @@ export default function App({ Component, pageProps }: AppProps) {
};
}, [router.events]);

useEffect(() => {
setIsClient(true);
}, []);

return (
<>
<NextNProgress options={{ showSpinner: false }} color={'#9161f3'} />
<header>
{isClient && window.location.hostname === 'commanderspellbook.com' && (
<Script
async
data-cfasync="false"
data-noptimize="1"
src="//scripts.pubnation.com/tags/5843d1fc-ee57-4ce9-8b8a-3516d1f3ea93.js"
type="text/javascript"
/>
)}
</header>
<PageWrapper>
<Component {...pageProps} />
</PageWrapper>
Expand Down
9 changes: 0 additions & 9 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { Html, Head, Main, NextScript } from 'next/document';
import Script from 'next/script';

export default function Document() {
return (
<Html lang="en">
<Head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Josefin%20Sans&display=swap" />
<Script
async
data-cfasync="false"
data-noptimize="1"
src="//scripts.pubnation.com/tags/5843d1fc-ee57-4ce9-8b8a-3516d1f3ea93.js"
type="text/javascript"
/>
</Head>
<body>
<Main />
Expand Down

0 comments on commit 819b9d4

Please sign in to comment.