analytics icon indicating copy to clipboard operation
analytics copied to clipboard

analytics.reset() does not reset userId in google-analytics plugin

Open tomek3e opened this issue 3 years ago • 4 comments

Google analytics plugin does not have an implementation for reset, hence after: analytics.reset() userId is still being sent.

tomek3e avatar Nov 14 '22 15:11 tomek3e

True. Based on the docs it should be sending GA a userId of null or "null" (I can't tell for sure which) but in the code it looks like the plugin will ignore null or empty userId values and just leave the userId as it was before.

dobesv avatar Nov 15 '22 17:11 dobesv

I guess the only workaround currently is to do a page reload, although I suppose GA would still store a cookie or value in local storage in that case so even then it could remember the old value.

dobesv avatar Nov 15 '22 17:11 dobesv

Correct, even page reload will not work so I am extending the plugin to handle my use case (chrome kiosk mode - multiple users on same device):

  1. Set user_id to undefined.
  2. Set client_id to a new value - in google format XXX.YYY, where XXX is a random part and YYY is a unix timestamp.
  3. Clear the cookie.

If I don't do points 2 & 3 the subsequent events on the same device will still be associated with the same user in analytics.

tomek3e avatar Nov 16 '22 08:11 tomek3e

Yeah looks like ga4 and ga3 plugin don't have a reset defined like so https://github.com/DavidWells/analytics/blob/0fb5860bf2b7e2c180dbc0462c66c6bd36331fde/packages/analytics-plugin-original-source/src/index.js#L40-L43 so there isn't any cleanup action happening in them. Only the libs values are getting reset.

We'd need a reset method defined in the plugin where u can run this logic. You can extend this in userland like so https://github.com/DavidWells/analytics/issues/67#issuecomment-664804311

DavidWells avatar Nov 18 '22 00:11 DavidWells