update adsense
This commit is contained in:
parent
11c425e409
commit
cd6515ba65
@ -2,7 +2,16 @@
|
|||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Load the Google AdSense script if it hasn't been added yet.
|
// Set up Google Consent Mode before loading AdSense
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag() {
|
||||||
|
window.dataLayer.push(arguments);
|
||||||
|
}
|
||||||
|
gtag("consent", "default", {
|
||||||
|
ad_storage: "denied",
|
||||||
|
analytics_storage: "denied",
|
||||||
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!document.querySelector(
|
!document.querySelector(
|
||||||
'script[src*="googlesyndication.com/pagead/js/adsbygoogle.js"]',
|
'script[src*="googlesyndication.com/pagead/js/adsbygoogle.js"]',
|
||||||
@ -16,8 +25,6 @@
|
|||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push to adsbygoogle after the script has loaded
|
|
||||||
// You might need a small delay if the script isn't immediately ready.
|
|
||||||
const loadAds = () => {
|
const loadAds = () => {
|
||||||
try {
|
try {
|
||||||
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
||||||
@ -26,11 +33,9 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if the ads script is loaded, then load the ads.
|
|
||||||
if (window.adsbygoogle) {
|
if (window.adsbygoogle) {
|
||||||
loadAds();
|
loadAds();
|
||||||
} else {
|
} else {
|
||||||
// If not, add an event listener to load ads once the script loads.
|
|
||||||
window.addEventListener("load", loadAds);
|
window.addEventListener("load", loadAds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user