Search code examples
google-analyticsgoogle-analytics-api

Google Analytics API: how to get non-US visitors


I have been using visitors with ga:country filters to get specific country's visitors. For example to get the number of visitors from US, I used the filter of 'ga:country==United%20States'. But I am wondering if I can do something like 'ga:country!=United%20States'? I guess I can subtract ga:country==United%20States from total visitors but I am wondering.


Solution

  • The easet way of doing this is to create a filter ga:country. A filter will let you remove a subset of the data returned by a query. Think of it like a where clause in SQL.

    Filter=ga:country!%3DUnited%20States
    

    That translates to

    Filter=ga:country != United States
    

    I made a simple report on my personal dashboard the Google Analtyics to test it.

    enter image description here


    Added info on filtering: You can add more then one filter by seprateing

    OR operator is defined using a comma (,).
    AND operator is defined using a semi-colon (;).
    

    You can mix and match Metric and Dimensions in the same filter.