Search code examples
google-analyticsgoogle-analytics-api

Google analytics user explorer get user report


How do I get user report from user explorer, using GA API. Didn't manage to find any information about it here https://developers.google.com/analytics/. For instance in user explorer (audiences section) you can see a list of records having ids like 11111111111.2222222222 and I want to get information about user activity on the website for record with id 11111111111.2222222222 using GA API


Solution

  • While the latest GA release notes says the client ids have been "surfaced" (i.e. made visible) it is (at least currently) not available as a dimension via the API. So if you want to use it you'd have to add the client id as a custom dimension to your reports yourself. Off the top of my hat this should look something like this:

    ga(function() {
      var trackers = ga.getAll();
      trackers.forEach(function(tracker) {
        tracker.set('dimension1',tracker.get('clientId'));
      });
    });
    

    Put before the pageview this would write the client id to your custom dimension with the index 1 (which you need to create in advance via the interface in properties->custom definitions). Should also work with multiple trackers on the same page.

    This will of course not help you with data that's already been collected.