• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

globals.visitor.country not returning data with some ISP

Engaged ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

I have a problem where a client wanted to stop users outside New Zealand and Australia registering on the site. So I implemented a solution using globals.visitor.country. It worked pretty good keeping most outside NZ and AU out. But there are a few ISP's at least in NZ that don't return a result and then my solution does not work, locking out NZ users. I can sort of fix this by including "" and then it helps. But is not Ideal as anyone blocking the location will be let through by default.

I have tested this with the client and when they use Spark it works and with primo wireless it returns blank same computer and browser. I used whois and the likes on the ISP that returns blank and it gives me the location fine. I have also see this issue with Vodafone where it returns a blank result.

Has anyone else seen this? Is there a work around? or is visitor.country just not robust enough to be any good? Are there other options?

TOPICS
Developer

Views

980

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 31, 2017 Jan 31, 2017

This is tough one.

I would suggest that because globals.visitor.country is out of our control and relies on BC to uphold integrity of data returned that you should focus your efforts on the controllable; such as usability and workflows etc.

Possible options include:

  • Place a country of origin drop-down which only has NZ, AU and International as options. When 'International' is selected you can have a message popup saying something like: "This service is only available for NZ and AU customers".
  • Place
...

Votes

Translate

Translate
Enthusiast ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

This is tough one.

I would suggest that because globals.visitor.country is out of our control and relies on BC to uphold integrity of data returned that you should focus your efforts on the controllable; such as usability and workflows etc.

Possible options include:

  • Place a country of origin drop-down which only has NZ, AU and International as options. When 'International' is selected you can have a message popup saying something like: "This service is only available for NZ and AU customers".
  • Place a qualifying messages permanently on the form, "This service is only available for NZ and AU customers".
  • Only show qualifying message and / or country drop-down when globals.visitor.country is blank - meaning, when it returns a value, you know it's correct. When the value is blank, display qualifying messages / drop down.

IMO this is the best of bad situation. If in doubt, control the controllable.

Hope this helps mate

- Stephen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Thanks Stephen this will help.

Great suggestion about dropdown only if country code is blank. This will stop a few more outside registrations without bothering most users.

@BC can you look into the reliability of globals.visitor.country please.

- Daniel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

You would have to re-write a bit and it might not be suitable but there are a few javascript libs that do this client side. The beauty of this is that if there is a range of IP's you can add an exception yourself in the code:

Free (as far as I can tell)

GitHub - benlowry/node-geoip-native: A native, fast, JavaScript geoip lookup for NodeJS.

Paid service:

http://dev.maxmind.com/geoip/geoip2/javascript/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

That belowry/node-geoip-native isn't for client-side, the csv it uses is 5.7mb.

There's also the ability to just ask the user's device where it is.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

I think GeoLocation requires a secure HTTPS url and also it pushes a prompt to the screen asking for permission to see your location.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Mozilla Developer doc does not seem to specifically say it only works with https but all the examples are https even though the link displays as http on 2 of the examples. I will have to look further into this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Robert's correct it uses a CSV it seems and passing 5MBs per user wouldn't be the best UX. If module_data worked with web apps you could have loaded the CSV into the webapp and pulled the data out using a where clause.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Geolocation API Removed from Unsecured Origins in Chrome 50

And, more generally: Deprecating Powerful Features on Insecure Origins

Mozilla, Microsoft, Opera, and Webkit/Safari may have similar intent.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

Robert: That's the HTML5 geo look up built into the browser not external lookups.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

GEOIP2 looks like it might work with the free light database.

Using geolocation works but asks for user interaction, a bit of a pain. Though this could be done only if the country in missing in liquid. so reduces its use.

It would be better if globals.visitor.country was more reliable.

Thanks for the suggestions.

- Daniel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2017 Jan 31, 2017

Copy link to clipboard

Copied

What is actually going on is two fold:

1. ISP Data Centre the information for this sometimes is not in the same area or routing is such that it reads incorrectly.

2. The service database BC uses for this information for some ISP's to get the city is incorrect and needs to be updated. In some cases such database services have to make manual adjustments for when 1. happens, and/or just keeping things up to date.

Spoke and covered this with BC ages ago...

- They will not do any changes their end.

- There is to much investment and work for them to change source.

- The service they use are not really forthcoming in actually doing updates and changes.

It is just as it is.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 19, 2017 Mar 19, 2017

Copy link to clipboard

Copied

Thanks to everyone who replied to this previously. I have a new issue with country codes. I cannot work out if I have got something terribly wrong or if there is a bug.

The below liquid. I though says if a visitor is from NZ, AU or blank (not seen) then do everything before the {% else -%} but it is letting user outside these countries through. It was seemingly working. But in the last few weeks maybe more the client has been getting registrations from outside these areas. They just got one from Netherland. One thing I did to test this was to put a hidden field in the form to pick up the {{globals.visitor.country}}. From New Zealand I get the data NZ but the Netherlands data returned is 'Netherland'. And if the data returned is 'Netherland' (which is odd in itself not being a country code like NZ) it is not in the if or and so should be else. which has no form in it. Am I missing something or is there a bug!

