Laurent
Laurent

Reputation: 1563

Apps script / Google Analytics API : combining multiple filters

I'm using Apps Script to query Google Analytics and drop the results in Google Sheets. My script works fine if I use only one filter but once I use multiple filters in the same query, the figures do not match what I see in Google Analytics anymore.

I have tried my query in the query explorer (https://ga-dev-tools.web.app/query-explorer/) and I get the right result.

One of the filters I'm trying to use is the following one: ga:eventCategory==Ecommerce,ga:eventAction==addToCart

In my script I have this:

var metric = 'ga:uniquePageviews';   
var options = {
                    'metrics' : 'ga:uniqueEvents',
                    'dimensions': 'ga:date',
                    'filters' : 'ga:eventCategory==Ecommerce;ga:eventAction==addToCart',
                    'samplinglevel': 'HIGHER_PRECISION'
                 }; 
   var report = Analytics.Data.Ga.get(tableId, past, today, metric, options);

It looks like the filter doesn't understand the ; as a AND condition. I have tried to encode it like for URLs but then I get an error message saying that the filter is not understood.

Should I transform the filter parameter differently?

Thanks Laurent

Upvotes: 0

Views: 415

Answers (1)

AUndang
AUndang

Reputation: 1

I was able to solve this using the below snippet.

"dimensionFilterClauses": [
    {
        "filters": [
            {
            "dimensionName": "ga:eventAction",
            "operator": "IN_LIST",
            "expressions": ['value1','value2'] 
            }
        ]
    }
] 

Upvotes: 0

Related Questions