File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import "./globals.css";
44import Header from "./components/Header" ;
55import Footer from "./components/Footer" ;
66import GoogleAnalytics from "./components/GoogleAnalytics" ;
7+ import Script from "next/script" ;
78
89const inter = Inter ( {
910 variable : "--font-inter" ,
@@ -28,6 +29,14 @@ export default function RootLayout({
2829} > ) {
2930 return (
3031 < html lang = "es" >
32+ < head >
33+ < Script
34+ async
35+ src = { `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ process . env . NEXT_PUBLIC_GOOGLE_ADSENSE_ID } ` }
36+ crossOrigin = "anonymous"
37+ strategy = "afterInteractive"
38+ />
39+ </ head >
3140 < body className = { `${ inter . variable } ${ roboto . variable } antialiased` } >
3241 < GoogleAnalytics />
3342 < Header />
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { useEffect } from 'react' ;
4+
5+ interface GoogleAdProps {
6+ adSlot : string ;
7+ adFormat ?: 'auto' | 'fluid' | 'rectangle' | 'vertical' ;
8+ style ?: React . CSSProperties ;
9+ }
10+
11+ export default function GoogleAd ( { adSlot, adFormat = 'auto' , style } : GoogleAdProps ) {
12+ useEffect ( ( ) => {
13+ try {
14+ // @ts -ignore
15+ ( window . adsbygoogle = window . adsbygoogle || [ ] ) . push ( { } ) ;
16+ } catch ( err ) {
17+ console . error ( 'Error loading Google Ad:' , err ) ;
18+ }
19+ } , [ ] ) ;
20+
21+ return (
22+ < ins
23+ className = "adsbygoogle"
24+ style = { style || { display : 'block' } }
25+ data-ad-client = { process . env . NEXT_PUBLIC_GOOGLE_ADSENSE_ID }
26+ data-ad-slot = { adSlot }
27+ data-ad-format = { adFormat }
28+ data-full-width-responsive = "true"
29+ />
30+ ) ;
31+ }
You can’t perform that action at this time.
0 commit comments