Skip to content

VuepressでGoogle AdSense広告を表示できるようにします.

本稿の設定の利点は,自分で広告コードを貼り付ける必要がなくなることです.

Google AdSenseに登録

()を参照してください.

.vuepress/config.jsの書き換え

以下のコードをに追記します.

js
module.exports = {
  ...
  head: [
    ...
    [
      "script",
      {
        "async src": "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
      }
    ],
    [
      "script",
      {},
      '(adsbygoogle = window.adsbygoogle || ).push({  google_ad_client: "ca-pub-0000000000000000",  enable_page_level_ads: true });'
    ]
  ],
  ...
}

あとは,Google AdSenseに飛んで,自動最適化の設定をします.

参考サイト

Google AdSense

VuePress に広告を表示する

VuePress に広告を表示する2