Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserID "Signing out use-case" - actions still attributed to the same Visitor #7556

Closed
peterbo opened this issue Mar 27, 2015 · 14 comments · Fixed by #12141
Closed

UserID "Signing out use-case" - actions still attributed to the same Visitor #7556

peterbo opened this issue Mar 27, 2015 · 14 comments · Fixed by #12141
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@peterbo
Copy link
Contributor

peterbo commented Mar 27, 2015

The Signing-out use-case in the Docs states: "In the case where a visitor visits your website and is logged-in (User ID is set) then a visit will be created for this User ID. If then visitor logs out then the visitor has no User ID set any more and a new visit will be created on the page view right after logging out. (if User ID was not used then the requests would have been tracked into one visit and one unique visitor)."

This seems to be not the case. When a user logs out (User-Id will not be set at all (not even empty string) anymore after logging out), all actions are still attributed to the visitor that had the UserId set, if the action is within "visit_standard_length" (or window_look_back_for_visitor). After waiting for timeout of "visit_standard_length", a new visitor without UserId is created, which would be expected even within "visit_standard_length".

@peterbo peterbo added the Bug For errors / faults / flaws / inconsistencies etc. label Mar 27, 2015
@mattab
Copy link
Member

mattab commented Mar 29, 2015

Thanks @peterbo for reporting this!

  • We need to define an official way for users to record requests from a signed-out user.
  • setUserId('') (called with empty string) should be ignored as some users call it this way and it breaks User ID tracking if we change this (it was reported in When UserID is set to empty string, actions maybe added to the same UserID visit #7368)
  • maybe we can use setUserId(false) for the "Signing out" use case? (edit: actually not a good idea)

Steps:

@peterbo
Copy link
Contributor Author

peterbo commented Mar 31, 2015

Hi Matt!

Instead of calling "setUserId(false)" we could introduce a convenience method like "resetUserId" or "logoutUser" or something more verbose.

Additionally, the recognition code confuses me a bit - in https://github.com/piwik/piwik/blob/master/core/Tracker/Visitor.php#L147 we say that the tracker should not only trust the UserId but also has to search for the user's config_id. In https://github.com/piwik/piwik/blob/master/core/Tracker/Model.php#L358 we UNION results with a) Config_id matched, user_id IS NULL and b) user_id equals the provided user-ID. That includes Users which logged out (no user_id but config_id matches).

Shouldn't we strictly search for the Visitor by user_id if one was provided and at the same time only search a Visitor with user_id IS NULL when a user_id wasn't provided?

@mattab mattab added this to the Short term milestone Apr 8, 2015
@mattab
Copy link
Member

mattab commented Apr 8, 2015

Shouldn't we strictly search for the Visitor by user_id if one was provided and at the same time only search a Visitor with user_id IS NULL when a user_id wasn't provided?

the reason of this lookup is that the first time the User ID is set, we want to assign it to the visit already created - it was done in cd1b52d / #6313

@kachkaev
Copy link

Looks like the issue still remains. I tried one suggested workaround, but it did not help:

if (Piwik.getAsyncTracker().getUserId()) {
    _paq.push(['appendToTrackingUrl', 'new_visit=1']); // (1) forces a new visit
    _paq.push(["deleteCookies"]); // (2) deletes existing tracking cookies to start the new visit
    _paq.push(["setUserId", false]); // tried null, "", etc.
}
_paq.push(["trackPageView"]);
_paq.push(['appendToTrackingUrl', 'new_visit=0']); // undo forcing a new visit in future calls to "trackPageView"

This script was supposed to run when a user presses "log out" in my web app. Network profiling showed that uid remained in the following tracking requests as it was set up previously.

It seems that the only way it is possible to reset a user at the moment is to refresh the page and start the JS tracker from scratch. That's not what may be wanted in some applications.

In meantime, is there any way of getting access to the raw piwik data and just changing the uid parameter in some dirty way? Restarting the app on logout does not look like a good temporal hack to fix tracking data :–)

UPD:_ I finally discovered that it's possible to have some sort of a solution by setting user to "guest" after logging out:

_paq.push(["setUserId", "guest"]);

That's a bit better, but still not ideal in the reports.

@mattab
Copy link
Member

mattab commented Nov 16, 2015

@kachkaev @peterbo I wanted to reproduce this issue but AFAIK the documentation at User ID is still valid, as of today is says:

Signing-in use case: In the case where a person connects to your website and is not logged-in (User ID is not set), a visit is created. If the visitor then logs-in your website and has a User ID set then the first existing visit without User ID will be updated with the User ID and all future requests from this User ID will be added in this same visit. Result: one user, one visit, one unique visitor. (if User ID was not used it would also have created one visit and one unique visitor).

Signing-out use case: In the case where a visitor visits your website and is logged-in (User ID is set) then a visit will be created for this User ID. If then visitor logs out then the visitor has no User ID set any more and a new visit will be created on the page view right after logging out. (if User ID was not used then the requests would have been tracked into one visit and one unique visitor).

