我的页面使用 GA 为自己提供统计数据。我稍后可以看到访问我网站最多的国家/地区。
有什么办法可以在客户端获取客户的国家/地区吗?如果用户不是来 self 的国家/地区,我想向她显示一条通知。
最佳答案
您无法使用 GA 在浏览器中访问该信息。
如果您想在浏览器中访问该信息 尝试在支持地理定位的浏览器中进行地理定位。
规范。 http://dev.w3.org/geo/api/spec-source.html
示例:
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
});
}
然后您可以使用 google ReverseGeocoding 访问完整地址在formatted_address字段中
{
"status": "OK",
"results": [ {
"types": street_address,
"formatted_address": "275-291 Bedford Ave, Brooklyn, NY 11211, USA",
关于javascript - 如何使用 Google Analytics 确定客户所在的国家/地区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11055065/