In Amplitude, why should a web app call reset() when a user logs out?
answer
- The browser keeps its identifier after logout
- Two identifiers resolve to one internal user
- Anonymous events after logout need somewhere to go
- Clearing only the user id is not enough
- Merges cannot be unpicked later
basics
~20 sBecause the browser's device ID stays mapped to the user who just logged out. reset() clears the user ID and issues a new device ID, so the next visitor's anonymous events start a fresh identity instead of being attributed to the previous person.
solid answer
~50 sAmplitude resolves identity by mapping `device_id` and `user_id` onto an internal Amplitude ID. Once a device has been associated with a user, events arriving from that device with no `user_id` still resolve to that user — which is exactly what you want mid-session and exactly what you do not want after logout. `amplitude.reset()` clears the stored user ID **and** generates a new device ID, breaking that association so the next visitor on a shared laptop or kiosk is a genuinely new anonymous identity. Skip it and you get inflated activity for the previous user, polluted funnels and cohorts, and a merge you cannot undo — Amplitude's identity merges are not reversible. The mirror-image mistake is calling `reset()` right after a successful login, which throws away the anonymous-to-known stitching that lets you measure the pre-signup funnel.
code
javascript · 11 lines// LOGIN: let the anonymous history merge into the known user
function onLoginSuccess(user) {
amplitude.setUserId(user.id); // no reset here
amplitude.identify(new amplitude.Identify().set('plan', user.plan));
}
// LOGOUT: sever the device association before anything else is tracked
function onLogout() {
amplitude.reset(); // clears user id AND issues a new device id
redirectToMarketingHome();
}go deeper
Know that Amplitude tracks a device identifier separately from the user identifier, and that reset() clears the user and issues a new device id — normally on logout.
Explain how the two identifiers resolve to one internal user, why the device stays mapped after logout, and why clearing only the user id does not fix it.
Walk through the concrete damage on a shared device — inflated retention, mixed funnels, cohorts syncing to the wrong person — and know that merges are irreversible, so the response is stop-and-annotate, not clean-up.
Own one identity policy across web, mobile and server: which identifier travels where, when stitching is intended, and how you audit for cross-user contamination before it reaches downstream activation tools.
## The identity model underneath the question Amplitude does not have one identifier; it has two inputs and one derived key. Every event carries a `device_id` (generated by the SDK and persisted in browser storage) and, once the user is known, a `user_id` you supply through `setUserId` or on the event payload. Amplitude resolves the pair onto an internal **Amplitude ID**, which is the thing charts actually count as a user. The resolution rules are what make the logout question interesting: - A device seen for the first time with no user id gets an anonymous Amplitude ID of its own. - When that device later sends a `user_id` that Amplitude has not associated with anyone, the anonymous history on the device is **merged into that user**. This is the good case: the visitor who browsed for a week before signing up keeps their pre-signup events, so the acquisition funnel is measurable. - Once the association exists, events from that device with no `user_id` continue to resolve to that user, because the device is already mapped. That last rule is the trap. Logging out in your application is a state change in *your* code; unless you tell the SDK, nothing about the browser's device id has changed. ## What goes wrong without reset() User A logs out on a shared laptop. User B sits down and browses anonymously before logging in. Every event B generates in that anonymous window still carries A's device id, so it resolves to A. The damage is quiet but broad: - **Inflated activity and retention for A.** A looks like a power user who came back; retention curves and active-user counts absorb someone else's behaviour. - **Broken funnels.** A conversion path gets steps performed by two different humans, which produces conversion rates that are not describing any real person's journey. - **Polluted behavioural cohorts.** If those cohorts sync outward to marketing or lifecycle tools, the wrong person receives the campaign — the error escapes analytics and reaches customers. - **Irreversible merges.** Amplitude's identity merges cannot be unpicked after the fact. There is no supported "split these two users back apart" operation, so this is not a bug you clean up; it is one you stop repeating and then live with in historical data. Kiosks, call-centre workstations, family tablets, demo laptops and shared support accounts are where this shows up worst, because the same device serves many people per day. ## What reset() actually does `amplitude.reset()` in the Browser SDK does two things together: it clears the stored user id, and it generates a **new device id**. Both halves matter. Clearing only the user id — for example by calling `setUserId` with an empty value — leaves the old device id in place and therefore leaves the association intact, which is the subtly-wrong fix candidates often propose. The new device id is what actually severs the link. Call it as part of the logout routine, alongside clearing your own session storage, and call it *before* any post-logout page view is tracked so the redirect to the marketing page does not land on the previous user. ## The mirror-image mistake Calling `reset()` at login is worse than useless. The whole value of Amplitude's anonymous-to-known merge is that the pre-signup journey — landing page, pricing page, trial start — stays attached to the person who eventually converted. Reset immediately before or after `setUserId` throws that history away by minting a new device id, and the acquisition funnel becomes unmeasurable from the first anonymous step. The correct login sequence is simply to call `setUserId` with the identifier; the merge happens because the device was already anonymous. ## Server-side and multi-surface complications Events sent from your backend have no browser storage and therefore no device id unless you supply one. If server events carry only a `user_id`, they resolve to that user, which is usually fine — but they cannot participate in the anonymous merge, so a signup completed server-side will not stitch the visitor's earlier anonymous browsing unless you propagate the client's device id into the backend call. Teams that instrument the same funnel across web, mobile and server need one deliberate rule for which identifier travels where. ## How to answer this in an interview State the mechanism (device id and user id resolve to an Amplitude ID), then the specific consequence at logout (the device stays mapped, so the next visitor is counted as the previous user), then the fix (`reset()` clears the user id and issues a new device id), then the two boundaries: merges are irreversible, and resetting at login destroys the stitching you actually want. Mentioning shared devices and kiosks shows you have thought about where the failure is common rather than theoretical.
- Why is calling reset() immediately after a successful login a mistake?It destroys the anonymous-to-known merge. Amplitude stitches a device's pre-login history onto the user id the first time it sees one, which is what makes the landing-page-to-signup funnel measurable. Minting a new device id at login discards that history, so every converted user appears to spring into existence at signup with no acquisition path. The correct login call is just setUserId.
- Is calling setUserId with an empty value an acceptable substitute for reset() at logout?No. It clears the user id but leaves the device id in place, and the device is already associated with the previous user, so subsequent anonymous events still resolve to them. The new device id is the part that actually severs the link, which is why reset does both together.
- You discover months of shared-kiosk events merged into one user. Can you split them apart?Not through the product — Amplitude's identity merges are not reversible, and there is no supported operation to separate two identities after the fact. Fix the instrumentation first, then decide how to handle history: exclude the known kiosk device or user from analyses, annotate the date range, and if the raw event stream is exported to a warehouse, rebuild the affected metrics there where you still control the join.
- How do server-side events fit into this identity model?Backend events have no browser storage, so unless you pass a device id they carry only a user id and resolve directly to that user. That is fine for known users but means they cannot participate in the anonymous merge. If a signup is completed server-side, propagate the client's device id into the backend call so the visitor's earlier anonymous browsing still stitches to the new account.
Logging out of your app is like closing the ledger; without resetting, the browser is still wearing the previous customer's name badge when the next person walks in.
saying these in an interview costs you the question
- Assumes logging out of the app also resets the SDK identity
- Says clearing the user id alone is enough
- Calls reset at login, destroying anonymous-to-known stitching
- Believes a bad identity merge can be undone later
- Ignores shared devices and kiosks as a real deployment case