Mobile app version of vmapp.org
Login or Join
Welton855

: Blocking adsense ad units for a particular country So I have got one hater in India who bombarded on my adsense ad units. Luckily I didn't get banned from Google. I have blocked Indian visitors

@Welton855

Posted in: #CountrySpecific #GoogleAdsense #Wordpress

So I have got one hater in India who bombarded on my adsense ad units. Luckily I didn't get banned from Google. I have blocked Indian visitors from my site using iq-blockcountry plugin (wordpress). Now I want to know if there's any procedure so that I can allow the Indian visitors but hide the adsense units from them? I don't want to block all visitors just because of one foolish person.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton855

2 Comments

Sorted by latest first Latest Oldest Best

 

@Odierno851

Good way to do this is - switching from AdSense to DFP Small Business. You can display AdSense with DFP and apply Geo-targeting feature.


DPF help: Target line items to geographic areas
Sam Azgor: How to Block AdSense Being Shown In Specific Countries


(I do not know Sam Azgor, but that looks to me like very fine step-by-step explanation.)

That needs some time and effort and that is a good way. Now, the bad way - quick an risky: you can try some hacking in file iq-block-country.php, line 351:

if (is_array ( $badcountries ) && in_array ( $country, $badcountries )) {
$blockmessage = get_option ( 'blockcountry_blockmessage' );
header ( 'HTTP/1.1 403 Forbidden' );
print "<p><strong>$blockmessage</strong></p>";
exit ();
}


You may try this, instead:

if (is_array ( $badcountries ) && in_array ( $country, $badcountries )) {
define('ADSENSE_HEADER', '');
define('ADSENSE_CONTENT', '');
} else {
define('ADSENSE_HEADER', '<script type="text/javascript"><!--google_ad... etc... </script>');
define('ADSENSE_CONTENT', '<script type="text/javascript"><!--google_ad... etc... </script>');
}


And, in your template - just print them:

<?php echo ADSENSE_HEADER; ?>
<?php echo ADSENSE_CONTENT; ?>


Example above is also a good example of bad coding (downvoting would not be surprise here), but it is an answer, I believe.

Very important: if you go with "bad way" - prepare your backups. If something goes wrong, I can not help you. Consider that as a pseudocode, and if works - as a temporary solution, and ask "iq-blockcountry" developers to implement "AdSense feature".

10% popularity Vote Up Vote Down


 

@Goswami781

You could conditionally hide the ad block with some geolocation service. However you cannot be 100% sure that you are going to block all IPs from India.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme