identify()
Tie events to your user
identify() ties the events of this tab to your own user id, so you can follow one person across visits on the Users page. Call it when someone signs in, and again on each page load while they stay signed in.
Signature
1function identify(userId: string, traits?: Props): void;
Parameters
Your own id for this user, up to 120 characters, such as your database id (user_8231). Never an e-mail address or a phone number: an id that looks like one is dropped.
Facts about the user, such as their plan or company. The same limits as event properties: up to 20, flat, keys of 1 to 40 characters, text up to 255. See track().
Examples
1import { identify } from "@viakite/sdk";23identify("user_8231", { plan: "pro", company: "Acme" });
1viakite.identify("user_8231", { plan: "pro", company: "Acme" });
On each page load, once you know who is signed in:
1"use client";2import { useEffect } from "react";3import { identify } from "@viakite/sdk";45export function Identify({ userId }: { userId?: string }) {6useEffect(() => {7if (userId) identify(userId);8}, [userId]);9return null;10}
How it works
- It sends an
identifyevent with the id and the traits. - Every event after it in this tab carries the id: page views, custom events and engagement.
- The id lives in memory only, for this tab. Nothing is stored on the device, so a new tab or a full page load starts without it. Call
identify()again on each page load. - A second call with another id replaces the first.
- Called before
init(), it waits and runs onceinit()does. - reset() forgets the id.
What is dropped
| What you send | What happens |
|---|---|
| An empty id | Nothing is sent; the current id stays |
An id that looks like an e-mail address (asha@example.com) | Dropped: nothing is sent and the current id stays |
An id with 7 or more digits in a row, after spaces, dots, dashes and brackets are removed (+91 98765 43210) | Dropped, as a phone number |
| An id over 120 characters | Cut to 120 |
| A trait that breaks a rule | That trait is dropped; the rest are sent |
Any id with 7 or more digits in a row reads as a phone number and is dropped, even with a prefix: 12345678 and user_12345678 are both dropped. A UUID can hold 7 digits in a row too, once its dashes are removed. If your ids are long numbers, send another id you keep for each user, with fewer than 7 digits in a row.
Why no e-mail addresses
Viakite keeps no personal data about your visitors. Your own id lets you look the person up in your own system, while Viakite holds only the id.
Warnings in debug mode
identify() never throws. With debug on:
| Console line | Means |
|---|---|
[viakite] user id looks personal; dropped | The id looks like an e-mail address or phone number; nothing was sent. |
[viakite] user id cut to 120 | The id was too long. |
[viakite] plan: dropped | A trait broke a rule. |