I configured “Adsense Invalid Click Protector” for this site whose theme is Cocoon!
Firstly I assumed installing and configuring below screen are enough.
It doesn’t make sense if you don’t implement code on your site.
(゚Д゚)
So I rushed to implement it.
– As engineer we always need to check actual behavior…
In concrete I performed below list.
1. Installing plugin 2. Configuring 3. Implementing short code 4. Replacing adsense code by short code 5. Checking if short code works fine
This video is useful.
Installing plugin
As you may finished, install it.
Configuring
Let’s go to configuration page.
Basically default settings are enough for most of users.
I investigated what each settings are.
# | Item | Description |
1 | Set the Ad Click Limit | How many clicks you can accept in period |
2 | Click Counter Cooke Expiration Time (default: 3 hours) | When to reset click counts |
3 | Set the Visitor Ban Duration (default: 7 days) | How many days to bann when limit of click count exceeds |
4 | Do you want to use the IP-API Pro key? | This plugin recommends to use IP-API Pro edition if your site has access more than 150 per minute. |
5 | Provide your IP-API Pro key | Key parameter if you use IP-API Pro. |
6 | Do you want to block showing ads for some specific countries? | If you want to avoid to be clicked from some countries, please activate. |
7 | Banned Country List – Put ISO ALPHA-2 Country Codes (Comma Seperated) | Country code which you don’t want to allow to click. If you want to set up multiple countries, separator commna “,” should be used. |
From 1 to 3
It’s easy!
Only you need to set below parameters.
– How many clicks you accept?
– When you want to reset click counter?
– How long you want to ban if click count exceeds?
Be careful one point which manages data both Cookie and database of this plugin.
It means,
– Cookie is stored in storage of browser of client
– database is stored in your server
So you need to be careful if you want to remove client from banned list.
Because even if you remove some clients from banned list, it doesn’t touch Cookie data and mismatch between Cookie and database.
So i would recommend to wait until Cookie data is removed.
From 4 to 5
This plugin uses IP-API.com to get client information, whose free edition has limit to allow up to 150 accesses per minute.
– If exceeding HTTP 503 will be replied.
If you are managing business or marchant site, 150 is not enough.
So you need to think about introducing Pro edition.
I guess if you have contract of Pro edition you can get some key string then you shall paste to here.
From 6 to 7
You can limit clicking your Google Adsense from specific country.
But… I cannot imagine this situation which allows accessing site itself but clicking adsense code…
Implementing short code
Let’s finish setup and make it works!
This site uses 3 types of ads.
I will create corresponding short codes.
Type | Short code |
Square | square_ad |
Infeed | infeed_ad |
Wide | wide_ad |
To implement short code, functions.php in child theme of Cocoon should be modified.
Source code
ID are hidden in below code, but essense of source code can be useful.
This is sample of square ads, but other 2 types are almost the same.
This function does,
Judging to show ads by aicp_can_see_ads() If OK then display ads as is If NG then display error code
From line 9 to line 21 is ads code.
You can replace by your ads code.
// This line links short code 'square_ad' and suare_ad_func() which is implemantation of square_ad add_shortcode('square_ad', 'square_ad_func'); // This is implementation of short code for square type ads function square_ad_func() { if(aicp_can_see_ads()) { $adCode = ' <div class="aicp"> <script async src="//pageads2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-XXXXXXXXXXXXXXXX" data-ad-slot="XXXXXXXXXX" data-ad-format="auto" data-full-width-responsive="true"> </ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> '; return $adCode; } else { return '<div class="error">You have been blocked from seeing ads.</div>'; } } // As well as square_ad, infeed_ad/wide_ad shall be defined add_shortcode('infeed_ad', 'infeed_ad_func'); function infeed_ad_func() { (snip) } add_shortcode('wide_ad', 'wide_ad_func'); function wide_ad_func() { (snip) }
Replacing adsense code by short code
You can deploy your short code as usual.
From customize,
Input short code to your widget.
Checking if short code works fine
To validate short code, putting your country to banned country list is easy.
It will be OK if your access is banned.
Conclusion
How was it?
I assume some people thinks installing plugin is enough, isn’t it?
I would be very appreciated if this article helps you!
Please post comment or messaging on SNS if you like it!
Comments