Reputation: 6613
Besides standard view 'All data' I've created a separate view to track users by USER_ID from my database, following official documentation (https://support.google.com/analytics/answer/3123662?hl=en).
If I watch User report
from 'All data' view, I can see both pageviews and events of users, but user ids aren't interpretable.
If I watch 'User report' from newly created USER_ID view, I can see events, but not page views! (I double checked that in filter above pageviews IS checked). How can I see both events AND pageviews?
My tacking code is
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=ID_OF_MY_RESOURCE"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<ID_OF_MY_RESOURCE>');
gtag('set', {'user_id': 'MY_USER_ID'});
</script>
and I send events with gtag('event', 'event name', {'event_category' : 'some category', 'event_label' : 'some label'});
inside my web pages.
Upvotes: 0
Views: 638
Reputation: 1712
In fact the config
command sends the page view along with the base configuration. If you set the user_id value AFTER the config
command, the page view hit doesn't know about it, but subsequent hits will use it.
And UserID views only collect hits that hold a value for the user_id
parameter. This is why you don't get page views in it.
Then you just need to change line orders:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('set', {'user_id': 'MY_USER_ID'});
gtag('js', new Date());
gtag('config', '<ID_OF_MY_RESOURCE>');
</script>
There is no persistent tracker in gtag.js, just persistent settings that must be declared before sending a hit.
Upvotes: 1