Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't sniff default country code using fallbacks when ad block is installed #472

Open
johnnyshankman opened this issue Jun 21, 2024 · 0 comments

Comments

@johnnyshankman
Copy link

Ad block will automatically block all calls to common websites that return your IP address information.

There should be a fallback that uses globals in the browser to sniff it out. I do something like this:

  const locale = navigator.language

  // Step 2: Check if the locale includes the region (country)
  if (locale.includes('-')) {
    const iso2CountryCode = locale.split('-')[1].toUpperCase();
    return iso2CountryCode;
  }

  // Step 3: Fallback to navigator.languages
  if (navigator.languages && navigator.languages.length > 0) {
    for (const lang of navigator.languages) {
      if (lang.includes('-')) {
        const iso2CountryCode = lang.split('-')[1].toUpperCase();
        return iso2CountryCode;
      }
    }
  }

Also there's no way to pass a default value for when the IP api call fails which is frustrating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant