Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Metadata } from 'next';
import localFont from 'next/font/local';
import Script from 'next/script';
import './globals.css';
import Header from '@/components/layout/Header';
import Footer from '@/components/layout/Footer';
Expand All @@ -23,6 +24,14 @@ export default function RootLayout({ children }: { children: React.ReactNode })
return (
<html lang="ko">
<body className={`${pretendard.variable} font-pretendard flex min-h-dvh flex-col`}>
{process.env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID && (
<Script
async
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${process.env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID}`}
crossOrigin="anonymous"
strategy="afterInteractive"
/>
)}
<QueryProvider>
<FirebaseProvider>
<AuthInitializer />
Expand Down
40 changes: 40 additions & 0 deletions src/components/ads/AdSense.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use client';

import { useEffect } from 'react';

interface AdSenseProps {
slot: string;
style?: React.CSSProperties;
className?: string;
format?: 'auto' | 'fluid' | 'rectangle' | 'vertical' | 'horizontal';
responsive?: boolean;
}

export default function AdSense({
slot,
style,
className,
format = 'auto',
responsive = true,
}: AdSenseProps) {
const publisherId = process.env.NEXT_PUBLIC_ADSENSE_PUBLISHER_ID;

useEffect(() => {
try {
(window.adsbygoogle = window.adsbygoogle || []).push({});
} catch {}
}, []);

if (!publisherId) return null;

return (
<ins
className={`adsbygoogle${className ? ` ${className}` : ''}`}
style={{ display: 'block', ...style }}
data-ad-client={publisherId}
data-ad-slot={slot}
data-ad-format={format}
data-full-width-responsive={responsive ? 'true' : 'false'}
/>
);
}
3 changes: 3 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Window {
adsbygoogle: unknown[];
}