Google AdSense 表示 (特定ページのみ)
方針
- 特定ページにだけ表示したい
表示例
コンポーネントの定義
src/components/AdSenseResponsive.tsx
import { useEffect } from 'react';
export default function AdSenseResponsive() {
useEffect(() => {
try {
((window as any).adsbygoogle = (window as any).adsbygoogle || []).push({});
} catch (e) {
console.error(e);
}
}, []);
return (
<>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" />
<ins
className="adsbygoogle"
style={{ display: 'block' }}
data-ad-client="ca-pub-XXXXXXXXXXXXXX"
data-ad-slot="XXXXXXXXX"
data-ad-format="auto"
data-full-width-responsive="true"
/>
</>
);
}
呼び出し
mdx
import AdSenseResponsive from '@site/src/components/AdSenseResponsive';
<AdSenseResponsive />