whatapalaver
whatapalaver

Reputation: 915

Implementing Google Adsense with Rails 6

I have followed the advice on the google adsense website instructing me to add the following code within the tag of my pages.

<script data-ad-client="ca-pub-64xxxxxxxxxxx" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

I have implemented this by adding it to my application.html.erb file.

Having deployed this to Heroku when I first load the page I get the following console error:

googleads.g.doubleclick.net/pagead/ads?guci=1.2.0.0.2.2.0.0&client=ca-pub-64xxxxxxxx Failed to load resource: the server responded with a status of 403 ()

I suspect that I may have to wait for the ads to start propagating despite having a validated site but I have a second problem:

Then after navigating to a different page on my site I get:

adsbygoogle.js:72 Uncaught P {message: "adsbygoogle.push() error: Only one AdSense head tag supported per page. The second tag is ignored.", name: "TagError", pbr: true, stack: "TagError: adsbygoogle.push() error: Only one AdSen…lesyndication.com/pagead/js/adsbygoogle.js:238:39"}

I haven't duplicated the code in my tag but I was wondering if this was a feature of turbolinks.

My site is verified and I have enabled auto ads but I think there is problem relating to my implementation. Does anyone have experience of implementing google ads in Rails 6 applications with turbolinks 5?

Upvotes: 0

Views: 963

Answers (1)

Mikita Belahlazau
Mikita Belahlazau

Reputation: 15419

403 Issue

I think you are right. It takes time to propagate. If it persists over couple of days - then there is something else. Are you still getting this error?

Only one AdSense head tag supported per page error

ThIt might be related to some framework feature, yes. But this error is harmless overall, it doesn't affect serving of ads. When you say "navigating to a different page" - do you know if it reloads the page or just updates html without reloading? If it's the latter then when the framework fetches second page and renders it - it's likely that page also has an adsbygoogle.js tag. Given that page is not reloaded - the old adsbygoogle.js tag is still loaded and you get this error.

Upvotes: 1

Related Questions