Method 1 - Using the Community Package
The first method is to use the community package nuxt-community/google-adsense-module and this will ensure the right configuration be placed in the application.
yarn add @nuxtjs/google-adsense
const config = { modules: [ ['@nuxtjs/google-adsense'] ], 'google-adsense': { id: 'ca-pub-#########' } } export default config
Method 2 - Override App.html Template
The 2nd method will override the default app template that Nuxt has by default. By default, every page will extend from this template and it's perfect to define global changes.
<!DOCTYPE html> <html {{ HTML_ATTRS }}> <head {{ HEAD_ATTRS }}> {{ HEAD }} <script data-ad-client="ca-pub-#########" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> </head> <body {{ BODY_ATTRS }}> {{ APP }} </body> </html>
Method 3 - Update nuxt.config.js head configuration
The last method would be to update the head configuration of the nuxt.config.js file. It will look as follow.
const config = { head: { script: [ { src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', 'data-ad-client': 'ca-pub-#########', async: true } ] } } export default config