viakite
Dashboard

SDKs/Web/identify()

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

ts
1function identify(userId: string, traits?: Props): void;

Parameters

userIdstringrequired

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.

traitsProps

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

src/auth.ts
1import { identify } from "@viakite/sdk";
2
3identify("user_8231", { plan: "pro", company: "Acme" });
auth.js
1viakite.identify("user_8231", { plan: "pro", company: "Acme" });

On each page load, once you know who is signed in:

app/providers.tsx
1"use client";
2import { useEffect } from "react";
3import { identify } from "@viakite/sdk";
4
5export function Identify({ userId }: { userId?: string }) {
6 useEffect(() => {
7 if (userId) identify(userId);
8 }, [userId]);
9 return null;
10}

How it works

  • It sends an identify event 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 once init() does.
  • reset() forgets the id.

What is dropped

What you sendWhat happens
An empty idNothing 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 charactersCut to 120
A trait that breaks a ruleThat 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 lineMeans
[viakite] user id looks personal; droppedThe id looks like an e-mail address or phone number; nothing was sent.
[viakite] user id cut to 120The id was too long.
[viakite] plan: droppedA trait broke a rule.

Next steps