31 lines
663 B
TypeScript
31 lines
663 B
TypeScript
"use client";
|
|
|
|
import Script from "next/script";
|
|
|
|
import { authClient } from "@/lib/auth/client";
|
|
|
|
const clientId = process.env.NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID?.trim();
|
|
|
|
export function GoogleAdsense() {
|
|
const { data: session, error, isPending } = authClient.useSession();
|
|
|
|
if (
|
|
process.env.NODE_ENV !== "production" ||
|
|
!clientId ||
|
|
isPending ||
|
|
error ||
|
|
session
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Script
|
|
id="google-adsense"
|
|
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${encodeURIComponent(clientId)}`}
|
|
strategy="afterInteractive"
|
|
crossOrigin="anonymous"
|
|
/>
|
|
);
|
|
}
|