Nuxt Google Adsense
October 4, 2020Via Nuxt Plugin
You can use @nuxtjs/google-adsense.
NOTE: The plugin has not been updated since Jan 2018, but it still works.
Install
npm install --save-dev @nuxtjs/google-adsense
Edit nuxt.config.js
export default {
buildModules: [
'@nuxtjs/google-adsense'
],
'google-adsense': {
id: 'ca-pub-8122716156XXXXXX'
}
}
NOTE: Adsense is disabled in development mode
Via Meta Head Script
Edit layouts/default.vue
<script>
export default {
head() {
let productionScripts = []
if (process.env.NODE_ENV === 'production') {
productionScripts = [
{ hid: 'adsense', src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', defer: true, 'data-ad-client': 'ca-pub-8122716156XXXXXX' },
]
}
return {
title: "Test Adsense",
script: [
].concat(productionScripts),
}
},
}
</script>
You might get the following warning, but it should be fine.
adsbygoogle.js:218 AdSense head tag doesn't support data-n-head attribute.
adsbygoogle.js:218 AdSense head tag doesn't support data-hid attribute.
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn