質問

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