How to Block Networks in Google AdSense via code

 Ads are an essential part of the online experience, but they can also be a nuisance. Google AdSense is a popular platform for displaying ads on websites, but sometimes the ads that are displayed may not be relevant or appropriate. In this post, we will discuss how to block specific networks from displaying ads on your website from the Google AdSense settings.


Why Block Ads from Specific Networks?

There are several reasons why you may want to block ads from specific networks on your website. Some common reasons include:

  1. Irrelevant ads: Sometimes the ads that are displayed on your website may not be relevant to your audience. Blocking ads from specific networks can help ensure that the ads displayed on your website are relevant and appropriate.

  2. Low-quality ads: Some networks may display low-quality or disruptive ads that can negatively impact the user experience on your website. Blocking these networks can help improve the overall user experience on your website.

  3. Brand safety: Some networks may display ads that are not appropriate for your brand or your audience. Blocking these networks can help ensure that your brand is not associated with these ads.

How to Block Networks in Google AdSense

Blocking networks in Google AdSense is a simple process that can be done from the settings of your AdSense account. Here are the steps to block specific networks from displaying ads on your website:

  1. Log into your AdSense account and click on the "Blocked sites" tab on the left sidebar.

  2. In the "Blocked sites" tab, you will see a list of all the sites that you have blocked. To block a new site, click on the "Add site" button.

  3. In the "Add site" field, enter the domain of the network you want to block. For example, if you want to block the network "network1.com", you would enter "network1.com" in the field.

  4. Click on the "Save" button to block the network.

  5. Repeat the process for any additional networks that you want to block.

It's important to note that once you've blocked a network, ads from that network will no longer be displayed on your website. However, please keep in mind that blocking a network may decrease your revenue from AdSense.

Additionally, it's also important to note that this feature is only available for AdSense for content and AdSense for search. Some types of ad units may not be able to block specific networks.

How to Block All Networks in Google AdSense via JavaScript



Blocking networks in Google AdSense is a simple process that can be done with a JavaScript code snippet using the setInterval function. However, it's important to note that this is not an official solution from Google and it may not work for all websites or in all cases. Here is an example of a code snippet that can be used to block specific networks from displaying ads on your website:


var toggl;
setInterval(function(){
    toggl=document.querySelector('.all-networks-table div.material-toggle[aria-checked=false]');
    if (toggl==null){
        document.querySelector('.all-networks-table material-button.next').click()
    }else{
        toggl.click()
    }
}, 100);


Open All Networks in Google AdSense via JavaScript


var toggl;
setInterval(function(){
    toggl=document.querySelector('.all-networks-table div.material-toggle[aria-checked=true]');
    if (toggl==null){
        document.querySelector('.all-networks-table material-button.next').click()
    }else{
        toggl.click()
    }
}, 100);


Or


var toggl;
setInterval(function(){
    toggl=document.querySelector('.blocked-networks-table div.material-toggle[aria-checked=true]');
    if (toggl==null){
        document.querySelector('.blocked-networks-table material-button.next').click()
    }else{
        toggl.click()
    }
}, 100);


This code snippet uses the setInterval function to repeatedly execute the enclosed function every 100 milliseconds. Inside the function, it's selecting an element with class "all-networks-table" and a child element with class "material-toggle" that has an attribute "aria-pressed" with value "false" using document.querySelector(). It assigns that selected element to the variable "toggl".

Then, it checks if "toggl" is equal to null, if it's true it will select the element with class "It is important to note that the code provided is an example and may not work as expected on all websites or in all cases. This is because the code is trying to access elements on a webpage that may not exist or may not have the specified class names or attributes, which could cause the script to throw an error and stop execution. Therefore, it is important to use a try-catch block to handle these errors and prevent the script from stopping execution.

Additionally, using setInterval function repeatedly executing the function, which could cause performance issues and could also cause the browser to crash if executed on a webpage. A better approach would be to use a setTimeout function, which will execute the function only once after a specified interval.

It's also important to note that this code could still cause unwanted actions on a webpage, so it is important to use it responsibly and only on sites that you own or have permission to modify. Additionally, this code is not an official solution from Google and it's not guaranteed to work on all websites or in all cases.

In conclusion, blocking ads from specific networks in Google AdSense is a simple process that can be done from the settings of your AdSense account. By blocking irrelevant, low-quality or disruptive ads, you can improve the user experience on your website, protect your brand and increase the relevance and appropriateness of the ads displayed on your website. However, it's important to keep in mind that this feature is not available for all types of ad units and that blocking a network may decrease your revenue from AdSense.

using setInterval function, it is important to note that this is not an official solution provided by Google and it is not guaranteed to work on all websites or in all cases. It's important to use this code with great caution, as it can have serious consequences on the targeted website. It's also important to test the code on your website before implementing it, and to handle errors with try-catch block to prevent the script from stopping execution

المقالة التالية المقالة السابقة
لا توجد تعليقات
اضـف تعليق
comment url