Provide UserID via Tag Manager - what to push after Logout and any further pageviews?

Hello everybody,

When a user is logged in, I want to push the user ID into the data layer before the actual Pageview Tag is triggered.
The settingsvariable will use a data layer variable for existing UserIDs.

My question is what do I have to do to prevent the storage of the UserID on / after logout?

Is it enough to specify a data layer variable with the value of undefined? (not a string)
Because if the UserID value is not available for any other pageview, it should not be taken into account for Matomo.
But I am worried if Matomo safely excludes all actions for this logged out user.

Would it be enough to just fire on the same site, before the next pageview.

_paq.push(['resetUserId']);

The page will reload and the dataLayer value is again undefined.