nuxt-modules / google-adsense

Google AdSense module for Nuxt.js
MIT License
204 stars 64 forks source link

Ads showing only on page reload #123

Open kovaletsyurii opened 3 years ago

kovaletsyurii commented 3 years ago

I have inserted an ad to the my page using this module and this ad works only with full page reload (for example when reload the page in browser or paste direct link on address field). When I open this page from my application (by clicking nuxt-link or after $route.push) ad wasn't load. my nuxt-config looks like:

modules: [
    ['@nuxtjs/google-adsense']
  ],
  'google-adsense': {
    id: 'ca-pub-xxxxxx',
    test: false,
    //onPageLoad: true //I've also try to set this property true but it doesn't help
  },

and in my *.vue file:

  <div class="my-ad-banner">
            <adsbygoogle
              :ad-style="{display: 'block!important', width: '208px'}"
              ad-client="ca-pub-xxxx"
              ad-slot="1231312312"
              ad-format="auto"
              full-width-responsive
            ></adsbygoogle>
          </div>
.my-ad-banner {
    min-width: 208px;
    margin-bottom: 16px;
  }
thor-n commented 2 years ago

I have same problem, did you find a solution?

i330z commented 2 years ago

@kovaletsyurii @thor-n have you tired by using no-prefetch in nuxt-link ??

modbender commented 1 year ago

The reason this happens is exactly because the page is loaded using nuxt-link/router page load

This type of loading doesn't cause browser to reload, and hence the global variable window which is used to store Google ads initialization is never cleared out.

Hence when you change page you might see in console errors saying something like slot already assigned or similar

modbender commented 1 year ago

The latest version for nuxt 3 seems to already have fixed this

https://github.com/nuxt-modules/google-adsense/blob/master/src/runtime/components-v3/Adsbygoogle.vue

By calling updateAd the complete initialization is re-run causing ads to render

This issue can probably be closed