Name signed-in users
Visitors are anonymous by default. When a user signs in to your app, your app can give Ottertrail that user’s ID. Every event from then on carries the ID, and the user’s activity shows on the Users page. See The Users page.
Choose the ID
Section titled “Choose the ID”Use your app’s own ID for the user, such as the user’s ID in your database.
- Do not use an email address or a name. An ID means nothing outside your app.
- The ID has 1 to 200 characters, without control characters.
- Ottertrail stores the ID as you send it. The tracker removes spaces at the start and end.
A user ID is personal data, even when it is only a number. Say in your privacy notice that you send it. Ottertrail deletes it with the project’s events, when the project’s retention removes them, or when you delete the project.
On each page load
Section titled “On each page load”The tracker keeps the ID in memory only. It stores nothing on the device. So put the ID on the script tag of every page that a signed-in user sees:
<script defer src="https://analytics.example.com/t.js" data-key="pk_…" data-host="https://analytics.example.com" data-user-id="42"></script>Leave data-user-id out when nobody is signed in.
If the project accepts only signed user IDs, add data-user-signature too. See Sign user IDs.
In a single-page app
Section titled “In a single-page app”A single-page app can sign a user in or out without a page load. Tell the tracker when that happens.
-
When a user signs in, call
identify()with the ID:window.ottertrail?.identify("42");With a signature, give it as the second argument:
window.ottertrail?.identify("42", signature); -
When the user signs out, call
reset():window.ottertrail?.reset();
Events after identify() carry the ID. Events after reset() are anonymous again. On the next full page load, the script tag gives the ID again.
What counts as the user’s activity
Section titled “What counts as the user’s activity”- Only events that carry the user’s ID count as the user’s. Anonymous events before a sign-in are not added to the user, even in the same visit. Another person can use the same computer.
- Ottertrail never merges two different user IDs.
- Users are listed for one environment at a time, as reports are. The environment picker appears once another environment has known users.
When the ID is not valid
Section titled “When the ID is not valid”If the ID is empty, has more than 200 characters, or has a control character, the tracker sends the events without an ID. It writes a warning in the browser’s console. It does not keep the ID of the user before, because that user can be signed out.