Identity Management

Within KISSmetrics there is a concept of an identity which is a unique identifier for a living person. A single person may have multiple identities, such as their e-mail address, username, or a unique cookie. KISSmetrics automatically assigns anonymous identities to your users if you use the Javascript API, but you can make your KISSmetrics data more accurate by giving us named identities for your users.

Anonymous Identities

KISSmetrics automatically assigns anonymous identities to your users if you use the Javascript API. These identities are persisted using first-party browser cookies. These anonymous identities are also useful to track events prior to a user signing up or logging in. However, if your users use multiple computers or you tracking data using multiple APIs (such as using the Javascript API and the Ruby API to send us data) then it is very important that you give KISSmetrics named identities.

Helping KISSmetrics Identify Users

If your site collects unique information about users (such as an e-mail address or a username) this can be used to improve the accuracy of your KISSmetrics data. All you need to do is call the identify method with the named identity you want. Using the Javascript API this might look like:

_kmq.push(['identify', 'bob@bob.com']);

For examples in other languages see: API Methods. If you exclusively use the Javascript API then KISSmetrics will automatically tie any anonymous identity that KISSmetrics previously assigned with the named identity you pass in using the identify method.

Passing in Data from Different APIs

In some cases you might be passing in data from multiple APIs (such as using the Javascript API and the Ruby API to send us data). In these cases it is extremely important that you call identify with named identities that are consistent across all data sources. So if you decide to use the user’s e-mail address you should make sure you call identify with the e-mail address for each API that you are using. As long as you use the same identity the KISSmetrics will record all the data as under the same person regardless of which API you use.

Multiple Identities for a Single Person

The Javascript API will set an anonymous identity for you automatically. When you call identify KISSmetrics will automatically alias the anonymous identity to your given identity (such as an e-mail address or username). All activity, whether the user is logged in or not, will be attributed to that named identity. If you are not using the Javascript API or are using multiple identities for some other reason please read about the alias method here.

Multiple People/Same Computer (Advanced)

What happens if someone in the same household uses the same computer and you call identify again? KISSmetrics will automatically detect this and will not alias the two named identities together (it will recognize them 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:

  1. Bob comes to your site and is assigned the anonymous identity qFq2LweZugFNE4o49hLhmRPBW34
  2. Bob then logs in and you call identify telling us that the identity is now bob@site.com. The activity from before Bob logs in (when we knew him as qFq2LweZugFNE4o49hLhmRPBW34) is automatically tied to bob@site.com.
  3. All activity continues to be attributed to bob@site.com, even after Bob logs out.
  4. 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.
  5. Bill logs in and you call identify telling us that the identity is now bill@site.com. KISSmetrics does not alias bill@site.com and bob@site.com - it treats these as two separate people.
  6. All activity from this point on is attributed to bill@site.com (until you call identify 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? 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:

_kmq.push(['identify', null]);

You can also call clearIdentity directly if you want:

_kmq.push(['clearIdentity']);

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:

_kmq.push(['identify', <%= session[:username].to_json %> ]);

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:

_kmq.push(['identify', 
  <%= @current_user ? @current_user.login.to_json : "null" %> ]);

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:

  1. Bob comes to your site and is assigned the anonymous identity qFq2LweZugFNE4o49hLhmRPBW34
  2. Bob then logs in and you call identify telling us that the identity is now bob@site.com. The activity from before Bob logs in (when we knew him as qFq2LweZugFNE4o49hLhmRPBW34) is automatically tied to bob@site.com.
  3. All activity continues to be attributed to bob@site.com. Bob logs out and you call clearIdentity (or if you are using the session method you end up calling identify with null).
  4. 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 to 7asdafn3128anansdfa32.
  5. Bill logs in and you call identify telling us that the identity is now bill@site.com. KISSmetrics aliases bill@site.com and 7asdafn3128anansdfa32 automatically - tying together Bill’s activity from before he logged in to after he logged in.
  6. All activity from this point on is attributed to bill@site.com (until you call identify 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.

User Privacy

For more information please see User Privacy.


Filed under Advanced

Search


Learn more about KISSmetrics

Get started now