Multiple People on the Same Browser
What happens if two people use the same computer and you call identify
multiple times? Kissmetrics will recognize the different identities as separate people. However, it should be noted that any activity before you call identify
for the second user will be attributed to the first user. Let’s see how this works:
- Bob comes to your site and is assigned the anonymous identity
qFq2LweZugFNE4o49hLhmRPBW34
- Bob then logs in and you call
identify
telling us that the identity is nowbob@site.com
. The activity from before Bob logs in (when we knew him asqFq2LweZugFNE4o49hLhmRPBW34
) is automatically tied tobob@site.com
. - All activity continues to be attributed to
bob@site.com
, even after Bob logs out. - Now Bob’s brother Bill comes in to use the computer and visits your site. All activity will continue to be attributed to
bob@site.com
. Kissmetrics has no way to know that it is a different person sitting at the keyboard automatically. - Bill logs in and you call
identify
telling us that the identity is nowbill@site.com
. Kissmetrics does not aliasbill@site.com
andbob@site.com
- it treats these as two separate people. - All activity from this point on is attributed to
bill@site.com
(until you callidentify
again)
As you can see the system works pretty well automatically under most circumstances. However, what if we wanted to prevent some of Bill’s anonymous activity (pre-login) activity from being attributed to Bob?
clearIdentity
All you need to do is clear the identity when Bob logs out (or his session expires). If you call identify
with a null
value then Kissmetrics will reset the identity on the current computer so that the next user is treated anonymously:
You can also call clearIdentity
directly if you want:
However, in most cases the best thing to do is to set the identity you want from a session variable. This way you don’t have to worry about people who didn’t actually click a “log out” button. So if I were using Ruby I might have a session variable username
which I set to the user’s username when they login and then do something like:
Once the session ends (through logout or expiration) then the value of session[:username]
will be null
so the named identity will be cleared out. It should be noted that calling identity
with a null
value or calling clearIdentity
only clears the named identity. Calling either method more than once will have no negative effect. It will not keep regenerating anonymous identities, it only clears any named identity you happen to have passed in. Many people assign the currently logged in user to a variable in their views. Let’s say I assigned the current user to the variable @current_user
, then my code might look like:
Just using this single line will make everything work automatically. When the @current_user
variable is set, we’ll get the identity. When the user logs out or their session expires then the @current_user
variable will not exist and the Kissmetrics named identity will be cleared. So let’s see how this works now:
- Bob comes to your site and is assigned the anonymous identity
qFq2LweZugFNE4o49hLhmRPBW34
- Bob then logs in and you call
identify
telling us that the identity is nowbob@site.com
. The activity from before Bob logs in (when we knew him asqFq2LweZugFNE4o49hLhmRPBW34
) is automatically tied tobob@site.com
. - All activity continues to be attributed to
bob@site.com
. Bob logs out and you callclearIdentity
(or if you are using the session method you end up callingidentify
withnull
). - Now Bob’s brother Bill comes in to use the computer and visits your site. However, since identity was cleared a new anonymous identity is generated:
7asdafn3128anansdfa32
. All activity will be attributed to7asdafn3128anansdfa32
. - Bill logs in and you call
identify
telling us that the identity is nowbill@site.com
. Kissmetrics aliasesbill@site.com
and7asdafn3128anansdfa32
automatically - tying together Bill’s activity from before he logged in to after he logged in. - All activity from this point on is attributed to
bill@site.com
(until you callidentify
again)
So this does require a little more work and integration on your end, but it will result in slightly more accurate tracking. This is only an issue if more than once person shares the computer and you are tracking both anonymous activity and logged-in activity. For most sites this level of integration is not needed.