Skip to content

Commit 6870067

Browse files
María Paz Arrieta LandazuriMaría Paz Arrieta Landazuri
authored andcommitted
add g analyti
1 parent bae94e9 commit 6870067

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

frontend/src/app/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./globals.css";
44
import Header from "./components/Header";
55
import Footer from "./components/Footer";
66
import GoogleAnalytics from "./components/GoogleAnalytics";
7+
import Script from "next/script";
78

89
const 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 />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)