---
title: "Flutter SDKでユーザー属性を設定する"
description: "Adaptyでユーザー属性を設定し、より正確なオーディエンスセグメンテーションを実現する方法を学びましょう。"
---

メールアドレスや電話番号などのオプション属性をアプリのユーザーに設定できます。設定した属性は、ユーザー[セグメント](segments)の作成やCRMでの閲覧に活用できます。

### ユーザー属性の設定 \{#setting-user-attributes\}

ユーザー属性を設定するには、`.updateProfile()` メソッドを呼び出します：

```dart showLineNumbers
final builder = AdaptyProfileParametersBuilder()
  ..setEmail("email@email.com")
  ..setPhoneNumber("+18888888888")
  ..setFirstName('John')
  ..setLastName('Appleseed')
  ..setGender(AdaptyProfileGender.other)
  ..setBirthday(DateTime(1970, 1, 3));

try {
  await Adapty().updateProfile(builder.build());
} on AdaptyError catch (adaptyError) {
  // handle the error
} catch (e) {
}
```
`updateProfile` メソッドで以前に設定した属性はリセットされないことに注意してください。

:::tip

Adapty SDK がモバイルアプリにどのように統合されているか、実際の例を見てみませんか？ペイウォールの表示、購入処理、その他の基本機能を含む完全なセットアップを実演している[サンプルアプリ](sample-apps)をご覧ください。

:::
### 使用可能なキーの一覧 \{#the-allowed-keys-list\}

`AdaptyProfileParameters.Builder` で使用できるキー `<Key>` と値 `<Value>` の一覧は以下のとおりです。

| キー | 値 |
|---|-----|
| <p>email</p><p>phoneNumber</p><p>firstName</p><p>lastName</p> | String |
| gender | 列挙型。使用できる値: `female`、`male`、`other` |
| birthday | Date |

### カスタムユーザー属性 \{#custom-user-attributes\}

カスタム属性を独自に設定できます。通常はアプリの使用状況に関連するもので、たとえばフィットネスアプリなら週あたりのエクササイズ回数、語学学習アプリならユーザーの習熟度レベルなどが該当します。カスタム属性はセグメントで活用してターゲットを絞ったペイウォールやオファーを作成したり、アナリティクスでどのプロダクト指標が収益に最も影響するかを分析したりするのに役立ちます。
```dart showLineNumbers
try {
  final builder = AdaptyProfileParametersBuilder()
      ..setCustomStringAttribute('value1', 'key1')
      ..setCustomDoubleAttribute(1.0, 'key2');

await Adapty().updateProfile(builder.build());
} on AdaptyError catch (adaptyError) {
// handle the error
} catch (e) {
}
```

既存のキーを削除するには、`.withRemoved(customAttributeForKey:)` メソッドを使用してください：
```dart showLineNumbers
try {
  final builder = AdaptyProfileParametersBuilder()
    ..removeCustomAttribute('key1')
    ..removeCustomAttribute('key2');

await Adapty().updateProfile(builder.build());
} on AdaptyError catch (adaptyError) {
// handle the error
} catch (e) {
}
```

すでに設定されているカスタム属性を確認したい場合は、`AdaptyProfile` オブジェクトの `customAttributes` フィールドを使用してください。
:::warning
`customAttributes` の値は最新でない可能性があることに注意してください。ユーザー属性はいつでも異なるデバイスから送信されるため、最後の同期以降にサーバー上の属性が変更されている場合があります。
:::
### 制限事項 \{#limits\}

- ユーザーあたり最大30件のカスタム属性
- キー名は最大30文字。キー名には英数字と次の文字を使用できます: `_`  `-` `.`
- 値は50文字以内の文字列または浮動小数点数。