Commit bc91786d authored by isstuev's avatar isstuev

adblock detect improvement

parent 3fd7f42b
import { useEffect } from 'react'; import { useEffect } from 'react';
import type { AdBannerProviders } from 'types/client/adProviders';
import config from 'configs/app';
import { useAppContext } from 'lib/contexts/app'; import { useAppContext } from 'lib/contexts/app';
import * as cookies from 'lib/cookies'; import * as cookies from 'lib/cookies';
import isBrowser from 'lib/isBrowser'; import isBrowser from 'lib/isBrowser';
const DEFAULT_URL = 'https://request-global.czilladx.com';
// in general, detect should work with any ad-provider url (that is alive)
// but we see some false-positive results in certain browsers
const TEST_URLS: Record<AdBannerProviders, string> = {
slise: 'https://v1.slise.xyz/serve',
coinzilla: 'https://request-global.czilladx.com',
adbutler: 'https://servedbyadbutler.com/app.js',
hype: 'https://api.hypelab.com/v1/scripts/hp-sdk.js',
// I don't have an url for getit to test
getit: DEFAULT_URL,
none: DEFAULT_URL,
};
const feature = config.features.adsBanner;
export default function useAdblockDetect() { export default function useAdblockDetect() {
const hasAdblockCookie = cookies.get(cookies.NAMES.ADBLOCK_DETECTED, useAppContext().cookies); const hasAdblockCookie = cookies.get(cookies.NAMES.ADBLOCK_DETECTED, useAppContext().cookies);
const provider = feature.isEnabled && feature.provider;
useEffect(() => { useEffect(() => {
if (isBrowser() && !hasAdblockCookie) { if (isBrowser() && !hasAdblockCookie && provider) {
const url = 'https://request-global.czilladx.com'; const url = TEST_URLS[provider] || DEFAULT_URL;
fetch(url, { fetch(url, {
method: 'HEAD', method: 'HEAD',
mode: 'no-cors', mode: 'no-cors',
......
...@@ -13,12 +13,16 @@ export function ad(): CspDev.DirectiveDescriptor { ...@@ -13,12 +13,16 @@ export function ad(): CspDev.DirectiveDescriptor {
'*.coinzilla.com', '*.coinzilla.com',
'https://request-global.czilladx.com', 'https://request-global.czilladx.com',
// adbutler
'servedbyadbutler.com',
// slise // slise
'*.slise.xyz', '*.slise.xyz',
// hype // hype
'api.hypelab.com', 'api.hypelab.com',
'*.ixncdn.com', '*.ixncdn.com',
'*.cloudfront.net',
//getit //getit
'v1.getittech.io', 'v1.getittech.io',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment