Google adsense plugin for vuepress
Use google automatic advertisement for your vuepress site. (Follow Google Ad Code Implementation Guide)
yarn add -D vuepress-plugin-google-adsense
# OR
# npm install -D vuepress-plugin-google-adsense
module.exports = {
plugins: [
[
"vuepress-plugin-google-adsense",
{
adClient: "ca-pub-2245427233262012", // replace it with your adClient
},
],
],
};
More Info: Using a Plugin
If you don't have a google adsense account, you need register one here.
If you pass, google adsense will give you a script like this.
<script
data-ad-client="ca-pub-2245427233262012"
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
></script>
In fact, when this plugin was developed, Google's automatic adsense code was not as simple as it is now.
And now, you can just insert the following code in config.js
instead of this plugin.
module.exports = {
head: [
[
"script",
{
"data-ad-client": "ca-pub-2245427233262012",
async: true,
src: "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
},
],
],
};
One advantage of plugin is that it can decide whether to show by ctx.isProd.
Name | Type | Required | Default | Description |
---|---|---|---|---|
adClient | string | true | undefined | Provide the Google Adsense ID to enable integration. |
adsTxt | boolean | false | false | Whether to generate ads.txt |
If you enable it, the following content will be generated in ads.txt
.
google.com, pub-2245427233262012, DIRECT, f08c47fec0942fa0