Search code examples
google-analyticsgoogle-analytics-apigtag.js

Is it possible to group users in Google Analytics by a custom parameter using gtag.js?


I'm looking to group users in GA reports by the organisation they belong to.

When a user visits my web app, they are asked to choose an organisation. An organisation can contain multiple visitors. It is also possible for users to switch their current organisation at any time.

Is it possible to send the organisation as a custom parameter in the tracking code every time a user switches organisation, so that I can view a report breaking down user statistics by the organisation they belong to?

For example, a visitor visits the site and chooses to join organisation A. Another visitor visits the site and chooses organisation B. I need to then be able to break down visitor statistics by organisation - e.g. see visitor stats for organisation A only, or organisation B only, etc.


Solution

  • You can listen an event "choose organization" and send gtag event with parameters like that:

    gtag('event', 'organization_set', {'organization_name': organizationName});
    

    where organization_set is event name, organization_name is event parameter

    However, if it's possible to change the organization, you will need to add an event listener to that too.

    After that you will need to specify it as a custom metric Analytics -> Configure -> Custom Dimensions