Skip to content

Commit 1dc4309

Browse files
committed
refactor: Dynamically load SocialBar script and move it to global layout, removing NativeBanner from homepage.
1 parent cbe9e71 commit 1dc4309

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SITE_URL } from "@/lib/constants";
77
import { FestiveModal } from "@/components/FestiveModal";
88
import { FeatureModal } from "@/components/FeatureModal";
99
import Script from "next/script";
10-
import { Popunder } from "@/components/ads";
10+
import { Popunder, SocialBar } from "@/components/ads";
1111

1212
const geistSans = Geist({
1313
variable: "--font-geist-sans",
@@ -73,6 +73,7 @@ export default function RootLayout({
7373
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
7474
>
7575
<Popunder />
76+
<SocialBar />
7677
{/* ✅ Google Analytics script */}
7778
<Script
7879
src="https://www.googletagmanager.com/gtag/js?id=G-MRZ0D7MXZD"

app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export default async function Home() {
131131

132132

133133

134-
<NativeBanner className="fixed bottom-0 left-1/2 -translate-x-1/2" />
134+
{/* <NativeBanner className="fixed bottom-0 left-1/2 -translate-x-1/2" /> */}
135135
</main>
136136
);
137137
}

components/ads/SocialBar.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
'use client';
22

3-
import Script from 'next/script';
3+
import { useEffect, useRef } from 'react';
44
import { adConfig } from './config';
55

66
interface AdProps {
77
className?: string;
88
}
99

1010
export default function SocialBar({ className }: AdProps) {
11+
const adRef = useRef<HTMLDivElement>(null);
12+
13+
useEffect(() => {
14+
if (adConfig.disableAds || !adRef.current) return;
15+
16+
const container = adRef.current;
17+
18+
// Clear previous content
19+
container.innerHTML = '';
20+
21+
const script = document.createElement('script');
22+
script.type = 'text/javascript';
23+
// Social bar script source
24+
script.src = '//pl27751387.effectivegatecpm.com/a3/4a/86/a34a865697fcbff52b5eca6ada6baccc.js';
25+
26+
container.appendChild(script);
27+
28+
return () => {
29+
if (container) {
30+
container.innerHTML = '';
31+
}
32+
};
33+
}, []);
34+
1135
if (adConfig.disableAds) return null;
1236

1337
return (
14-
<div className={className}>
15-
<Script
16-
type="text/javascript"
17-
src="//pl27751387.effectivegatecpm.com/a3/4a/86/a34a865697fcbff52b5eca6ada6baccc.js"
18-
strategy="afterInteractive"
19-
/>
20-
</div>
38+
<div ref={adRef} className={className} />
2139
);
2240
}

0 commit comments

Comments
 (0)