config adsense
This commit is contained in:
1 parent
4cb4a46def
commit
28e6893934
2 files changed
+4
-3
No files matched your search
@@ -34,9 +34,11 @@ export const AdSlot: React.FC<AdSlotProps> = ({ placement, className = '' }) =>
|
||||
}
|
||||
};
|
||||
|
||||
if (document.querySelector('script[data-adsense-loader]')) {
|
||||
const scriptExists = !!document.querySelector('script[src*="adsbygoogle.js"]');
|
||||
if (scriptExists) {
|
||||
pushAd();
|
||||
} else {
|
||||
// Wait a short moment for the AdSense script to load, then try again
|
||||
window.setTimeout(pushAd, 250);
|
||||
}
|
||||
}, [canRenderAd]);
|
||||
|
||||
+1
-2
@@ -4,12 +4,11 @@ import './index.css';
|
||||
import App from './App.tsx';
|
||||
|
||||
const adsenseClient = import.meta.env.VITE_ADSENSE_CLIENT;
|
||||
if (adsenseClient && typeof document !== 'undefined' && !document.querySelector('script[data-adsense-loader]')) {
|
||||
if (adsenseClient && typeof document !== 'undefined' && !document.querySelector('script[src*="adsbygoogle.js"]')) {
|
||||
const script = document.createElement('script');
|
||||
script.async = true;
|
||||
script.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${encodeURIComponent(adsenseClient)}`;
|
||||
script.crossOrigin = 'anonymous';
|
||||
script.dataset.adsenseLoader = 'true';
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user