setUserId, visitorID and E-commerce


We use setUserId to set the id of the user when logged in.
This works fine, but we encounter a problem with measuring conversions (e-commerce).

The problem is that users do not have a user id when first visiting the website so Matomo generates a new visitorID. It links the referrer like Google and / or campaign to this initial vistorId.

However, when the visitor buys something he / she becomes a customer and gets a user id from our website. The user is then logged in and we pass the user id to Matomo using setUserId.

But here comes the issue; Matomo generates a new visitorID once we call setUserId for a the new user. And then the conversion is logged under the new user and thus the new visitorId. So in Matomo the originated referrer and/or campaign is lost. In this way we cannot measure the success of our campaigns because the converted users never have a campaign or referring website set.

I hope this sounds clear, if not feel free to ask more details, but my question is;

How can we preserve the campaign or referring website from the initial visitorID after calling setUserId?

In an ideal world, we would like to just link the new userId to the initial visitorID so that Matomo does not creates a new visitorID.

If someone could point us towards a solution for this, we would be very happy.