Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent AdSense Auto Ad from showing ad in specific area

I have a problem in a project where an AdSense Auto Ad code has been pasted, one of the ads automatically placed have ruined the web page layout and design. Is there a method to prevent a specific ad to be shown inside a certain element or a container. Here is a sample of what the ad has done:

Code before AdSense Auto Ad was implimented:

 <div class="row">
  <div class="col-md-4">
   somecontent
  </div>
  <div class="col-md-4">
   somecontent
  </div>
  <div class="col-md-4">
   somecontent
  </div>

Code after AdSense Auto Ad was implimented:

 <div class="row">
  <div class="col-md-4">
   somecontent
  </div>
  <div class="google-auto-placed">
    ad content
  </div>
  <div class="col-md-4">
   somecontent
  </div>
  <div class="col-md-4">
   somecontent
  </div>
like image 883
Surya Neupane Avatar asked Jul 05 '18 05:07

Surya Neupane


2 Answers

You could try to make a JavaScript file that executes after (important word) the Google AdSense script. Something like:

var ad = document.querySelector(".google-auto-placed"); //Can be replaced any identifying trait depending on the actual Ad Div
ad.innerHTML="";
<html>

<body>

  <div class="row">
    <div class="col-md-4">
      somecontent
    </div>
    <div class="google-auto-placed">
      ad content
    </div>
    <div class="col-md-4">
      somecontent
    </div>
    <div class="col-md-4">
      somecontent
    </div>

</body>

</html>

This removes the ad (if it is executed after the Google AdSense script). However, this may set of AdBlocker detectors.

Essentially what this does is it selects the google-auto-placed class using document.querySelector(); which will select a specific element depending on the prefix, . for class in this case. Sadly, this may not work with some older IE versions. If you have multiple elements you may want to check the parentElement to check if it is the correct ad. You can read about that here.

To read up more about document.querySelector() have a look here.

like image 180
DecstarG Avatar answered Oct 11 '22 10:10

DecstarG


I just found an easier way to do this.

You should go :

  • Sign in to your AdSense account.
  • Click Ads.
  • On the "Auto ads" page, under "Global settings", click edit Edit button.

Here you can see how would google generate the auto ads in specific page. you can also hit a remove button on the ad it self.

like image 23
jony89 Avatar answered Oct 11 '22 08:10

jony89