Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ad blocker from blocking ads on an app

One of my users let the cat out of the bag and told me they were using one of my free apps, which is monetized by ads, but they were blocking the ads with an ad blocker. They told me this mockingly, as if I can't do anything about it.

Can I do something about it? Is there a way to detect that ads are being blocked?

like image 329
Christopher Perry Avatar asked Aug 10 '10 19:08

Christopher Perry


1 Answers

I am aware of one way that ad blocking works (on any computer really), they edit the hosts file to point to localhost for all known ad servers. For android this is located in the "etc/hosts" file.

For example, I use admob ads and a host file that I have taken from custom rom lists the folowing admob entries:

127.0.0.1 analytics.admob.com 127.0.0.1 mmv.admob.com 127.0.0.1 mm.admob.com 127.0.0.1 admob.com 127.0.0.1 a.admob.com 127.0.0.1 jp.admob.com 127.0.0.1 c.admob.com 127.0.0.1 p.admob.com 127.0.0.1 mm1.vip.sc1.admob.com 127.0.0.1 media.admob.com 127.0.0.1 e.admob.com 

Now anytime a process tries to resolve the above addresses they are routed to the address listed to the left of them (localhost) in this case.

What I do in my apps is check this host file and look for any admob entries, if I find any I notify the user that I've detected ad blocking and tell them to remove admob entries from there and do't allow them use of the app.

After all what good does it do me if they're not seeing ads? No point in letting them use the app for free.

Here is a code snippet of how I achieve that:

        BufferedReader in = null;      try      {         in = new BufferedReader(new InputStreamReader(                 new FileInputStream("/etc/hosts")));         String line;          while ((line = in.readLine()) != null)         {             if (line.contains("admob"))             {                 result = false;                 break;             }         }     }  

I vow that all ad supported apps should check this file. You do not need to be root in order to access it, but writing to it might be a different story.

Also, not sure if there is any other files that act the same on a linux based OS, but at any rate we can always check all of those files.

Any suggestions on improving this are welcome.

Also the app called "Ad Free android" needs root access, meaning that it most likely changes the hosts file in order to achieve its goal.

like image 88
Ivan Avatar answered Sep 22 '22 13:09

Ivan