DavidWells / analytics

Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors
https://getanalytics.io
MIT License
2.43k stars 247 forks source link

What's the difference between `payload.userId` and `instance.user('userId')`? No way to reset google-tag-manager `userId` property #399

Open benjamindulau opened 1 year ago

benjamindulau commented 1 year ago

I don't quite understand where the payload.userId comes from here https://github.com/DavidWells/analytics/blob/master/packages/analytics-plugin-google-tag-manager/src/browser.js#L81

Problem is once you called identify with a non null userId, there is absolutely no way to set it back to null. Neither calling identify() again without an userId nor calling analytics.reset() have any effect on this.

Every subsequent calls to track include a stale userId property...

What code is responsible of setting this userId property in the payload object? And why is this plugin using this instead of instance.user('userId')? What's the difference between the two?

Thanks :)

benjamindulau commented 1 year ago

Well it seems that calling reset() or identify() or identify(null) does not clear instance.user('userId') either... I give up, I don't understand what is the recommended way to handle the user identification there.

user.traits are correctly overridden, but I don't find any way to clear the user.userId property..