Search code examples
c#google-analyticsgoogle-analytics-api

Filtering on multiple Hostnames in Google's Core Analytics APIv3


As the title states I am trying to filter my GA data using multiple Hostnames within a C# application using Google's Client Libraries.

I have no issues filtering on the main Hostname, however certain events are triggered while the user is not on our site technically, not that most users realize.

Getting this data is possible if I don't filter by Hostname, however this presents its own caveats of having a great deal of noisy data, hence my original desire to filter using the Hostname.

Currently I am filtering on the hostname using the stock standard request:

serviceRequest.Filters = "ga:hostname==www.foo.com";

This works fine for a single Hostname.

How can I filter on multiple Hostnames?


Solution

  • Filters can be combined using OR and AND boolean logic.

    The OR operator is defined using a comma (,). It takes precedence over the AND operator and may NOT be used to combine dimensions and metrics in the same expression.

    Country is either (United States OR Canada):

    ga:country==United%20States,ga:country==Canada 
    

    The AND operator is defined using a semi-colon (;). It is preceded by the OR operator and CAN be used to combine dimensions and metrics in the same expression.

    Country is United States AND the browser is Firefox:

    ga:country==United%20States;ga:browser==Firefox 
    

    I would like to recommend that you use the Query Explorer for testing out your filters, on occation you can get some interesting results. Depending upon your application it may be easer to test it in the GUI Query Exploer