Skip to content

Instantly share code, notes, and snippets.

@piotrkulpinski
Created July 24, 2025 20:07
Show Gist options
  • Select an option

  • Save piotrkulpinski/b4b86ab264a8052b63c498648b817af4 to your computer and use it in GitHub Desktop.

Select an option

Save piotrkulpinski/b4b86ab264a8052b63c498648b817af4 to your computer and use it in GitHub Desktop.
"use client"
import { useEffect } from "react"
import { env, isDev } from "~/env"
type AdGoogleProps = {
adSlot: string
adLayoutKey: string
adFormat?: string
fullWidthResponsive?: boolean
}
export const AdGoogle = ({
adSlot,
adLayoutKey,
adFormat = "fluid",
fullWidthResponsive = true,
}: AdGoogleProps) => {
useEffect(() => {
try {
window.adsbygoogle = window.adsbygoogle || []
window.adsbygoogle.push({})
} catch (error: any) {
console.log(error.message)
}
}, [])
return (
<ins
className="adsbygoogle block w-full"
data-ad-client={env.NEXT_PUBLIC_GOOGLE_ADS_PUBLISHER_ID}
data-ad-slot={adSlot}
data-ad-format={adFormat}
data-ad-layout-key={adLayoutKey}
data-adtest={isDev ? "on" : "off"}
data-full-width-responsive={fullWidthResponsive.toString()}
/>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment