# setUserAttributes()

Sets custom attributes for the current user that can be used in campaign targeting.

> **Note**

User attributes are key-value pairs that help you target campaigns to specific user segments. They're also sent with events for analytics.



Purpose [#purpose]

Sets custom attributes for the current user that can be used for campaign targeting and analytics.

Signature [#signature]

```dart
Future<void> setUserAttributes(Map<String, Object> userAttributes)
```

Parameters [#parameters]

<TypeTable
  type="{
  userAttributes: {
    type: &#x22;Map<String, Object>&#x22;,
    description: &#x22;A map of user attributes to set. Values can be strings, numbers, booleans, or dates.&#x22;,
    required: true,
  },
}"
/>

Returns / State [#returns--state]

Returns a `Future<void>` that completes when the user attributes are set.

If you have a [`SuperwallDelegate`](/docs/flutter/sdk-reference/SuperwallDelegate) set, `userAttributesDidChange` is invoked after the SDK applies the updated attributes.

Usage [#usage]

Basic usage:

```dart
await Superwall.shared.setUserAttributes({
  'plan': 'premium',
  'age': 25,
  'hasCompletedOnboarding': true,
});
```

After user signup:

```dart
Future<void> _setUserProfile(User user) async {
  await Superwall.shared.setUserAttributes({
    'email': user.email,
    'name': user.name,
    'signupDate': user.createdAt.toIso8601String(),
    'referralSource': user.referralSource ?? 'direct',
    'trialEndDate': user.trialEndDate?.toIso8601String(),
    'isFirstTimeUser': user.isFirstTimeUser,
  });
}
```

Updating subscription info:

```dart
Future<void> _updateSubscriptionAttributes(Subscription subscription) async {
  await Superwall.shared.setUserAttributes({
    'subscriptionTier': subscription.tier,
    'subscriptionStartDate': subscription.startDate.toIso8601String(),
    'subscriptionStatus': subscription.status,
    'monthlySpend': subscription.monthlyAmount,
  });
}
```

With error handling:

```dart
Future<void> _safeSetUserAttributes(Map<String, Object> attributes) async {
  try {
    await Superwall.shared.setUserAttributes(attributes);
    print('User attributes updated successfully');
  } catch (e) {
    print('Failed to set user attributes: $e');
  }
}
```