How to hide (AdSense) ads in your mobile app or webview app

Some publishers are using plugins or services to create an app for smartphones from their websites. It is good practice to disable ads from ad networks like Google AdSense in an app because you are not allowed to use them there. This tutorial shows you how to do that.

There are two methods to disable ads from your webview app. The solution you need to choose depends on the technology used by the software that creates the app. All cases I have seen so far are covered by the two methods described below.

How to test which solution might work

Before we set up the solution to hide ads from your mobile app, we need to find out how to identify it on our website.

To do this, you can set up an ad with the purpose to show these information.

  1. go to Advanced Ads > Ads and create a new ad
  2. add a title like “User Agent and Referrer URL Test”
  3. choose the Plain Text and Code ad type and add the following code to the input field:
<div style="width: 300px; height: 250px; background: #428bca; color: #fff; text-align: center; font-size: 1.8em; overflow: scroll;">
	<p>User Agent: <?php echo isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'user agent not set'; ?></p>
	<p>Referrer URL: <?php echo isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'referrer not set'; ?></p>
</div>Code language: HTML, XML (xml)
  1. enable the Allow PHP option
Ad code field with HTML and PHP code to show User Agent and URL referrer.
Set up the test ad like on the screenshot
  1. publish the ad
  2. either choose a placement to embed the ad on every page or use the shortcode to place it only on one

Now, visit the page where you placed the ad code in your web app. You might need to refresh any caches to see the ad.

The output could look like this:

example of an ad output
Example of the test ad output in the mobile app.

You either find a trace of the mobile app in the User Agent or Referrer URL. In this case, we see one in the Referrer URL and can choose the appropriate solution below.

Disable ads using the User Agent condition

Use this method to remove ads from the web app if it identifies itself through the user agent string. This solution uses the User Agent visitor condition included in Advanced Ads Pro.

  1. go to the edit page of the ad
  2. navigate to Visitor Conditions and select the User Agent condition
  3. choose “does not contain” and enter a unique part of the user agent string. It does not have to be the full string
  4. save the changes
Option to remove ad from mobile app that uses a specific user agent string.
Example of using the User Agent condition to hide ads from apps that write “mobile-webview” into their user agent

The ad is now visible on your website and not in the webview app anymore.

Disable ads using the Referrer URL condition

The example from our test ad above shows how to identify the view of the mobile app when using the WPMobile.APP plugin to create it.

To remove AdSense or any other ads from this app version, we are using the Referrer URL condition in Advanced Ads Pro.

  1. go to the edit page of the ad
  2. navigate to Visitor Conditions and select the Referrer URL condition
  3. choose “does not contain” and enter the parameter that is used by the mobile app to identify itself
  4. save the changes
Example of the Referrer URL condition set up to hide ads from mobile apps that identify through a referrer URL.
Example of the Referrer URL condition set up to hide ads from WPMobile.APP.

The ad is now only visible in your web version and not in the mobile app anymore.

The author of the WPMobile.APP plugin made us aware that one can also use the HTTP_X_WPAPPNINJA cookie as a basis to disable ads in the mobile app view.

With Advanced Ads Pro being installed, follow these steps.

  1. go to the edit page of the ad
  2. navigate to Visitor Conditions and select the Cookie condition
  3. choose “is not” and leave the field for the value empty
  4. save the changes
Option to deliver ads based on cookies set for the HTTP_X_WPAPPNINJA cookie
Example of the Cookie condition set up to hide ads from WPMobile.APP.

This condition reads as: show this ad only if the HTTP_X_WPAPPNINJA cookie is not present.

Other methods

The above methods are the ones we have worked with so far. Please let us know if you run into different cases.

Developers can also output the whole content of the $_SERVER global array to check if there are other identifies. I am happy to update this tutorial accordingly.

Author image Thomas

Starting in 2009, Thomas’ own word game website grew to 40 MM page impressions per month. He then built Advanced Ads to help his colleagues to place ads and test different ad positions and networks tests without any coding skills. Thomas now enjoys improving the product for our more than 150,000 users worldwide.

With over a decade of industry expertise, Advanced Ads is your surefooted ally in the ad tech realm. Their array of WordPress ad manager plugins enhances your advertising strategy, ensuring effective ad placements. Rely on their ad tech proficiency to stay ahead in the dynamic world of digital advertising. Contact info

Advanced Ads icon

Make it better

Increase your ad management skills without spending more time.
Join over 150,000 publishers and AdOpts increasing their ad revenue.