Skip to content

Commit 6a6e408

Browse files
committed
feat: add SimpleAd component for page-level AdSense integration
1 parent dfa7dfc commit 6a6e408

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/app/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Link from "next/link";
44
import NotesBrowser from "@/components/public/NotesBrowser";
55
import DynamicBackground from "@/components/layout/DynamicBackground";
6+
import SimpleAd from "@/components/ads/SimpleAd";
67
import { ArrowDown, BookOpen, Layers, Users } from "lucide-react";
78

89
export default function Home() {
@@ -92,7 +93,10 @@ export default function Home() {
9293

9394
</section>
9495

95-
{/* AdSense removed - incompatible with Next.js SSR */}
96+
{/* Ad Section */}
97+
<div className="container" style={{ marginBottom: "2rem" }}>
98+
<SimpleAd adSlot="3325660893" />
99+
</div>
96100

97101
{/* 3. Main Browser Area */}
98102
<div id="browse" style={{ padding: "2rem 1rem 4rem", background: "linear-gradient(to bottom, rgba(0,0,0,0.02) 0%, var(--bg-gradient-end) 100%)" }}>

src/components/ads/SimpleAd.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"use client";
2+
3+
import { useEffect, useRef } from "react";
4+
5+
interface SimpleAdProps {
6+
adSlot: string;
7+
adFormat?: string;
8+
fullWidthResponsive?: boolean;
9+
}
10+
11+
/**
12+
* Simplified Ad Component for Next.js
13+
* Use this on individual pages, NOT in layout.tsx
14+
*/
15+
export default function SimpleAd({
16+
adSlot,
17+
adFormat = "auto",
18+
fullWidthResponsive = true
19+
}: SimpleAdProps) {
20+
const adRef = useRef<HTMLModElement>(null);
21+
const initialized = useRef(false);
22+
23+
useEffect(() => {
24+
if (initialized.current) return;
25+
26+
try {
27+
// Push ad after a delay to ensure DOM is ready
28+
setTimeout(() => {
29+
if (window && (window as any).adsbygoogle && adRef.current) {
30+
(window as any).adsbygoogle.push({});
31+
initialized.current = true;
32+
}
33+
}, 500);
34+
} catch (err) {
35+
// Silently fail
36+
}
37+
}, []);
38+
39+
return (
40+
<div style={{
41+
minHeight: "100px",
42+
margin: "20px 0",
43+
display: "flex",
44+
justifyContent: "center",
45+
alignItems: "center"
46+
}}>
47+
<ins
48+
ref={adRef}
49+
className="adsbygoogle"
50+
style={{ display: "block" }}
51+
data-ad-client="ca-pub-6253589071371136"
52+
data-ad-slot={adSlot}
53+
data-ad-format={adFormat}
54+
data-full-width-responsive={fullWidthResponsive.toString()}
55+
/>
56+
</div>
57+
);
58+
}

0 commit comments

Comments
 (0)