Home
Quick start
Identifying users
Tracking events
Tracking groups

Technical Guides

Browser
Node.js
Ruby
Python
HTTP API
License
Sign in

Identifying Users

Correlate user behavior with identity

What we'll cover

Identifying users allows June to correlate app activity with their identity. You'll be able to segment users and generate more accurate reports with this data.

This will take less than 15 minutes and consist of three easy steps:

  • Adding a call on sign in · 5 minutes
  • Adding a call on register · 5 minutes
  • Logging out users on exit · 5 minutes

If you haven't installed June's script yet, don't panic! Head over to the Quick Start Guide.

Adding a call on sign in

First, we begin by adding an analytics.identify call wherever the user signs in to your app. This could be a login form, SSO redirect, or any other authentication scheme.

1
// Assuming using the inline browser script, we use window.analytics.
2
3
// Send an identify call once the user signs in.
4
async function signIn(username, password) {
5
const user = await login(username, password);
6
// ... user variable contains a JSON object identifying the user:
7
// e.g. {id: 1, first_name: "Enzo", last_name: "Avigo", favorite_color: "blue"}
8
window.analytics.identify(user.id, { favorite_color: user.favorite_color });
9
}

If you're doing an HTML form or server-side rendered app, the best approach is to serialize the user parameters to JSON and pass them to a script. An example for Rails would be:

1
<script>
2
window.analytics.identify(<%= user.id %>, { favorite_color: <%= user.favorite_color %> });
3
</script>

Adding a call on register

Now, let's add an analytics.identify call on register. This is a good place to send the user's details and initiate their first records.

1
// Send an identify call once the user signs up.
2
async function signUp(username, password) {
3
const user = await register(username, password);
4
// ... user variable contains a JSON object identifying the user:
5
// e.g. {id: 1, first_name: "Enzo", last_name: "Avigo", favorite_color: "blue"}
6
window.analytics.identify(user.id, { favorite_color: user.favorite_color });
7
}

Logging out users on exit

Finally, let's add a call on logout. This makes sure we track users accurately, especially in multi-user environments.

1
// Reset the session on logout.
2
async function signOut() {
3
await clearSession();
4
window.analytics.reset();
5
}

Next steps

Congrats, you're done! Here's other guides to check out: