I am trying to collect user ID’s for google analytics tracking, but am confused on discrepancy between articles I found.
This article (https://www.analyticsmania.com/post/google-analytics-4-user-id/) is saying to use this approach:
<code>window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'login',
'userId' : '1234567' //this number must be replaced with an actual User ID
})
</code>
<code>window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'login',
'userId' : '1234567' //this number must be replaced with an actual User ID
})
</code>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'login',
'userId' : '1234567' //this number must be replaced with an actual User ID
})
While the official docs are saying to do this:
<code>gtag('config', 'TAG_ID', {
'user_id': 'USER_ID'
});
</code>
<code>gtag('config', 'TAG_ID', {
'user_id': 'USER_ID'
});
</code>
gtag('config', 'TAG_ID', {
'user_id': 'USER_ID'
});
What is the correct approach to implementing this?