I am thinking for a passive income, that’s why I added Google Adsense
to my personal blog. But if user blocks the advertisement (by using adblock or something else), it means I receive nothing.
That’s why I will display a popup for reminding you to disable Adblock on my page.
Actually I use the Adblock also, to keep focus on the reading because there’re lots of page which have too much ads. But a minor ads in somewhere is acceptable also, that’s why I am asking my reader to disable it.
I found solutions here. The last one seems nice to me.
async function checkForAdBlocker() { | |
let Blocked; | |
async function Request() { | |
try { | |
return fetch( | |
new Request( | |
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", { | |
method: 'HEAD', | |
mode: 'no-cors' | |
})) | |
.then(function(response) { | |
// There is no AdBlocker | |
Blocked = false; | |
return Blocked; | |
}).catch(function(e) { | |
// Failed, Because of an AdBlocker | |
Blocked = true; | |
return Blocked; | |
}); | |
} catch (error) { | |
console.log(error); | |
Blocked = true; | |
return Blocked; | |
} | |
} | |
return Blocked !== undefined ? Blocked : await Request(); | |
} | |
const usingBlocker = await checkForAdBlocker(); |
But it seems too much to me, I just need simple one. I already have jQuery
, after some trying there’s my finally source.
Have a brief explain in the gist above also.
Looking for my first 100 bucks (the limit of being able to withdraw from Google)