mazipan / vue-google-adsense

💰 Vue.js Google Adsense Component with InFeed and InArticle Ads support
https://mazipan.github.io/vue-google-adsense/
MIT License
257 stars 42 forks source link

Nuxt.js Integration issues #50

Closed iiAku closed 4 years ago

iiAku commented 5 years ago

Hello, Thanks for this great adsense integration. I have seen the 2 closed issues regarding nuxt integration. I also track down how you integrated it into your blog. However it seems it's still hard to get adsense being integrated properly into nuxt.js

Added this to plugin list in nuxt.configs.js: { src: "~/plugins/vue-google-adsense", ssr: false } Created plugins/vue-google-adsense.js with following content

import Vue from "vue";
import Ads from "vue-google-adsense";

Vue.use(require("vue-script2"));

Vue.use(Ads.Adsense);

Tried to integrate (with and without data-ad-test prop):

    <Adsense
      data-ad-client="ca-pub-XXXXXXXXX"
      data-ad-slot="XXXXXXXXXX"
      data-ad-test="on"
    >
    </Adsense>

I noticed 2 issues while adding a Adsense component that might need to be indicated in the README.md.

First

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

I presume this is happening because the plugin has ssr-false option, so the renderer has sent an output which is different from the one actually generated. This can be fixed with a block or more recently (since no-ssr will be deprecated) .

Second

Setting the subdomain seems to fix at least an issue, I was constantly having 2 GET requests toward googleads.g.doubleclick.net where one of them was getting either a 400 or 403 status code. Once I added the subdomain to the verified domain I did not longer had this 400/403 error. Nevertheless it did not fixed my issue.

This way everything seems to be running fine, the adsense object even create extra space into the page but does not display. I disabled my adblocker, tried from firefox/brave/chrome where tracking/adblocker are normally disabled, none of them showed the advertisement. I have put the exact same advertisement on a php page from the exact same domain name and it has been displayed properly. Do you have any leads, tips or recommandations, thanks for your help and work.

158008001 commented 5 years ago

The code is very busy,Looking forward to updating~

mazipan commented 5 years ago

I am just using like this in my blog, file vue-google-adsense.js

import Vue from 'vue'
import Ads from 'vue-google-adsense'

Vue.use(require('vue-script2'))

Vue.use(Ads.Adsense)
Vue.use(Ads.InArticleAdsense)
Vue.use(Ads.InFeedAdsense)

if (process.env.ENABLE_ADS) {
  Vue.use(Ads.AutoAdsense, { adClient: process.env.ADS_CLIENT })
}