Skip to main content

User Identity

Analytics

Identify users and associate traits to create segments and personalize experiences.

User Segmentation

Group users by traits

Auto Aliasing

Link anonymous to known

Custom Traits

Any business-relevant data

Group Identity

B2B company tracking

Identify Users

Associate traits with a user:

Server-side
import { platform } from '@/lib/platform'

// Identify with traits
await platform.analytics.identify({
  userId: user.id,
  traits: {
    email: user.email,
    name: user.name,
    createdAt: user.createdAt,
    plan: 'pro',
    company: 'Acme Inc',
    role: 'admin',
  },
})
Client-side (React)
'use client'

import { useAnalytics } from '@sylphx/sdk/react'
import { useEffect } from 'react'

export function IdentifyUser({ user }) {
  const { identify } = useAnalytics()

  useEffect(() => {
    if (user) {
      identify({
        email: user.email,
        name: user.name,
        plan: user.subscription?.plan,
      })
    }
  }, [user, identify])

  return null
}

When to Identify

Call identify at key moments:

After signup

Capture initial user data

After login

Refresh traits and merge anonymous

Profile updates

Keep traits in sync

Subscription changes

Update plan information

After signup
// In your signup handler
async function handleSignup(formData) {
  const user = await createUser(formData)

  // Identify the new user
  await platform.analytics.identify({
    userId: user.id,
    traits: {
      email: user.email,
      name: user.name,
      createdAt: new Date(),
      signupSource: formData.source,
    },
  })

  // Track the signup event
  await platform.analytics.track({
    userId: user.id,
    event: 'signup_completed',
    properties: { method: 'email' },
  })
}

Anonymous to Known

When a user signs up or logs in, link their anonymous activity to their user ID:

// The user has been browsing anonymously with anonymousId
// Now they sign up or log in

await platform.analytics.alias({
  userId: newUser.id,
  previousId: anonymousId, // From cookie or localStorage
})

// Now all previous anonymous events are linked to this user

// Then identify with traits
await platform.analytics.identify({
  userId: newUser.id,
  traits: {
    email: newUser.email,
    name: newUser.name,
  },
})

Automatic Aliasing

If you're using the React SDK, aliasing happens automatically when you call identify with a userId after tracking anonymous events.

Common Traits

Recommended traits to capture:

PropertyTypeDescription
emailstringUser's email address
namestringFull name
createdAtdateAccount creation date
planstringSubscription plan
companystringCompany name (B2B)
rolestringUser role in app
avatarstringAvatar URL
localestringUser's locale (en-US)

Custom Traits

Add any custom traits relevant to your business:

await platform.analytics.identify({
  userId: user.id,
  traits: {
    // Standard traits
    email: user.email,
    name: user.name,

    // Custom traits for your app
    teamSize: 5,
    industry: 'technology',
    referralSource: 'product_hunt',
    onboardingCompleted: true,
    lastActiveAt: new Date(),
    totalPurchases: 3,
    lifetimeValue: 299.97,

    // Nested objects for organization
    preferences: {
      theme: 'dark',
      notifications: true,
    },
  },
})

Group Identification

For B2B apps, identify company/organization traits:

// Identify the user
await platform.analytics.identify({
  userId: user.id,
  traits: {
    email: user.email,
    name: user.name,
  },
})

// Associate user with a group/company
await platform.analytics.group({
  userId: user.id,
  groupId: company.id,
  traits: {
    name: company.name,
    industry: company.industry,
    employees: company.employeeCount,
    plan: company.plan,
    createdAt: company.createdAt,
  },
})

Use Case

Group identification is useful for B2B analytics where you want to analyze behavior at the company level, not just individual users.