Minalcar
(Minalcar)
October 11, 2017, 12:18pm
1
Hi,
I want to be able to associate actions of a user to a visitor profile before the user creates and account and logs in. As of right now visitors get a visitorID and their actions are recorded, but as soon as they create an account a new (from the hashed userID) visitorID is created and all previous actions are lost. How do I preserve the information before the login?
Minalcar
(Minalcar)
October 11, 2017, 2:03pm
2
mabeabe
(Marion)
November 20, 2017, 3:31pm
3
bump. anyone have a solution to this in Piwik?
peterbo
(Peterbo)
November 23, 2017, 8:49am
4
there is no solution yet, please have a look at:
opened 09:56PM - 16 Apr 15 UTC
closed 08:24PM - 12 Dec 19 UTC
Task
This is especially a problem for Log Importer and QueuedTracking, but can happen… with normal tracking as well. It's hard to explain but I will try :)
It's a problem when a user logs in and turns from a visitor into a user or when a user logs out and becomes a visitor again. It is a problem when the requests are not inserted in the exactly same order as they were sent.
Imagine the following tracking requests:
```
1: http://apache.piwik/piwik.php?action_name=foo&_id=visitorId&idsite=1 // visitor
2: http://apache.piwik/piwik.php?action_name=bar&_id=visitorId&idsite=1 // visitor pageview
3: http://apache.piwik/piwik.php?action_name=foo&_id=visitorId&idsite=1&uid=5 // logs in
```
We will create a new visit for tracking request `1`. So far so good. If then for some reason `3` is processed before `2`, a second visit will be created. Why? When a userId is detected, we use the `uid` as visitorId and we do overwrite the `idvisitor` of all past visits (in this case of request `1`). Meaning when the second tracking requests is executed, it won't find an existing `idvisitor` as the `uid` does not exist there and it will create a new visit.
When is this a problem? As mentioned this is especially a problem when using log importer or queuedTracking with multiple workers / recorders. Both split requests into a different queues to process them in parallel see: https://github.com/piwik/piwik-log-analytics/blob/master/import_logs.py#L1642-L1651 and https://github.com/piwik/plugin-QueuedTracking/blob/multi_test/Queue/Manager.php#L161-L177 . This means once a `uid` is set, a request might go into a different queue than the one without `uid` and they can be likely processed in different order.
Same problem can occur if someone has for example multiple PHP nodes with load balancing etc. but it is less likely and it would be - realistically - only one request affected and all following would be fine. Still it can create one additional visit.
As an alternative, you could use a visit scope CustomDimension to store the UserID.