Skip to Content
IdentityVerifying Identity

Verifying Identity

Browsers and apps send events with a public write key, so an event can say anything about who is visiting. Identity verification lets your own systems vouch for a login, so realtime identity can tell a login your server confirmed from one a page merely claims. Verified logins join a visitor’s devices to their profile with confidence, and you decide how strict realtime identity should be about the rest.

There are two ways to vouch for a login:

  • Identity tokens. After someone signs in, your server signs a short-lived token and hands it to the page or app, which passes it to the SDK. The token vouches for that person on that device.
  • Server write credentials. Events your server sends with a server write credential are trusted for every identifier they carry.
Your server signs a token after a login, the page passes it to identify, the token is checked when the event arrives, and the device joins the person's profile

Open Identity Resolution and select Identity verification to manage both, and to choose the verification level. The page is available in workspaces with realtime identity.

The Identity verification page with the verification level, an active secret and a server write credential

Verification levels

LevelWhat it means
OffIdentity tokens are ignored, and every identifier is linked as the event states it.
Recommended (default)Tokens are checked when sent. A browser or app can link its own device to a login, but it cannot join two people who are already known.
RequiredA login or an email is linked to a device only when an identity token or a server write credential vouches for it. Choose this when a login that was never confirmed must never reach a person’s profile.
The verification level set to Required, with its explanation

The same card sets what happens to events that carry no consent information: Link identifiers (the default) or Do not link identifiers.

Identity token secrets

Your server signs identity tokens with your workspace’s secret. Select Create secret to make one. The secret is shown once: copy it into your server’s secret store straight away. It must never reach a browser or an app.

The dialog showing a new identity verification secret, to be copied once

Each secret has a key id, which every token names. To change the secret, select Rotate secret and choose how long the current one keeps working: an hour, a day or a week, so tokens your servers already issued keep working while you deploy the new secret. You can also stop it at once. Revoke stops a secret immediately.

Minting an identity token

A token is three parts joined by dots: sit1, the claims, and a signature.

ClaimValue
kidThe key id of your secret.
workspace_idYour workspace id.
user_idThe user id you send in identify.
anonymous_idThe visitor’s anonymous id, which the SDK gives you with getAnonymousId(). The token is valid only for this device.
identitiesOptional: other identifiers the token vouches for, as { family, value_key }. An email can be given as the address or as the SHA-256 of the lower-cased address.
iat, expWhen the token was issued and when it expires, in seconds. A token lives at most 15 minutes.

The signature is an HMAC-SHA256, keyed with your secret, over the claims written in a fixed order. Each value is written as its length in bytes, a colon and the value itself, in this order: sit1, kid, workspace_id, user_id (empty when there is none), anonymous_id, iat, exp, the number of identities, then the family and value_key of each identity. The claims part of the token is the claims as JSON, and both the claims and the signature are base64url-encoded without padding.

Node.js
import { createHmac } from 'node:crypto'; export function identityToken(secret, kid, workspaceId, userId, anonymousId, identities = []) { const iat = Math.floor(Date.now() / 1000); const claims = { kid, workspace_id: workspaceId, user_id: userId, anonymous_id: anonymousId, identities, iat, exp: iat + 600 }; const field = (s) => `${Buffer.byteLength(s, 'utf8')}:${s}`; let signed = field('sit1') + field(kid) + field(workspaceId) + field(userId ?? '') + field(anonymousId) + field(String(iat)) + field(String(claims.exp)) + field(String(identities.length)); for (const i of identities) signed += field(i.family) + field(i.value_key); const body = Buffer.from(JSON.stringify(claims)).toString('base64url'); const sig = createHmac('sha256', secret).update(signed, 'utf8').digest('base64url'); return `sit1.${body}.${sig}`; }
Python
import base64, hashlib, hmac, json, time def b64url(b: bytes) -> str: return base64.urlsafe_b64encode(b).rstrip(b"=").decode() def identity_token(secret, kid, workspace_id, user_id, anonymous_id, identities=()): iat = int(time.time()) claims = {"kid": kid, "workspace_id": workspace_id, "user_id": user_id, "anonymous_id": anonymous_id, "identities": list(identities), "iat": iat, "exp": iat + 600} field = lambda s: f"{len(s.encode())}:{s}" signed = "".join(field(v) for v in ["sit1", kid, workspace_id, user_id or "", anonymous_id, str(iat), str(claims["exp"]), str(len(claims["identities"]))]) for i in claims["identities"]: signed += field(i["family"]) + field(i["value_key"]) sig = hmac.new(secret.encode(), signed.encode(), hashlib.sha256).digest() return f"sit1.{b64url(json.dumps(claims).encode())}.{b64url(sig)}"

A token vouches only for the identifiers it names, and only on the device it names. An event from another device, or about another user, is accepted as usual but is not verified.

Sending the token from the SDK

Pass the token with the login. Identify calls are sent at once, so the login reaches realtime identity in the time it takes to send.

Browser
zeotap.identify(userId, { plan: 'pro' }, { identityToken: tokenFromYourServer }); // Or, on later pages of the same visit: zeotap.setIdentityToken(tokenFromYourServer);
SDKHow
Browseridentify(userId, traits, { identityToken }) or setIdentityToken(token)
iOSanalytics.identify(userId:traits:options: IdentifyOptions(identityToken:)) or setIdentityToken(_:)
Androidanalytics.identify(userId, traits, IdentifyOptions(null, token), null) or setIdentityToken(token)
React NativeZeotap.identify(userId, traits, { identityToken }) or Zeotap.setIdentityToken(token)
Google Tag ManagerThe Identity token field of the Identify tag, or the Set Identity Token tag
Adobe LaunchThe Identity token field of the Identify action

The SDK keeps the token in memory until it expires and attaches it to every event, and forgets it on reset(). The token is removed from each event when it arrives, so it is never stored with your events or sent to your destinations.

Server write credentials

A server write credential belongs to one event source. Choose the source, give the credential a name and select Create credential. Like a secret, it is shown once.

Send events from your server with the credential in the Authorization header, instead of the write key:

curl https://events.zeotap.com/v1/identify \ -H "Authorization: Bearer swk_..." \ -H "Content-Type: application/json" \ -d '{"userId": "customer-42", "anonymousId": "3f6c2a8e-0b7d-4a51-9c1e-2d4f6a8b0c1d"}'

Every identifier on these events is verified. A server write credential is refused when a browser sends it, so it cannot be used from a web page. Revoke stops a credential at once; the page shows when each was last used.

Profile ids in the SDK

The SDK can tell your page which profile the visitor belongs to. Give it your Site key and call getProfileId():

zeotap.load(writeKey, { identity: { siteKey: 'psk_...' } }); const profile = await zeotap.getProfileId(); // { profileId, graphId, status } or null zeotap.onProfileChange(({ profileId, previousProfileId, reason }) => { // for example, after a login joins this device to a known person });

The profile id is remembered only while the visitor has given identify consent.

Linking calls, identify, alias and setUserIdentities, all follow the identify consent signal. When a visitor withdraws identify consent, the SDK tells Zeotap straight away, and the visitor’s device is separated from their profile.

Last updated on