Search code examples
google-analyticsgoogle-analytics-apigoogle-analytics-filters

GA realtime api with custom dimensions


I want to query the google analytics realtime api using one of my custom dimensions.

In the regular api (not realtime) I can do this as follows:

'metrics': 'ga:pageviews',
'filters': 'ga:pagePath=~/myPath*;ga:dimension2=='+myVal

However, when I change the metrics to 'rt:activeUsers', I got the error:

"Unknown dimension(s): ga:dimension2"

when I did the request.

I changed the separator in the filters string from semi-colon to & and I didn't get the error any more, but the result always returns 0

Is it possible to do filtering on the realtime api? TIA


Solution

  • The realtime API does not support custom dimensions (you can see the list of supported dimensions and metrics here). On possible reason is that at least the values for session- and user-scope dimensions cannot be determined in realtime since realtime reports based on hits. So you cannot filter based on a custom dimension.

    There is a possible workaround, but that comes with a caveat that makes it mostly pointless. You can create an additional data view, and then use an advanced filter to copy the custom dimension value for the hit to a dimension supported by the realtime API - e.g. you extract the value from your custom dimension and copy it to the "source" field (or some other field). Then you query for/ filte by the source field to retrieve the value. The caveat is that the original value of the source data field (or whatever field you overwrote) will be lost.