google-analyticsanalyticsreportinguniversal-analyticscustom-dimensions

Combining/Linking custom events in Google Analytics 4


I am using GA-4 to track user activity on my nextJs website. I have a few custom dimensions and custom metrics to satisfy my requirements. For example, I am firing the event, userDetailsEvent with user details when the user logs in.

window.dataLayer.push({
 event: userDetailsEvent,
 userName: "ABC",
 role: "admin"
})

userName and role both are sent to GA via Google Tag manager as parameters. GA accepts them as a custom dimension.

Later, when the user clicks the download report button (on the home page), I create one more event, downloadReportEvent with details related to the file downloaded.

window.dataLayer.push({
 event: downloadReportEvent,
 reportType: "XYZ",
})

reportType is sent to GA via GTM as a parameter along with a additional parameter downloadCount. GA accepts reportType as custom dimension and downloadCount as custom metric.

The problem is in the GA report values sent by 2 events are disconnected. I am not able to associate user name to download count or report type. I see all the values in the report but in separate rows. Username and role have "(not set)" value when reportType is XYZ. Similarly, reportType is "(not set)" when userName and role has "abc" and "admin" respectively.

How can I link these events together? Do I need to send common Id or something?

Thanks in advance.


Solution

  • I found a solution to this question. We need to use user scope dimensions and parameters to connect all events. This can be achieved by sending user properties (as parameters) from GTM to GA and receiving it as user-scoped custom dimensions in GA4.

    For ex: If user_name and user_id are sent as user properties from GTM and GA accepts it as user scoped custom dimension then all the further events will have these two values tied to them.