ie:

  • actions before the User ID is set, will be attributed to the same visit as the visit with User ID (ie. the User ID will be set for the existing visit)
  • actions after the User logged out (ie. when setUserId is not called at all) will be recorded in a new visit.

it seems the user guides are correct, but maybe I'm missing something?

@mattab
Copy link
Member

mattab commented Nov 16, 2015

Related issue: Piwik might create too many visits when using userId feature #7691

@kachkaev
Copy link

kachkaev commented Nov 17, 2015

@mattab the guides are correct for cases when a website is a set of standalone pages, not a single-page web app. When opening a new page is just rendering a different template without reloading css and js, then this problem with user sign out takes place. I could not find the way of unsetting userId in the JS tracker – it looks like the only thing you can do is to call location.reload(); just after they click "logout". Otherwise all the following events and page views will belong to a user that has recently logged out.

@mattab
Copy link
Member

mattab commented Nov 18, 2015

@kachkaev could you try this patch, whether this works for you? https://github.com/piwik/piwik/compare/7556?expand=1

@kachkaev
Copy link

kachkaev commented Nov 18, 2015

@mattab I’m afraid it will be difficult for me to check this case now since I have already switched to another user-tracking approach in my web app.

Looking at the implementation of setUserId in the PHP tracker and in your change, I see a tiny bit of inconsistency. It may be worth changing the behaviour a little.

The PHP version of the method strictly requires you to supply false to reset userId. The patch suggests that the JS method will also work when you give it undefined or null (as well as no argument). I think it would be nice to handle the data in the same way. Maybe by making things strict and throwing an error when userId is not false or a non-empty string, it will be possible to avoid confusion with the method.

@vladgurovich
Copy link

I second @kachkaev request -- in a modern single page application where there are NO full page reloads, we need a way to reset the user id upon sign out

@kernins
Copy link

kernins commented Aug 22, 2016

In my opinion, there should be no "magic" values to reset userID, but two clearly distinct API methods: setUserId & resetUserId. Resetting userID is necessary only on specific event - user logout, there is no need to reset it just in case (as no-user-id is the default), and so - no need in more "opaque" universal set/reset method

Or, if there are some strong reasons to have one universal method, magic value must be accompanied with proper validation, which will throw an exception when value is invalid and not magic, as already suggested above.

@1ucay
Copy link

1ucay commented Sep 24, 2016

Any workaround for this? Thx

@saithis
Copy link

saithis commented Aug 21, 2017

We also have this problem with a Angular SPA. There is no full page reload, how should we unset the userId on logout?

znerol added a commit to Openki/Openki that referenced this issue Sep 22, 2017
Does not do anything unless `public.piwik` setting is populated with the
following properties:

```
"piwik": {
    "url": "http://piwik.example.com/",
    "site": 1
}
```

Where `url` is the base url to the piwik instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
piwik instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[piwik blog][1].

Regrettably there is currently a [piwik bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://piwik.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
@znerol
Copy link
Contributor

znerol commented Oct 3, 2017

PR: #12141

znerol added a commit to Openki/Openki that referenced this issue Nov 15, 2017
Does not do anything unless `public.piwik` setting is populated with the
following properties:

```
"piwik": {
    "url": "http://piwik.example.com/",
    "site": 1
}
```

Where `url` is the base url to the piwik instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
piwik instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[piwik blog][1].

Regrettably there is currently a [piwik bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://piwik.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Nov 15, 2017
Does not do anything unless `public.piwik` setting is populated with the
following properties:

```
"piwik": {
    "url": "http://piwik.example.com/",
    "site": 1
}
```

Where `url` is the base url to the piwik instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
piwik instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[piwik blog][1].

Regrettably there is currently a [piwik bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://piwik.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
mattab added a commit to matomo-org/matomo-php-tracker that referenced this issue Feb 1, 2018
Implements the new resetUserId() method from JS tracker in matomo-org/matomo#12141 matomo-org/matomo#7556
@mattab mattab modified the milestones: 3.4.0, 3.3.1 Feb 1, 2018
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 3, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
znerol added a commit to Openki/Openki that referenced this issue Feb 4, 2018
Does not do anything unless `public.matomo` setting is populated with the
following properties:

```
"matomo": {
    "url": "http://analytics.example.com/",
    "site": 1
}
```

Where `url` is the base url to the matomo instance (terminating slash is
important) and `site` is the numeric id of the site configured on that
matomo instance.

Iron-router integration was implemented in accordance with
recommendations for single page applications published in the
[matomo blog][1].

Regrettably there is currently a [matomo bug][2] preventing reliable
user-tracking in single-page-applications, hence this is not supported
at this time.

[1]: https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
[2]: matomo-org/matomo#7556
@mattab mattab changed the title UserID "Signing out use-case" - actions still attributed to the same Visitor (2.12.0) UserID "Signing out use-case" - actions still attributed to the same Visitor Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants