I am beginner in reactjs and I want to embed google inline ads in loops. The ad is showing only at first time. When I inspect the element tag shows in loop. Can I please kno
Answer by @jpgbarbosa is great. I'll add better practice for Server Side Rendered React applications which have multiple pages, for scalability, I suggest you use this method to keep code base maintainable.
export default class HomePage extends React.Component {
componentDidMount() {
const installGoogleAds = () => {
const elem = document.createElement("script");
elem.src =
"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
elem.async = true;
elem.defer = true;
document.body.insertBefore(elem, document.body.firstChild);
};
installGoogleAds();
(adsbygoogle = window.adsbygoogle || []).push({});
}
render() {
return (
);
}
}