Capacitor SDKでユーザー属性を設定する

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

ユーザー属性の設定

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


const params = {
  email: '[email protected]',
  phoneNumber: '+18888888888',
  firstName: 'John',
  lastName: 'Appleseed',
  gender: 'other',
  birthday: new Date().toISOString(),
};

try {
  await adapty.updateProfile(params);
  console.log('Profile updated successfully');
} catch (error) {
  console.error('Failed to update profile:', error);
}

updateProfile メソッドで以前に設定した属性はリセットされないのでご注意ください。

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

使用可能なキーの一覧

AdaptyProfileParameters で使用可能なキーとその値は以下の通りです:

キー
email文字列
phoneNumber文字列
firstName文字列
lastName文字列
gender列挙型。使用可能な値: 'female''male''other'
birthdayISO形式の日付文字列

カスタムユーザー属性

独自のカスタム属性を設定することもできます。通常、アプリの利用状況に関連するものです。たとえば、フィットネスアプリなら週あたりの運動回数、語学学習アプリならユーザーの習熟度レベルなどが該当します。セグメントに活用してターゲットを絞ったペイウォールやオファーを作成したり、収益に最も影響を与えるプロダクト指標を分析することもできます。


try {
  await adapty.updateProfile({
    codableCustomAttributes: {
      key_1: 'value_1',
      key_2: 2,
    },
  });
  console.log('Custom attributes updated successfully');
} catch (error) {
  console.error('Failed to update custom attributes:', error);
}

既存のキーを削除するには、値として null を渡します:


try {
  // to remove keys, pass null as their values
  await adapty.updateProfile({
    codableCustomAttributes: {
      key_1: null,
      key_2: null,
    },
  });
  console.log('Custom attributes removed successfully');
} catch (error) {
  console.error('Failed to remove custom attributes:', error);
}

事前に設定されているカスタム属性を確認したい場合は、AdaptyProfile オブジェクトの customAttributes フィールドを使用してください。

customAttributes の値は最新でない可能性があります。ユーザー属性は異なるデバイスからいつでも送信される可能性があるため、最後の同期以降にサーバー上の属性が変更されている場合があります。

制限事項

  • ユーザーあたり最大30個のカスタム属性
  • キー名は最大30文字。使用できる文字は英数字と _-. のいずれか
  • 値は文字列または浮動小数点数で、50文字以内