How do I use dimension filters in Google Analytics API to omit records?

Viewed 769

I'm using the Analytics reporting API to retrieve search terms, keywords, etc. I'd like to filter out instances where the search term is '(not set)' and have included what I thought were the appropriate dimension filters. However, the results that come back include records with the '(not set)' value in the search term field. I'm not sure what I'm missing and would appreciate any help. Thanks.

req =   {"reportRequests": [
            {"viewId": ACCOUNT,
            "dateRanges": [{"startDate": first, "endDate": last}],
            "metrics": [
                {"expression": "ga:impressions"},
                {"expression": "ga:adClicks"},
                {"expression": "ga:adCost"},
                {"expression": "ga:goalCompletionsAll"},
                {"expression": "ga:goalValueAll"},
                {"expression": "ga:transactions"},
                {"expression": "ga:transactionRevenue"},
                {"expression": "ga:sessions"}],
            "dimensions": [
                {"name": "ga:adMatchedQuery"},
                {"name": "ga:keyword"},
                {"name": "ga:adKeywordMatchType"},
                {"name": "ga:campaign"},
                {"name": "ga:adGroup"},
                {"name": "ga:date"},
                {"name": "ga:adwordsCampaignID"}],
            "dimensionFilterClauses": [
                {"operator": "OR",
                 "filters": [
                    {"dimensionName": "ga:adMatchedQuery",
                     "not": True,
                     "operator": "EXACT",
                     "expressions": ["(not set)"]},
                    {"dimensionName": "ga:keyword",
                     "not": True,
                     "operator": "IN_LIST",
                     "expressions": ["(not provided)", "(not set)"]}]}],
            "includeEmptyRows": "False",
            "pageSize": 100,
            "pageToken": nextpage,
            "hideTotals": True,
            "hideValueRanges": True}]}
1 Answers

Value of operator should be AND instead of OR.

When you use OR, if ga:adMatchedQuery has a (not set) value and ga:keyword has let's say abc, the second condition will make the entire condition true and you will be able to see the rows where ga:adMatchedQuery has (not set) value.

Hence, it should be like this: adMatchedQuery != '(not set)' and keyword not in ["(not provided)", "(not set)"]

Related