Unfortunately, the documentation is currently incorrect. You can set the user ID outside the create method.
The reason your example does not work is because you call create twice. What you want to do is call set . Here's how:
// Create the tracker instance. ga('create', 'UA-XXXX-Y', 'auto'); // Once you know the user ID, set it on the current tracker. ga('set', { userId: USER_ID });
Now all subsequent hits sent to GA will be associated with this user ID.
UPDATE:
The user ID documentation now reflects that it can be set outside of the create method.
source share