Swift SDK
User Identification
Identifying users in UserJot allows you to track who’s submitting feedback, follow up with users, and provide a personalized experience.
Basic Identification
The simplest way to identify a user requires only a unique user ID:
UserJot.identify(userId: "user123")
This associates all feedback from this session with the specified user ID.
Identification with Email
Adding an email enables UserJot to send notifications about feedback status changes:
UserJot.identify(
userId: "user123",
email: "john@example.com"
)
Full User Profile
Provide additional details for a complete user profile:
UserJot.identify(
userId: "user123",
email: "john@example.com",
firstName: "John",
lastName: "Doe",
avatar: "https://example.com/avatars/john.jpg"
)
Profile Fields
- userId (required): Unique identifier from your system
- email: User’s email address for notifications
- firstName: User’s first name
- lastName: User’s last name
- avatar: URL to user’s profile picture
Secure Authentication
For enhanced security, use server-side signatures to verify user identity:
UserJot.identify(
userId: "user123",
email: "john@example.com",
signature: "abc123..." // HMAC-SHA256 signature from your server
)
See the Server Authentication guide for details on generating HMAC-SHA256 signatures on your server.
When to Identify Users
App Launch
Identify users when your app launches if they’re already logged in:
// SwiftUI
@main
struct MyApp: App {
@StateObject private var authManager = AuthManager()
init() {
UserJot.setup(projectId: "YOUR_PROJECT_ID")
}
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
if authManager.isLoggedIn {
UserJot.identify(userId: authManager.userId)
}
}
}
}
}
After Login
Identify users immediately after successful authentication:
func loginUser(email: String, password: String) async {
do {
let user = try await authService.login(email: email, password: password)
// Identify in UserJot
UserJot.identify(
userId: user.id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName
)
// Continue with app flow
navigateToHome()
} catch {
// Handle login error
}
}
Profile Updates
Re-identify when user profile information changes:
func updateUserProfile(firstName: String, lastName: String) {
// Update in your system
currentUser.firstName = firstName
currentUser.lastName = lastName
// Update in UserJot
UserJot.identify(
userId: currentUser.id,
email: currentUser.email,
firstName: firstName,
lastName: lastName
)
}
Logging Out Users
Clear user identification when users log out:
func logout() {
// Your logout logic
authService.logout()
// Clear UserJot identification
UserJot.logout()
// Navigate to login screen
navigateToLogin()
}
Anonymous Feedback
Users can submit feedback without identification if you have Guest Posting enabled in your UserJot dashboard.
To allow anonymous feedback:
- Go to your UserJot Dashboard
- Navigate to Settings → Feedback
- Enable Guest Posting
Then users can submit feedback without calling identify():
// Show feedback form without identification
// Feedback will be submitted anonymously
UserJot.showFeedback()
Best Practices
- Identify early: Call identify as soon as you have user information
- Keep data current: Re-identify when user profile changes
- Use signatures in production: Implement server-side signatures for production apps
- Handle logout: Always call
UserJot.logout()when users sign out - Graceful fallbacks: Handle cases where identification might fail
Troubleshooting
User Not Identified
If feedback isn’t associated with users:
- Verify
identify()is called beforeshowFeedback() - Check that userId is not nil or empty
- Ensure you’re passing the correct user data
Signature Validation Failed
If using signatures and getting validation errors:
- Verify the secret key matches between server and UserJot settings
- Ensure signature is generated using HMAC-SHA256
- Check that userId in signature matches the one sent to identify