User Identification
Track which users are affected by errors to prioritize fixes and provide better support.
Overview
User identification allows you to:
- See which users are affected by specific errors
- Search for all errors affecting a particular user
- Prioritize fixes based on user impact
- Provide better customer support
Automatic User Identification
Enable automatic user identification in config/nadi.php:
'user' => [
'auto_identify' => true,
'fields' => ['id', 'email', 'name'],
'capture_ip' => true,
],When enabled, the SDK automatically captures authenticated user information.
Manual User Identification
Set user information explicitly:
use Nadi\Laravel\Facades\Nadi;
Nadi::setUser([
'id' => $user->id,
'email' => $user->email,
'name' => $user->name,
]);Additional User Fields
Include any relevant user information:
Nadi::setUser([
'id' => $user->id,
'email' => $user->email,
'name' => $user->name,
'username' => $user->username,
'subscription' => $user->subscription_plan,
'company' => $user->company?->name,
]);IP Address Tracking
By default, the SDK captures the user's IP address for geographic context:
// config/nadi.php
'user' => [
'capture_ip' => true,
],To disable IP capturing:
'user' => [
'capture_ip' => false,
],Identifying Anonymous Users
For users who aren't logged in, you can still track them:
use Nadi\Laravel\Facades\Nadi;
// Using session ID
Nadi::setUser([
'id' => 'anon:' . session()->getId(),
]);
// Using a tracking cookie
Nadi::setUser([
'id' => 'anon:' . request()->cookie('tracking_id'),
]);User Context in Middleware
Set user context early using middleware:
namespace App\Http\Middleware;
use Nadi\Laravel\Facades\Nadi;
class IdentifyUserForNadi
{
public function handle($request, $next)
{
if ($user = $request->user()) {
Nadi::setUser([
'id' => $user->id,
'email' => $user->email,
'name' => $user->name,
'subscription' => $user->subscription_plan,
]);
} else {
// Track anonymous users with session ID
Nadi::setUser([
'id' => 'anon:' . session()->getId(),
]);
}
return $next($request);
}
}Register after authentication middleware:
// app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
// ...
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\Authenticate::class,
\App\Http\Middleware\IdentifyUserForNadi::class,
],
];Multi-Tenant Applications
For multi-tenant apps, include tenant information:
Nadi::setUser([
'id' => $user->id,
'email' => $user->email,
'name' => $user->name,
]);
Nadi::setTag('tenant_id', $tenant->id);
Nadi::setExtra('tenant_name', $tenant->name);API Authentication
For API requests with token authentication:
namespace App\Http\Middleware;
use Nadi\Laravel\Facades\Nadi;
class IdentifyApiUser
{
public function handle($request, $next)
{
if ($user = $request->user('api')) {
Nadi::setUser([
'id' => $user->id,
'email' => $user->email,
'type' => 'api_user',
]);
// Track which API token was used
if ($token = $user->currentAccessToken()) {
Nadi::setExtra('token_name', $token->name);
}
}
return $next($request);
}
}Clearing User Data
Clear user information when they log out:
use Nadi\Laravel\Facades\Nadi;
class LogoutController
{
public function __invoke()
{
Nadi::setUser(null);
auth()->logout();
return redirect('/');
}
}Or using Laravel's event system:
// EventServiceProvider.php
use Illuminate\Auth\Events\Logout;
protected $listen = [
Logout::class => [
ClearNadiUser::class,
],
];// app/Listeners/ClearNadiUser.php
use Nadi\Laravel\Facades\Nadi;
class ClearNadiUser
{
public function handle(Logout $event)
{
Nadi::setUser(null);
}
}Privacy Considerations
GDPR Compliance
For GDPR compliance, consider:
- Minimize data collection - Only capture necessary fields
- Anonymize when possible - Use hashed identifiers
- Respect consent - Honor user privacy preferences
// Only track users who have consented
if ($user->hasConsentedToErrorTracking()) {
Nadi::setUser([
'id' => $user->id,
'email' => $user->email,
]);
} else {
Nadi::setUser([
'id' => 'gdpr-opted-out:' . hash('sha256', $user->id),
]);
}Hashing Sensitive Data
Hash identifiable information:
Nadi::setUser([
'id' => hash('sha256', $user->id . config('app.key')),
// Don't include email
]);Best Practices
Do
- Include user ID (required for user tracking)
- Include email for easier user identification
- Use consistent field names
- Set user context early in the request lifecycle
Don't
- Include passwords or authentication tokens
- Include sensitive personal information (SSN, etc.)
- Include payment information
- Over-collect user data
Viewing User Data
In the Nadi dashboard:
- Error Details - See affected users for each error
- User Search - Find all errors for a specific user
- Impact Analysis - See unique user count per error
Next Steps
- Performance Monitoring - Track application performance
- Sampling - Control event volume
- Troubleshooting - Debug integration issues