문제

My page uses GA to provide myself with statistics. I can later see countries that were most visiting my site.

Are there any way to get client's country at the client-side? I would like to show user a notification if she is not from my country.

도움이 되었습니까?

해결책

You don't have access to that information in the browser using GA.

If you want to access that information in the browser Try geolocation in browsers whom support it.

spec. http://dev.w3.org/geo/api/spec-source.html

demo: http://html5demos.com/geo

sample:

if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;
        });
    }

And then you can access to the complete address using google ReverseGeocoding in formatted_address filed

    {
  "status": "OK",
  "results": [ {
    "types": street_address,
    "formatted_address": "275-291 Bedford Ave, Brooklyn, NY 11211, USA",

다른 팁

you'll need to use an IP based Geolocation service - a good free one is IPInfoDB I use it to detect if a visitor is from my province, and pop up a message if they are. Works great.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top