When user log, we loose his history

With the tracking js, if a new user starts to navigate we keep tracking of him with visitor-i’d. But if this user is creating an account, so we set userId and so he has now a new visitor-id.
How I can do a link between what he was doing before to create the account and now ? which variable ?
thanks for your help