important:
This page references our older Objective-C SDK. Check out our new Swift SDK to integrate our latest Swift-first library.
iOS のカスタム属性の設定
Braze には、ユーザーに属性を割り当てるメソッドが用意されています。ダッシュボード上のこれらの属性に従って、ユーザーのフィルター処理とセグメント化を行うことができます。
実装前に、ベストプラクティスのカスタムイベント、カスタム属性、および購入イベントによって提供されるセグメンテーションオプションの例と、イベント命名規則のメモを必ず確認しておいてください。
デフォルトユーザー属性の割り当て
ユーザー属性を割り当てるには、共有 ABKUser
オブジェクトで適切なフィールドを設定する必要があります。
以下は名属性の設定例です。
1
| [Appboy sharedInstance].user.firstName = @"first_name";
|
1
| Appboy.sharedInstance()?.user.firstName = "first_name"
|
ABKUser
オブジェクトでは、以下の属性を設定する必要があります。
firstName
lastName
email
dateOfBirth
country
language
homeCity
phone
userID
gender
カスタムユーザー属性の割り当て
Braze では、デフォルトユーザー属性以外にも、複数の異なるデータ型を使用してカスタム属性を定義できます。これらの各属性で提供されるセグメンテーションオプションの詳細については、ユーザーデータ収集を参照してください。
文字列値のカスタム属性
1
| [[Appboy sharedInstance].user setCustomAttributeWithKey:@"your_attribute_key" andStringValue:"your_attribute_value"];
|
1
| Appboy.sharedInstance()?.user.setCustomAttributeWithKey("your_attribute_key", andStringValue: "your_attribute_value")
|
整数値のカスタム属性
1
| [[Appboy sharedInstance].user setCustomAttributeWithKey:@"your_attribute_key" andIntegerValue:yourIntegerValue];
|
1
| Appboy.sharedInstance()?.user.setCustomAttributeWithKey("your_attribute_key", andIntegerValue: yourIntegerValue)
|
double 値のカスタム属性
Braze では、データベース内での float
値と double
値の扱いが同じです。
1
| [[Appboy sharedInstance].user setCustomAttributeWithKey:@"your_attribute_key" andDoubleValue:yourDoubleValue];
|
1
| Appboy.sharedInstance()?.user.setCustomAttributeWithKey("your_attribute_key", andDoubleValue: yourDoubleValue)
|
ブール値のカスタム属性
1
| [[Appboy sharedInstance].user setCustomAttributeWithKey:@"your_attribute_key" andBOOLValue:yourBOOLValue];
|
1
| Appboy.sharedInstance()?.user.setCustomAttributeWithKey("your_attribute_key", andBOOLValue: yourBoolValue)
|
日付値のカスタム属性
このメソッドで Braze に渡される日付は、ISO 8601 フォーマット (例: 2013-07-16T19:20:30+01:00
) または yyyy-MM-dd'T'HH:mm:ss:SSSZ
フォーマット (2016-12-14T13:32:31.601-0800
) のいずれかである必要があります。
1
| [[Appboy sharedInstance].user setCustomAttributeWithKey:@"your_attribute_key" andDateValue:yourDateValue];
|
1
| Appboy.sharedInstance()?.user.setCustomAttributeWithKey("your_attribute_key", andDateValue:yourDateValue)
|
配列値のカスタム属性
カスタム属性配列内の要素の最大数は、デフォルトで 25 に設定されています。要素の最大数を超える配列は、含まれる要素が最大数になるよう切り捨てられます。個々の配列の最大数は、100 まで増やすことができます。この最大数を増やす必要がある場合は、カスタマーサービスマネージャーに連絡してください。
1
2
3
4
5
6
7
8
| // Setting a custom attribute with an array value
[[Appboy sharedInstance].user setCustomAttributeArrayWithKey:@"array_name" array:@[@"value1", @"value2"]];
// Adding to a custom attribute with an array value
[[Appboy sharedInstance].user addToCustomAttributeArrayWithKey:@"array_name" value:@"value3"];
// Removing a value from an array type custom attribute
[[Appboy sharedInstance].user removeFromCustomAttributeArrayWithKey:@"array_name" value:@"value2"];
// Removing an entire array and key
[[Appboy sharedInstance].user setCustomAttributeArrayWithKey:@"array_name" array:nil];
|
1
2
3
4
5
6
| // Setting a custom attribute with an array value
Appboy.sharedInstance()?.user.setCustomAttributeArrayWithKey("array_name", array: ["value1", "value2"])
// Adding to a custom attribute with an array value
Appboy.sharedInstance()?.user.addToCustomAttributeArrayWithKey("array_name", value: "value3")
// Removing a value from an array type custom attribute
Appboy.sharedInstance()?.user.removeFromCustomAttributeArrayWithKey("array_name", value: "value2")
|
カスタム属性の設定解除
カスタム属性は、次のメソッドを使用して設定を解除することもできます。
1
| [[Appboy sharedInstance].user unsetCustomAttributeWithKey:@"your_attribute_key"];
|
1
| Appboy.sharedInstance()?.user.unsetCustomAttributeWithKey("your_attribute_key")
|
カスタム属性のインクリメント / デクリメント
このコードは、カスタム属性のインクリメントの例です。カスタム属性の値は、正または負の整数か、long 値でインクリメントできます。
1
| [[Appboy sharedInstance].user incrementCustomUserAttribute:@"your_attribute_key" by:incrementIntegerValue];
|
1
| Appboy.sharedInstance()?.user.incrementCustomUserAttribute("your_attribute_key", by: incrementIntegerValue)
|
REST API によるカスタム属性の設定
REST API を使用してユーザー属性を設定することもできます。詳細については、ユーザー API のドキュメントを参照してください。
カスタム属性値の制限
カスタム属性値の最大長は 255 文字です。これより長い値は切り捨てられます。
追加情報
ユーザーサブスクリプションの設定
ユーザーのサブスクリプション (メールまたはプッシュ) を設定するには、それぞれ関数 setEmailNotificationSubscriptionType
または setPushNotificationSubscriptionType
を呼び出します。これらの関数では、いずれも引数として列挙型 ABKNotificationSubscriptionType
が使用されます。この型には、次の 3 つの状態があります。
サブスクリプションステータス |
定義 |
ABKOptedin |
配信登録済み、かつ明示的にオプトイン済み |
ABKSubscribed |
配信登録済みだが、明示的なオプトインは未実行 |
ABKUnsubscribed |
配信停止済みまたは明示的にオプトアウト済み、あるいはその両方 |
アプリにプッシュ通知の送信を許可するユーザーは、iOS で明示的なオプトインが必要であるため、ステータス ABKOptedin
にデフォルト設定されます。
ユーザーは、有効なメールアドレスを取得すると自動的に ABKSubscribed
に設定されます。ただし、明示的なオプトインのプロセスを確立し、ユーザーから明示的な同意を得た時点でこの値を OptedIn
に設定することをお勧めします。詳細については、「ユーザーサブスクリプションの管理」を参照してください。
メールサブスクリプションの設定
1
| [[Appboy sharedInstance].user setEmailNotificationSubscriptionType: ABKNotificationSubscriptionType]
|
1
| Appboy.sharedInstance()?.user.setEmailNotificationSubscriptionType(ABKNotificationSubscriptionType)
|
プッシュ通知サブスクリプションの設定
1
| [[Appboy sharedInstance].user setPushNotificationSubscriptionType: ABKNotificationSubscriptionType]
|
1
| Appboy.sharedInstance()?.user.setPushNotificationSubscriptionType(ABKNotificationSubscriptionType)
|
詳細については、「ユーザーサブスクリプションの管理」を参照してください。