cat ./posts/adsense-slot-id-guide.en.md
AdSenseのslot IDをURLと広告コードから設定する手順
# AdSenseのpublisher ID、slot ID、ads.txt、環境変数の関係を、ブログ運用で迷わないように整理します。
grep -R tag ./posts
cat ./posts/adsense-slot-id-guide.en.md
# AdSenseのpublisher ID、slot ID、ads.txt、環境変数の関係を、ブログ運用で迷わないように整理します。
grep -R tag ./posts
まだコメントはありません。
AdSenseをブログに入れるときは、まず2つのIDを分けて考えると迷いにくくなります。data-ad-client に入る ca-pub-... が publisher/client ID、広告ユニットごとに発行される data-ad-slot が slot ID です。
1. Google AdSense にログインします。
2. 「広告」から対象サイトを登録し、審査に進めます。
3. 「広告ユニットごと」でディスプレイ広告などを作成します。
4. 表示された広告コードを確認します。
5. `data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"` を `NEXT_PUBLIC_ADSENSE_CLIENT` に設定します。
6. `data-ad-slot="1234567890"` を `NEXT_PUBLIC_ADSENSE_SLOT` に設定します。
7. `/ads.txt` が `google.com, pub-xxxxxxxxxxxxxxxx, DIRECT, f08c47fec0942fa0` を返すことを確認します。
このサイトでは NEXT_PUBLIC_ADSENSE_CLIENT があると AdSense の script を読み込み、NEXT_PUBLIC_ADSENSE_SLOT があると広告枠に slot ID を渡します。slot ID が未設定のときは、レイアウト確認用のスポンサー枠として表示されます。
• https://support.google.com/adsense/answer/105516
• https://support.google.com/adsense/answer/6307124