Nuxt access to Google Adsence recently in the study of access to Google Adsence, account review for a long time, did not pass, so guess is not the access code problem, so search data summarized nuxT access to Google Adsence way.

Method 1: Configure it in nuxt.config.js

This is seen in this blog markdowner.net/article/821…

Configure it under the Script tag

script: [
      {
       {
         async: true,
         src : "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
       },
       { 
         innerHTML: `
           (adsbygoogle = window.adsbygoogle || []).push({
             client=ca-pub-xxxxxxxxxxxx",
             enable_page_level_ads: true
           });
         `
       },
    ],
     __dangerouslyDisableSanitizers: ['script']
  },
Copy the code

Ca – pub – XXXXXXXXXXXX Google code, __dangerouslyDisableSanitizers: [‘ script ‘] role is embedded HTML code does not escape.

The green note indicates the access mode. However, this kind of access method will report a JS error in my page – this symbol problem, I don’t know if it will affect.

Method 2: Configure in template code

Create a new app.html file in the root directory with the following contents:

<! DOCTYPE html> <html {{ HTML_ATTRS }}> <head {{ HEAD_ATTRS }}> <script data-ad-client="ca-pub-xxxxxxxx" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> {{ HEAD }} </head> <body {{ BODY_ATTRS }}> {{ APP }} </body> </html>Copy the code

Finally, I took the second option, which I thought was a little more convenient.