Search code examples
google-analyticsgoogle-analytics-api

Google Universal Analytics API using the new Custom Metric / Definition as a filter


I am using the new UA custom definitions and custom metrics e.g.

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-XXXXX-X', 'auto');
    ga('set', 'metric1', <?= $contest_data->ID; ?>);
    ga('set', 'dimension1',  'c');
    ga('send', 'pageview');

And I have now seen the custom metric and definition show up in my GA dashboard for filtering but I am not able to get any results back using the query explorer. I would not worry if my results were 0 because I know it takes time to populate but I am getting an error code:

400 : Invalid value 'ga:metric1=123' for filters parameter. Does anyone have any experience with using custom metrics and definitions as filters?

Thanks in advance.


Solution

  • Try ga:metric1==123 (note the two equals signs).

    Here's the filter operator documentation:
    https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filterOperators