How to determine client's country using Google Analytics?

纵饮孤独 提交于 2021-01-05 10:47:39

问题


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.


回答1:


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",



回答2:


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.



来源:https://stackoverflow.com/questions/11055065/how-to-determine-clients-country-using-google-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!