Skip to main content

Overview

The MentiQ Analytics SDK provides comprehensive user identification capabilities, allowing you to track both anonymous and identified users, merge user profiles, and enrich user data with custom traits.

User Identity Types

The SDK manages three types of user identifiers:
  1. User ID: Unique identifier for logged-in users
  2. Anonymous ID: Automatically generated for all users
  3. Session ID: Unique identifier for each session

Anonymous Tracking

Anonymous tracking is automatic - no configuration needed:
The anonymous ID is:
  • Generated on first visit
  • Stored in localStorage as mentiq_anonymous_id
  • Persists across sessions and page reloads
  • Included automatically with all events

Identifying Users

Basic User Identification

Call identify() when a user logs in or signs up:
string
required
Unique identifier for the user (e.g., database ID, UUID)

Identification with User Traits

Enrich user profiles with additional information:
string
required
Unique identifier for the user
UserProperties
Object containing user traits. Can include:
  • email: User email address (automatically detected from auth if not provided)
  • name: User full name
  • subscription: Subscription properties (see Subscription Tracking)
  • Custom properties: Any additional user attributes

Managing User IDs

Set User ID

Set or update the user ID without sending an identify event:

Get User ID

Retrieve the current user ID:

Initialize with User ID

Set user ID during initialization:

User Aliasing

Alias allows you to merge user identities, typically when transitioning from anonymous to identified:
string
required
The new user ID (typically the logged-in user ID)
string
The previous user ID or anonymous ID. If omitted, uses the current user ID.

Automatic Aliasing Flow

Resetting User Identity

Reset user identity when logging out:
This:
  • Clears the user ID
  • Clears event queue
  • Generates a new anonymous ID
  • Starts a new session
  • Preserves stored anonymous tracking
Always call reset() when a user logs out to prevent attribution errors.

Automatic Email Detection

The SDK automatically detects user email from popular authentication providers:
  • NextAuth / Auth.js
  • Supabase Auth
  • Firebase Auth
  • Clerk
  • Auth0
No additional configuration needed:
Detected email is:
  • Stored in localStorage as mentiq_user_email
  • Automatically included with all events
  • Used for user attribution and segmentation

Manual Email Override

Manually set email to override auto-detection:

Subscription Tracking

Track user subscription status for SaaS metrics:

Subscription Properties

string
required
Subscription status: "active", "trialing", "past_due", "canceled", "paused", "incomplete", "incomplete_expired", or "unpaid"
string
Unique plan identifier
string
Human-readable plan name
string
Plan tier: "free", "starter", "pro", "enterprise", etc.
number
Monthly Recurring Revenue in cents (e.g., 2900 for $29.00)
number
Annual Recurring Revenue in cents
string
Currency code (e.g., "usd", "eur")
string
Billing cycle: "day", "week", "month", or "year"
string
Payment provider: "stripe", "paddle", "chargebee", "manual", or custom

Automatic Subscription Detection

The SDK automatically detects subscriptions from:
  • Stripe.js
  • Paddle.js
  • Chargebee.js

PCI Compliance

The SDK automatically ensures PCI compliance:
Never include full card numbers or CVV codes. The SDK automatically removes these fields and truncates card numbers to last 4 digits only.

User Trait Enrichment

All events automatically include user traits:

User Persistence

Storage Locations

User data is persisted in browser storage:

Cross-Domain Tracking

For cross-domain tracking, manually pass user identifiers:

Best Practices

Call identify() immediately after successful login or signup to ensure all subsequent events are attributed correctly.
Always call reset() on logout to prevent cross-user contamination.
Use database IDs (not emails) as user IDs for stability - emails can change.
Anonymous and identified user data is automatically merged when you call alias(), preserving the complete user journey.

Common Implementation Patterns

Next.js with NextAuth

React with Supabase

SaaS with Stripe Integration