This issue is similar to this issue highlighted on github, and still seems to persist: https://github.com/matomo-org/matomo/issues/3776
This issue appears to still persist / exist again. What I did:
- Added the Javascript general tracking snippet to the HTML page; to track page views out of the box.
- When a visitor submits a certain contact form, I use the server-side to:
- identify the client via the submitted e-mail address (set the e-mail address equal to the user ID, using
$tracker->setUserId(submitted_email)
in PHP. - To be able to enforce the visitor ID according to an attempted retrieval of it from the request received from the client via
$tracker->getVisitorId()
, I callsetTokenAuth('apiKey')
, thengetVisitorId()
, thensetVisitorId()
with what has been retrieved viagetVisitorId()
. - This seems to properly work, as I’ve tested it:
getVisitorId()
successfully returns the value of the tracking cookie I get from the client that fired the request. Then Ivar_dump
the url thatgetRequest()
internally generates withindoTrackEvent()
, and the generated URL properly holds thecid
parameter equal to the tracking cookie of the client.
- Result, and that’s the problem: in the visitors log dashboard, I see a first log of the page view of a visitor of a random visitor ID, let’s call that one ‘visitor ID X’. After that, an event is tracked (of the contact form submission), with a visitor ID which is however different from the one of the page view, let’s call that ‘visitor ID Y’, although the submitted doTrackEvent() call submitted the ‘visitor ID X’ in the submitted request, as mentioned above. Hence the page view and the subsequent contact form submission are not recognized as actions of the same user, due to the visitor ID not being enforced using the PHP Packages’
setVisitorId()
method.
The same happens when you do what’s mentioned above over and over, so I seemingly cannot enforce the visitorId using the PHP Package’s setVisitorId()
method, even though I authenticate properly and the getRequest()
method, internally called in the doTrackEvent()
method generates the proper URL with the correct cid parameter value (visitor ID X).
Of course it is essential for a proper use of the user ID that the system allows to enforce the visitor ID via request from the server to the API, with the received visitor ID from the client-side cookie, such that the entire history of page views / whatever can be reconstructed.
Update: It actually seems that the problem is the simultaneous use of both setUserId()
and setVisitorId()
before the doTrackEvent()
call. This seems to lead to the consequence that only the user ID is considered, and the visitor ID submitted via cid
is simply ignored. But when I omit a call to setUserId()
and only do setVisitorId()
and then doTrackEvent()
, the event gets properly stored and shows up in the according Dashboard under the correct visitor ID (the one grabbed from the cookie received from the client-side), but of course without the user ID in that case. This leads to the problem that either way, it is not possible to relate events related to a specific visitor ID to a specific user ID ?!