Skip to content

Commit

Permalink
Add google adsense to page
Browse files Browse the repository at this point in the history
  • Loading branch information
llaoj committed Jun 27, 2024
1 parent e55be56 commit b5417bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "@/app/globals.css";
import { ReactNode } from "react";
import { getTranslations } from "next-intl/server";
import type { Viewport } from "next";
import GoogleAdsense from "@/components/google-adsense";

export async function generateMetadata({
params: { locale },
Expand Down Expand Up @@ -35,6 +36,7 @@ export default function RootLayout({
return (
<html lang={locale}>
<body className={`${inter.className} bg-base-200`}>{children}</body>
<GoogleAdsense pId={process.env.GoogleAdsensePId} />
</html>
);
}
15 changes: 15 additions & 0 deletions frontend/components/google-adsense.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Script from "next/script";

export default function GoogleAdsense({ pId }: { pId?: string }) {
if (process.env.NODE_ENV !== "production" || !pId) {
return null;
}

return (
<Script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${pId}"
crossOrigin="anonymous"
/>
);
}

0 comments on commit b5417bd

Please sign in to comment.