Using gtag.js I can change the user id in this way:
gtag('config', 'G-XXXXXX', {
'user_id': '12345'
});
Using GTM instead, how can I change the user id used by Google Analytics?
What I currently did was to add a variable in GTM, and insert it as the value of the user property "user_id" in the TAG of analytics.
The problem is that in this way Analytics is initialized with the initial user_id value. In my case though, using it on a single page application, the user id can change after having already initialized GTM and so Analytics, and dataLayer.push({ 'user_id': 'xxx' }) has no effect on Analytics.