Using Google Adsense in a Preact-CLI project
See original GitHub issueHi guys!
I have an issue and I’ve spent A LOT OF TIME trying to solve this. I am trying to add the Google Adsense code to my project. My status stays stuck at: “Your site needs work”. The additional information explains that Google can’t find the code. Eventhough I’ve added it (in multiple ways).
What I’ve found out is that everytime this code:
<script data-ad-client="ca-pub-#####" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
gets transformed to this code:
<script data-ad-client="ca-pub-#####" async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" data-checked-head="true"></script>
This is how I’m trying to add the code:
Option 1: In my app.js file
componentDidMount() {
//SetAdsense
let script = document.createElement('script');
script.setAttribute('data-ad-client','ca-pub-########' );
script.setAttribute('async');
script.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
document.getElementsByTagName('head')[0].appendChild(script);
}
Option 2: Using Helmet
<Helmet>
<script data-ad-client="ca-pub-#####" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</Helmet>
Any idea how I can make Google see the provided Adsense code in my Head?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
(we discussed elsewhere but I’ll echo here for others)
In 2.2.1, the
--template
argument was relative to thesrc
directory. Here’s how to use it:package.json
:src/template.html
:https://github.com/preactjs-templates/netlify/blob/master/template/src/template.html If you update to preact-cli v3 it should generate the template in your project dir you can insert stuff into