feat: integrate Google AdSense with publisher ca-pub-3876936176422477
This commit is contained in:
parent
7bfdaafc10
commit
fffbb1b2ff
3 changed files with 22 additions and 16 deletions
|
|
@ -70,10 +70,11 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||||
name="google-site-verification"
|
name="google-site-verification"
|
||||||
content="t_GK2K5w97K3W9jIuzdmPKGu-STw4fagx-5jYQib4yE"
|
content="t_GK2K5w97K3W9jIuzdmPKGu-STw4fagx-5jYQib4yE"
|
||||||
/>
|
/>
|
||||||
{/* Adsterra Network Script */}
|
{/* Google AdSense */}
|
||||||
<Script
|
<script
|
||||||
src="https://pl31295441.profitableratecpmnetwork.com/fd/4a/91/fd4a9155d8cc10399821f613377ee9f1.js"
|
async
|
||||||
strategy="afterInteractive"
|
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3876936176422477"
|
||||||
|
crossOrigin="anonymous"
|
||||||
/>
|
/>
|
||||||
</head>
|
</head>
|
||||||
<body className="dot-bg-fade flex min-h-full flex-col bg-black text-foreground">
|
<body className="dot-bg-fade flex min-h-full flex-col bg-black text-foreground">
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export default function AdSlot({ slot, format = "auto", className = "" }: AdSlot
|
||||||
<ins
|
<ins
|
||||||
className="adsbygoogle"
|
className="adsbygoogle"
|
||||||
style={{ display: "block" }}
|
style={{ display: "block" }}
|
||||||
data-ad-client="ca-pub-XXXXXXXXXXXXXXXX"
|
data-ad-client="ca-pub-3876936176422477"
|
||||||
data-ad-slot={slot}
|
data-ad-slot={slot}
|
||||||
data-ad-format={format}
|
data-ad-format={format}
|
||||||
data-full-width-responsive="true"
|
data-full-width-responsive="true"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
interface SidebarAdProps {
|
interface SidebarAdProps {
|
||||||
slotId?: string;
|
slotId?: string;
|
||||||
|
|
@ -8,18 +8,15 @@ interface SidebarAdProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SidebarAd({ format = "vertical", className = "" }: SidebarAdProps) {
|
export default function SidebarAd({ slotId, format = "vertical", className = "" }: SidebarAdProps) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!containerRef.current) return;
|
|
||||||
try {
|
try {
|
||||||
const script = document.createElement("script");
|
if (typeof window !== "undefined") {
|
||||||
script.src = "https://pl31295441.profitableratecpmnetwork.com/fd/4a/91/fd4a9155d8cc10399821f613377ee9f1.js";
|
// @ts-expect-error Google ads window object
|
||||||
script.async = true;
|
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
||||||
containerRef.current.appendChild(script);
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore network blocks
|
// Ignore if AdSense blocked by client
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
@ -34,7 +31,15 @@ export default function SidebarAd({ format = "vertical", className = "" }: Sideb
|
||||||
Ad
|
Ad
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div ref={containerRef} className="w-full flex items-center justify-center min-h-[250px]" />
|
{/* Google AdSense Unit */}
|
||||||
|
<ins
|
||||||
|
className="adsbygoogle block w-full h-full"
|
||||||
|
style={{ display: "block" }}
|
||||||
|
data-ad-client="ca-pub-3876936176422477"
|
||||||
|
data-ad-slot={slotId || "1234567890"}
|
||||||
|
data-ad-format={format === "vertical" ? "vertical" : "auto"}
|
||||||
|
data-full-width-responsive="true"
|
||||||
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue