Maybe this isn't possible, but here's the situation.
I am trying to track user ID's on my sharepoint pages in google analytics, on page view. Because I have to use sharepoint's SP.js script to get the currently logged in user to retrieve their ID, I am using SP.SOD.executeOrDelayUntilScriptLoaded to run the part of my javascript that gets the user id and then pushes it to the dataLayer.
Unfortunately because of having to wait for the SP.js script to be loaded the userid value is pushed to the datalayer after the GTM container has loaded and so shows up as undefined in the PageView tag on Tag Manager.
I have thought about putting the GTM container into my script after it has obtained the user id, but I'm not sure what that means for the non-javascript part of the container:
<noscript>
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
My work around has been to fire an event when I have the userid and send an event to Google Tag Manager, but this means that the userId shows up as an event and not as part of page view.
So is it possible to set a field in the Google Analytics Page View event after the tag manager container has loaded?
The answer here is no. Once the page view is recorded, you cannot set a field for that same page view once tracking has occurred. What you are doing with events is exactly what you should be doing. The only other options you have are to delay recording the page view until your script finishes, but that means late-loading tags, hence a percentage of missed page views being recorded, or you could simply let the first page view be recorded without the user id, then set a cookie so it is recorded on all subsequent page views. An additional option, you could set the user id as a cookie on the browser for up to a year after the session starts. Then anytime that person comes back, you would conveniently already have the user id.