2

我的页面使用 GA 为自己提供统计数据。稍后我可以看到访问我网站最多的国家/地区。

有什么方法可以在客户端获取客户所在的国家/地区?如果她不是来自我的国家,我想向用户显示通知。

4

2 回答 2

3

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",
于 2012-06-15T17:11:31.563 回答
2

您需要使用基于 IP 的地理定位服务 - 一个很好的免费服务是IPInfoDB ,我用它来检测访客是否来自我所在的省份,如果是,则弹出一条消息。效果很好。

于 2012-06-15T17:02:38.913 回答