From 7b18fd53baa75498de06422eb07e5cd2cdbbbaa4 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 27 Mar 2026 12:51:18 +0200 Subject: [PATCH] feat: enhance ad initialization and display logic, add Ezoic methods, and improve ad rendering conditions --- app/[locale]/layout.tsx | 2 ++ src/components/ads/EzoicAd.tsx | 6 +++++- src/components/ads/HorizontalAdBanner.tsx | 8 ++++++-- src/components/ads/InArticle.tsx | 25 +++++++++++++++-------- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index ae42c41..5121e72 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -268,6 +268,8 @@ export default async function RootLayout({ params, children }: RootLayoutProps) window.ezstandalone = window.ezstandalone || {}; ezstandalone.cmd = ezstandalone.cmd || []; ezstandalone.cmd.push(function() { + ezstandalone.enable(); + ezstandalone.display(); ezstandalone.initRewardedAds({ anchor: false, interstitial: false, diff --git a/src/components/ads/EzoicAd.tsx b/src/components/ads/EzoicAd.tsx index 7734d37..13211a6 100644 --- a/src/components/ads/EzoicAd.tsx +++ b/src/components/ads/EzoicAd.tsx @@ -11,7 +11,11 @@ declare global { interface Window { ezstandalone: { cmd: Array<() => void>; - showAds: (placementId?: string | string[]) => void; + define: (...placementIds: (string | number)[]) => void; + enable: () => void; + display: () => void; + refresh: () => void; + showAds: (...placementIds: (string | number)[]) => void; }; } } diff --git a/src/components/ads/HorizontalAdBanner.tsx b/src/components/ads/HorizontalAdBanner.tsx index 447e605..0285e0c 100644 --- a/src/components/ads/HorizontalAdBanner.tsx +++ b/src/components/ads/HorizontalAdBanner.tsx @@ -29,10 +29,14 @@ export function HorizontalAdBanner({ adSlot, ezoicPlacementId }: HorizontalAdBan return ( <> - {/* Below lg: always show sponsor carousel */} + {/* Below lg: show ezoic if configured, otherwise sponsor carousel */}
- + {useEzoic ? ( + + ) : ( + + )}
diff --git a/src/components/ads/InArticle.tsx b/src/components/ads/InArticle.tsx index f4d7488..bc7e563 100644 --- a/src/components/ads/InArticle.tsx +++ b/src/components/ads/InArticle.tsx @@ -1,11 +1,17 @@ +import { GoogleAdSense } from "./GoogleAdSense"; +import { EzoicAd } from "./EzoicAd"; +import { SponsorHorizontalBanner } from "./custom"; +import { AdWrapper } from "./AdWrapper"; + import { env } from "@/env"; import { AdPlaceholder } from "@/components/ads/AdPlaceholder"; -import { GoogleAdSense } from "./GoogleAdSense"; -import { AdWrapper } from "./AdWrapper"; -import { SponsorHorizontalBanner } from "./custom"; +interface InArticleProps { + adSlot?: string; + ezoicPlacementId?: string; +} -export function InArticle({ adSlot }: { adSlot: string }) { +export function InArticle({ adSlot, ezoicPlacementId }: InArticleProps) { if (env.NEXT_PUBLIC_AD_PROVIDER === "custom") { return ( @@ -17,8 +23,9 @@ export function InArticle({ adSlot }: { adSlot: string }) { } const isDevelopment = process.env.NODE_ENV === "development"; + const useEzoic = env.NEXT_PUBLIC_AD_PROVIDER === "ezoic" && ezoicPlacementId; - if (!env.NEXT_PUBLIC_AD_CLIENT) { + if (!env.NEXT_PUBLIC_AD_CLIENT && !useEzoic) { return null; } @@ -28,9 +35,11 @@ export function InArticle({ adSlot }: { adSlot: string }) {
{isDevelopment ? ( - ) : ( + ) : useEzoic ? ( + + ) : adSlot ? ( - )} + ) : null}