identifyUser method
Identifies a user by sending a POST request to Evntaly.
userData - The user identification payload. Can be either:
- EvntalyUser object (recommended for IntelliSense support)
- Map<String, dynamic> for flexible custom user data
Example with typed user:
await EvntalyClient.instance.identifyUser(
EvntalyUser(
id: 'user_123',
email: 'user@example.com',
fullName: 'John Doe',
organization: 'Acme Corp',
data: {'license': 'Premium'},
),
);
Example with Map (flexible):
await EvntalyClient.instance.identifyUser({
'id': 'user_123',
'email': 'user@example.com',
});
Implementation
Future<void> identifyUser(dynamic userData) async {
try {
if (!_initialized) {
_log('SDK not initialized. Please call init() first.', level: 'error');
return;
}
// Convert EvntalyUser to Map if needed
Map<String, dynamic> userMap;
if (userData is EvntalyUser) {
userMap = userData.toMap();
} else if (userData is Map<String, dynamic>) {
userMap = userData;
} else {
_log('Invalid userData type. Expected EvntalyUser or Map<String, dynamic>', level: 'error');
return;
}
final url = Uri.parse('$_baseUrl/api/v1/register/user');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
'secret': _developerSecret ?? '',
'pat': _projectToken ?? '',
},
body: jsonEncode(userMap),
);
_log('Identify user response:', level: 'log', args: [response.body]);
} catch (error) {
_log('Identify user error:', level: 'error', args: [error]);
}
}