Adblock

Hello,

I tried simple methods to know, if user uses adblock or not ( it is second one - https://ctrlq.org/code/19818-detect-adblock-javascript )
But I have a problem to insert simple ads.js file to src tag in .
I tried ‘public/ads.js’, but still console said that it was not possible to load the js file.

Could you help me to solve this problem?

Hi Ady,

It is not possible to set a variable before importing it from a backend file, therefore this method will not work.

and is way to implement some similiar method to get know if someone use adblock and then I can change layout?

Hi Ady,

I found a way to detect if an adblock is enabled or not. Simply try fetching an ads javascript file.
Note that this code must be executed in frontend code

Add a text element and set its text to “Adblock in ON”
Then add the following code:

import {fetch} from 'wix-fetch';

$w.onReady(function () {
	fetch('https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', {
		mode: 'no-cors'
	}).then(() => {
		$w('#text1').text = "Adblock OFF";
	});
});

The code you provided does not work :frowning:

Works fine, thanks! (y)