{% if globals.visitor.country == 'NZ' or globals.visitor.country == 'AU' or globals.visitor.country == ''-%}

        <div class="create-employee">

            ...

            <div class="signupform">

      {% if globals.visitor.country != '' -%}{module_webform,42275}{%else-%}{% include '/_System/Includes/library/employee register.inc' -%}{% endif -%}

               ...

            </div>

        </div>

{% else -%}

        ...

{% endif -%}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 19, 2017 Mar 19, 2017

Copy link to clipboard

Copied

The logic looks sound.

You're going to have to go through this with a fine tooth comb on a test page and see where it breaks down. Use a proxy server browser add-on to test.

Not sure this means anything, but place a space between ''-%} on the first line, like this: '' -%}.

If nothing works, try your logic from another angle - backwards.

IF visitor.country == ""

     --- handle visitors returning no country code.

ELSE

     IF visitor.country == NZ or visitor.country == AU

          -- handle your target audience
     ELSE

          -- handle the restricted customers.

     END

END

Good luck Daniel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 19, 2017 Mar 19, 2017

Copy link to clipboard

Copied

Thanks Stephen

The space before the -%} did not fix the issue though these was an instance when it did cause and issue. I have seen it and Liam posted about it but thought it was fixed. Can find the post at the moment.

I chatted support and got this reply

If there are multiple conditions with in an if you have to use elsif and then use the else in the end:

https://docs.worldse…/liquid/logic-tags.html#IFelse

So I am trying that now. First I have tried breaking out the empty country code like this. And like you suggested. Also like I should have done in the first place.

{% if globals.visitor.country == 'NZ' or globals.visitor.country == 'AU' -%}

            ...

          {module_webform,42275}

{% elseif globals.visitor.country == '' -%}

     {% include '/_System/Includes/library/employee register.inc' -%}

{% else -%}

          ...

        {% endif -%}

Next if it does not work I will break out everything. Though that would balloon the code or force me to use capture.

I have seen and use or and embed if logic heaps and never had an issue that I know of.  All seems very odd.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2017 Mar 19, 2017

Copy link to clipboard

Copied

Not sure what support was on about

{% if globals.visitor.country == 'NZ' or globals.visitor.country == 'AU' -%}

            ...

          {module_webform,42275}

{% else  -%}

     {% include '/_System/Includes/library/employee register.inc' -%}

{% else -%}

IF it is NZ or AU and anything else do something.

IF you have condition where it is blank you can do something like

IF BLANK

     DO THIS

ELSE

     IF NZ OR AU DO THIS

     ELSE DO THIS

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2017 Mar 19, 2017

Copy link to clipboard

Copied

Woops, it posted before finishing.
If that is all the condition you have where globals is either NZ or AU and for anything else do something else then just remove the bit after the else

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 20, 2017 Mar 20, 2017

Copy link to clipboard

Copied

Hi Liam

There are 4 options as below NZ and AU are exactly the same. If the country is blank the form is alter slightly and if the country is out of these they see no form at all. But it does not work. To test I have supports suggestion I have tried below. Still does not work.

{% if globals.visitor.country == 'NZ' -%}

        ...

                {module_webform,42275}

                ...

    {% elseif globals.visitor.country == 'AU' -%}

        ...

                {module_webform,42275}

                ...

    {% elseif globals.visitor.country == '' -%}

        ...

                {% include '/_System/Includes/library/employee register.inc' -%}

                ...

        {% else -%}

        <h4>...</h4>...

    {% endif -%}

A user from Great Britain Should not see a webform but they do. There globals.visitor.country = ‘Great Britain’

In New Zealand I get the globals.visitor.country = ‘NZ’

All those I have see come through have globals.visitor.country = there full country Name ie.‘Great Britain’ The docs show a country code for this data. This data should be consistent. Should it not?

And I cannot see how this is not working. As globals.visitor.country is returning a value and the logic seems correct.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 20, 2017 Mar 20, 2017

Copy link to clipboard

Copied

Have you tried the code I provided or/and the sudo code for what to do in the other use case?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 20, 2017 Mar 20, 2017

Copy link to clipboard

Copied

LATEST

Hi Liam

Yes your code is working. But it seems so might the original code. I tried a proxy as Stephen suggested and it does not let me through. It works like it should. So the code is seemingly working. The data being returned is a country code when I use a proxy like it should be. All the users getting through have globals.visitor.country = there country name. I tried this {% if globals.visitor.country == 'New Zealand' and I cannot get in. So how does the same globals.visitor.country return a different type of data for these users. 

To minimise users submitting the for I implemented JS to only let users through that selected New Zealand in the registration form by disabling the submit button. But they all seem to be getting around this to. It has not reduced the numbers which seems odd that they all get around this. Not hard to bypass but most people could not.

There is something odd going on. How is this happening, why and is it malicious in some way. I have a lot of questions. Not many answer yet.

Thanks for you help. I will let everyone know what I find out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines