The Google Analytics User ID documentation page shows that you set the User ID when you create the tracker. I have a javascript only project with sign-in after page load, is there any way to set the User ID after login? Something like ga("set", "userid", "UNIQUEID")
On the field reference page it says you can only set user-id in the create function. Are we able to call create again with the user-id? Will that create a new tracker, or override the old one?
EDIT: The beta version of User ID tracking showed that you could specify the userid after creating the tracker using ga('set', '&uid', {{ USER_ID }});
and that would try to unify the session from before the userid was set with the one after. That seems to be very different than what the docs current specify. Is there any way to do this with the current method?
You should set userId beofre sending event to Google Analytics. I couldn't manage to send userId after sending events pageview and ecommerce:send.
The documentation seems to indicate that, with analytics.js, you should do the following:
I'm not sure how this differs from the current answer (which uses
&uid
), but this solution is working for us.It appears from Justin Cutroni's blog that he's saying that data stitching (in your case matching the userid prior to login to the userid post-login) is not currently offered in Google Analytics.
http://cutroni.com/blog/2014/04/10/understanding-cross-device-measurement-and-the-user-id/
See specifically this sentence: "Google Analytics will not go back in time and stitch every single session from a given user together."
If you are using Google Tag Manager you can set the User ID by added '&uid' as a field to your Google Analytics Setting variable:
This one works