I am using Google Adsense for my website, the ads are shown successfully, but when I want to show ad in one component and ad in another component, then in only one component it works and every time it works on the one component(which is on the left side)
Component One
HTML
<div class="text-center">
<ins class="adsbygoogle ads_resp" style="display:inline-block" data-ad-client="publisherid" data-ad-slot="ad unit id"
data-full-width-responsive="true"></ins>
</div>
TS
declare interface Window { adsbygoogle: any[]; }
declare var adsbygoogle: any[];
export class OneComponent implements OnInit {
ngAfterViewInit() {
setTimeout(() => {
try {
(adsbygoogle = window["adsbygoogle"] || []).push({});
/* or
(window["adsbygoogle"] = window["adsbygoogle"] || []).push({}); Both are wrking finr*/
} catch (e) {
console.error('adsid',e);
}
}, 300);
}
}
The same code is written in the other component
and the both components are wrapped in another component like
I want to put the ad in both one and other component, when I put the ads in both, then on the left side ad shows and in the right only blank space, if I use ads only in one or other component then it works fine.
One more interesting thing, on the main page of the website(left side), when I put two ad codes then two ads are showing but when the same put on the right side it won't works
In the other pages, only 1 ad is showing unable to show two ads, the two ads are shown only in the left side of the main page.