diff --git a/src/app/(marketing)/tools/layout.tsx b/src/app/(marketing)/tools/layout.tsx
index ebd6b42..4246278 100644
--- a/src/app/(marketing)/tools/layout.tsx
+++ b/src/app/(marketing)/tools/layout.tsx
@@ -1,6 +1,7 @@
'use client';
import React from 'react';
+import Script from 'next/script';
import AdBanner from '@/components/ads/AdBanner';
export default function ToolsLayout({
@@ -10,6 +11,13 @@ export default function ToolsLayout({
}) {
return (
+ {/* AdSense script - only loads on tool pages */}
+
{children}
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 176d6d6..674f24b 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -114,11 +114,8 @@ export default function RootLayout({
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(websiteSchema) }}
/>
-
+ {/* AdSense script removed from global layout to prevent auto-ads on landing pages.
+ Ads are loaded locally via the AdBanner component only on tool pages. */}
diff --git a/src/components/ads/AdBanner.tsx b/src/components/ads/AdBanner.tsx
index 3605040..9443b25 100644
--- a/src/components/ads/AdBanner.tsx
+++ b/src/components/ads/AdBanner.tsx
@@ -1,6 +1,6 @@
'use client';
-import { useEffect, useState } from 'react';
+import { useEffect, useState, useRef } from 'react';
import { useSession } from 'next-auth/react';
interface AdBannerProps {
@@ -17,38 +17,65 @@ export default function AdBanner({
className = '',
}: AdBannerProps) {
const { data: session, status } = useSession();
+ const adRef = useRef(null);
+ const [adFilled, setAdFilled] = useState(false);
// Check if user has a paid plan
- // Adjust 'pro' or 'premium' based on your actual plan values
const isPaidUser = session?.user && (
session.user.plan === 'PRO' ||
session.user.plan === 'PREMIUM' ||
session.user.plan === 'LIFETIME'
);
- const [adLoaded, setAdLoaded] = useState(false);
-
useEffect(() => {
// Don't load if loading session or if user is paid
if (status === 'loading' || isPaidUser) return;
- try {
- // @ts-ignore
- (window.adsbygoogle = window.adsbygoogle || []).push({});
- setAdLoaded(true);
- } catch (err) {
- console.error('AdSense error:', err);
- }
+ const loadAd = () => {
+ try {
+ // @ts-ignore
+ (window.adsbygoogle = window.adsbygoogle || []).push({});
+
+ // Check if ad was filled after a short delay
+ setTimeout(() => {
+ if (adRef.current) {
+ const adElement = adRef.current;
+ // AdSense sets data-ad-status="filled" when an ad loads
+ const adStatus = adElement.getAttribute('data-ad-status');
+ if (adStatus === 'filled') {
+ setAdFilled(true);
+ }
+ // Also check if child iframe exists (another indicator)
+ if (adElement.querySelector('iframe')) {
+ setAdFilled(true);
+ }
+ }
+ }, 1500);
+ } catch (err) {
+ console.error('AdSense error:', err);
+ }
+ };
+
+ // Small delay to ensure DOM is ready
+ const timer = setTimeout(loadAd, 100);
+ return () => clearTimeout(timer);
}, [isPaidUser, status]);
// Don't render anything if paid user
if (status === 'authenticated' && isPaidUser) return null;
+ // Don't render anything while session is loading
+ if (status === 'loading') return null;
+
return (
-