Skip to content

ユーザー属性の設定

Braze SDKを通してユーザー属性を設定する方法を学習する。

前提条件

この機能を使用する前に、Android Braze SDKを統合する必要があります。

デフォルトのユーザー属性

定義済みのメソッド

Brazeには、以下のユーザー属性を設定するための定義済みメソッドがある。 BrazeUserクラス内でメソッドの仕様については、KDocを参照のこと。

  • 言語
  • 生年月日
  • メールアドレス
  • 性別
  • 市区町村
  • 電話番号

デフォルト属性の設定

ユーザーにデフォルト属性を設定するには、BrazeインスタンスでgetCurrentUser() メソッドを呼び出し、アプリの現在のユーザーへの参照を取得する。そして、ユーザー属性を設定するメソッドを呼び出すことができる。

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setFirstName("first_name");
  }
}
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setFirstName("first_name")
}

デフォルト属性の設定を解除する

ユーザー属性を解除するには、関連するメソッドにnull

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setFirstName(null);
  }
}
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setFirstName(null)
}

カスタムユーザー属性

デフォルトのユーザー属性に加え、Brazeではいくつかのデータタイプを使用してカスタム属性を定義することができる。各属性のセグメンテーションオプションの詳細については、ユーザーデータ収集を参照のこと。

カスタム属性の設定

string 、カスタム属性を設定する:

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", "your_attribute_value");
  }
}
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", "your_attribute_value")
}

int 、カスタム属性を設定する:

1
2
3
4
5
6
7
8
9
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_INT_VALUE);
    
    // Integer attributes may also be incremented using code like the following:
    brazeUser.incrementCustomUserAttribute("your_attribute_key", YOUR_INCREMENT_VALUE);
  }
}
1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_INT_VALUE)

  // Integer attributes may also be incremented using code like the following:
  brazeUser.incrementCustomUserAttribute("your_attribute_key", YOUR_INCREMENT_VALUE)
}

long 、整数値でカスタム属性を設定する:

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_LONG_VALUE);
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_LONG_VALUE)
}

float 、カスタム属性を設定する:

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_FLOAT_VALUE);
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_FLOAT_VALUE)
}

double 、カスタム属性を設定する:

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DOUBLE_VALUE);
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DOUBLE_VALUE)
}

boolean 、カスタム属性を設定する:

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_BOOLEAN_VALUE);
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_BOOLEAN_VALUE)
}
1
2
3
4
5
6
7
8
9
10
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DATE_VALUE);
    // This method will assign the current time to a custom attribute at the time the method is called:
    brazeUser.setCustomUserAttributeToNow("your_attribute_key");
    // This method will assign the date specified by SECONDS_FROM_EPOCH to a custom attribute:
    brazeUser.setCustomUserAttributeToSecondsFromEpoch("your_attribute_key", SECONDS_FROM_EPOCH);
  }
});
1
2
3
4
5
6
7
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setCustomUserAttribute("your_attribute_key", YOUR_DATE_VALUE)
  // This method will assign the current time to a custom attribute at the time the method is called:
  brazeUser.setCustomUserAttributeToNow("your_attribute_key")
  // This method will assign the date specified by SECONDS_FROM_EPOCH to a custom attribute:
  brazeUser.setCustomUserAttributeToSecondsFromEpoch("your_attribute_key", SECONDS_FROM_EPOCH)
}

カスタム属性配列内の要素の最大数は、25にデフォルト設定されています。個々の配列の最大値は、Braze ダッシュボードの [データ設定] > [カスタム属性] で100まで増やすことができます。要素の最大数を超える配列は、含まれる要素が最大数になるよう切り捨てられます。カスタム属性配列とその動作の詳細については、配列に関するドキュメントを参照してください。

1
2
3
4
5
6
7
8
9
10
11
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    // Setting a custom attribute with an array value
    brazeUser.setCustomAttributeArray("your_attribute_key", testSetArray);
    // Adding to a custom attribute with an array value
    brazeUser.addToCustomAttributeArray("your_attribute_key", "value_to_add");
    // Removing a value from an array type custom attribute
    brazeUser.removeFromCustomAttributeArray("your_attribute_key", "value_to_remove");
  }
});
1
2
3
4
5
6
7
8
Braze.getInstance(context).getCurrentUser { brazeUser ->
  // Setting a custom attribute with an array value
  brazeUser.setCustomAttributeArray("your_attribute_key", testSetArray)
  // Adding to a custom attribute with an array value
  brazeUser.addToCustomAttributeArray("your_attribute_key", "value_to_add")
  // Removing a value from an array type custom attribute
  brazeUser.removeFromCustomAttributeArray("your_attribute_key", "value_to_remove")
}

カスタム属性の設定を解除する

カスタム属性を解除するには、unsetCustomUserAttribute メソッドに関連する属性キーを渡す。

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.unsetCustomUserAttribute("your_attribute_key");
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.unsetCustomUserAttribute("your_attribute_key")
}

階層化カスタム属性

また、カスタム属性の中にプロパティを入れ子にすることもできる。以下の例では、階層化プロパティを持つfavorite_book オブジェクトが、ユーザープロファイルのカスタム属性として設定されている。詳しくは、階層化カスタム属性を参照のこと。

1
2
3
4
5
6
7
8
9
10
11
12
13
JSONObject favoriteBook = new JSONObject();
try {
  favoriteBook.put("title", "The Hobbit");
  favoriteBook.put("author", "J.R.R. Tolkien");
  favoriteBook.put("publishing_date", "1937");
} catch (JSONException e) {
  e.printStackTrace();
}

braze.getCurrentUser(user -> {
  user.setCustomUserAttribute("favorite_book", favoriteBook);
  return null;
});
1
2
3
4
5
6
7
8
val favoriteBook = JSONObject()
  .put("title", "The Hobbit")
  .put("author", "J.R.R. Tolkien")
  .put("publishing_date", "1937")

braze.getCurrentUser { user ->
  user.setCustomUserAttribute("favorite_book", favoriteBook)
}

REST API の使用

また、REST APIを使用して、ユーザー属性を設定または解除することもできる。詳細については、ユーザーデータエンドポイントを参照してください。

ユーザーサブスクリプションの設定

ユーザーのサブスクリプション (メールまたはプッシュ) を設定するには、それぞれ関数 setEmailNotificationSubscriptionType() または setPushNotificationSubscriptionType() を呼び出します。これらの関数では、いずれも引数として列挙型 NotificationSubscriptionType が使用されます。この型には、次の 3 つの状態があります。

メールサブスクリプションの設定

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setEmailNotificationSubscriptionType(emailNotificationSubscriptionType);
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setEmailNotificationSubscriptionType(emailNotificationSubscriptionType)
}

プッシュ通知サブスクリプションの設定

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setPushNotificationSubscriptionType(pushNotificationSubscriptionType);
  }
});
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setPushNotificationSubscriptionType(pushNotificationSubscriptionType)
}

前提条件

この機能を使用する前に、Swift Braze SDKを統合する必要があります。

デフォルトのユーザー属性

サポートされている属性

Braze.User オブジェクトでは、以下の属性を設定する必要があります。

  • firstName
  • lastName
  • email
  • dateOfBirth
  • country
  • language
  • homeCity
  • phone
  • gender

デフォルト属性の設定

デフォルトユーザー属性を設定するには、共有Braze.User オブジェクトの該当フィールドを設定する。以下は名属性の設定例です。

1
AppDelegate.braze?.user.set(firstName: "Alex")
1
[AppDelegate.braze.user setFirstName:@"Alex"];

デフォルト属性の設定を解除する

デフォルトのユーザー属性を解除するには、関連するメソッドにnil

1
AppDelegate.braze?.user.set(firstName: nil)
1
[AppDelegate.braze.user setFirstName:nil];

カスタムユーザー属性

デフォルトのユーザー属性に加え、Brazeではいくつかのデータタイプを使用してカスタム属性を定義することができる。各属性のセグメンテーションオプションの詳細については、ユーザーデータ収集を参照のこと。

カスタム属性の設定

string 、カスタム属性を設定する:

1
AppDelegate.braze?.user.setCustomAttribute(key: "your_attribute_key", value: "your_attribute_value")
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" stringValue:"your_attribute_value"];

integer 、カスタム属性を設定する:

1
AppDelegate.braze?.user.setCustomAttribute(key: "your_attribute_key", value: yourIntegerValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andIntegerValue:yourIntegerValue];

Braze では、データベース内での float 値と double 値の扱いが同じです。カスタム属性に2倍の値を設定する:

1
AppDelegate.braze?.user.setCustomAttribute(key: "your_attribute_key", value: yourDoubleValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andDoubleValue:yourDoubleValue];

boolean 、カスタム属性を設定する:

1
AppDelegate.braze?.user.setCustomAttribute("your_attribute_key", value: yourBoolValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andBOOLValue:yourBOOLValue];

date 、カスタム属性を設定する:

1
AppDelegate.braze?.user.setCustomAttribute("your_attribute_key", dateValue:yourDateValue)
1
[AppDelegate.braze.user setCustomAttributeWithKey:@"your_attribute_key" andDateValue:yourDateValue];

カスタム属性配列内の要素の最大数は、デフォルトで 25 に設定されています。要素の最大数を超える配列は、含まれる要素が最大数になるよう切り捨てられます。個々の配列の最大数は、100 まで増やすことができます。この最大数を増やす必要がある場合は、カスタマーサービスマネージャーに連絡してください。

array 、カスタム属性を設定する:

1
2
3
4
5
6
// Setting a custom attribute with an array value
AppDelegate.braze?.user.setCustomAttributeArray(key: "array_name", array: ["value1",  "value2"])
// Adding to a custom attribute with an array value
AppDelegate.braze?.user.addToCustomAttributeArray(key: "array_name", value: "value3")
// Removing a value from an array type custom attribute
AppDelegate.braze?.user.removeFromCustomAttributeArray(key: "array_name", value: "value2")
1
2
3
4
5
6
7
8
// Setting a custom attribute with an array value
[AppDelegate.braze.user setCustomAttributeArrayWithKey:@"array_name" array:@[@"value1",  @"value2"]];
// Adding to a custom attribute with an array value
[AppDelegate.braze.user addToCustomAttributeArrayWithKey:@"array_name" value:@"value3"];
// Removing a value from an array type custom attribute
[AppDelegate.braze.user removeFromCustomAttributeArrayWithKey:@"array_name" value:@"value2"];
// Removing an entire array and key
[AppDelegate.braze.user setCustomAttributeArrayWithKey:@"array_name" array:nil];

カスタム属性をインクリメントまたはデクリメントする

このコードは、カスタム属性のインクリメントの例です。カスタム属性の値は、integer またはlong

1
AppDelegate.braze?.user.incrementCustomUserAttribute(key: "your_attribute_key", by: incrementIntegerValue)
1
[AppDelegate.braze.user incrementCustomUserAttribute:@"your_attribute_key" by:incrementIntegerValue];

カスタム属性の設定を解除する

カスタム属性を解除するには、unsetCustomAttribute メソッドに関連する属性キーを渡す。

1
AppDelegate.braze?.user.unsetCustomAttribute(key: "your_attribute_key")

カスタム属性を解除するには、unsetCustomAttributeWithKey メソッドに関連する属性キーを渡す。

1
[AppDelegate.braze.user unsetCustomAttributeWithKey:@"your_attribute_key"];

階層化カスタム属性

また、カスタム属性の中にプロパティを入れ子にすることもできる。以下の例では、階層化プロパティを持つfavorite_book オブジェクトが、ユーザープロファイルのカスタム属性として設定されている。詳しくは、階層化カスタム属性を参照のこと。

1
2
3
4
5
6
7
let favoriteBook: [String: Any?] = [
  "title": "The Hobbit",
  "author": "J.R.R. Tolkien",
  "publishing_date": "1937"
]

braze.user.setCustomAttribute(key: "favorite_book", dictionary: favoriteBook)
1
2
3
4
5
6
7
NSDictionary *favoriteBook = @{
  @"title": @"The Hobbit",
  @"author": @"J.R.R. Tolkien",
  @"publishing_date": @"1937"
};

[AppDelegate.braze.user setCustomAttributeWithKey:@"favorite_book" dictionary:favoriteBook];

REST API の使用

また、REST APIを使用して、ユーザー属性を設定または解除することもできる。詳細については、ユーザーデータエンドポイントを参照してください。

ユーザーサブスクリプションの設定

ユーザーのサブスクリプション (メールまたはプッシュ) を設定するには、それぞれ関数 set(emailSubscriptionState:) または set(pushNotificationSubscriptionState:) を呼び出します。これらの関数では、いずれも引数として列挙型 Braze.User.SubscriptionState が使用されます。この型には、次の 3 つの状態があります。

アプリにプッシュ通知の送信を許可するユーザーは、iOS で明示的なオプトインが必要であるため、ステータス optedIn にデフォルト設定されます。

ユーザーは、有効なメールアドレスを取得すると自動的に subscribed に設定されます。ただし、明示的なオプトインのプロセスを確立し、ユーザーから明示的な同意を得た時点でこの値を optedIn に設定することをお勧めします。詳細については、「ユーザーサブスクリプションの管理」を参照してください。

メールサブスクリプションの設定

1
AppDelegate.braze?.user.set(emailSubscriptionState: Braze.User.SubscriptionState)
1
[AppDelegate.braze.user setEmailSubscriptionState: BRZUserSubscriptionState]

プッシュ通知サブスクリプションの設定

1
AppDelegate.braze?.user.set(pushNotificationSubscriptionState: Braze.User.SubscriptionState)
1
[AppDelegate.braze.user setPushNotificationSubscriptionState: BRZUserSubscriptionState]

詳細については、「ユーザーサブスクリプションの管理」を参照してください。

Prerequisites

Before you can use this feature, you’ll need to integrate the Web Braze SDK.

デフォルトのユーザー属性

定義済みのメソッド

Brazeは、Userクラス内で次のユーザー属性を設定するための定義済みメソッドを提供します:

  • 言語
  • 生年月日
  • メールアドレス
  • 性別
  • 市区町村
  • 電話番号

デフォルト属性の設定

ユーザーにデフォルト属性を設定するには、BrazeインスタンスでgetUser() メソッドを呼び出し、アプリの現在のユーザーへの参照を取得する。そして、ユーザー属性を設定するメソッドを呼び出すことができる。

1
braze.getUser().setFirstName("SomeFirstName");
1
braze.getUser().setGender(braze.User.Genders.FEMALE);
1
braze.getUser().setDateOfBirth(2000, 12, 25);

Googleタグマネージャーを使用して、標準ユーザー属性(ユーザーの名など)は、カスタムユーザー属性と同じ方法でログに記録されるべきである。標準属性項目に渡す値が、[ユーザークラス] のドキュメントで指定されている予期される形式と一致していることを確認します。

たとえば、性別属性は、値として次のいずれかを使用できます。"m" | "f" | "o" | "u" | "n" | "p"したがって、ユーザーの性別を女性に設定するには、次の内容のカスタムHTML タグを作成します。

1
2
3
<script>
window.braze.getUser().setGender("f")
</script>

デフォルト属性の設定を解除する

デフォルトのユーザー属性を解除するには、関連するメソッドにnull 。以下に例を示します。

1
braze.getUser().setFirstName(null);
1
braze.getUser().setGender(null);
1
braze.getUser().setDateOfBirth(null, null, null);

カスタムユーザー属性

カスタム属性の設定

デフォルトのユーザー属性に加え、カスタム属性を設定することもできる。完全なメソッドの仕様はJSDocsを参照のこと。

string 、カスタム属性を設定する:

1
2
3
4
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  YOUR_STRING_VALUE
);

integer 、カスタム属性を設定する:

1
2
3
4
5
6
7
8
9
10
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  YOUR_INT_VALUE
);

// Integer attributes may also be incremented using code like the following
braze.getUser().incrementCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  THE_INTEGER_VALUE_BY_WHICH_YOU_WANT_TO_INCREMENT_THE_ATTRIBUTE
);

date 、カスタム属性を設定する:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  YOUR_DATE_VALUE
);

// This method will assign the current time to a custom attribute at the time the method is called
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  new Date()
);

// This method will assign the date specified by secondsFromEpoch to a custom attribute
braze.getUser().setCustomUserAttribute(
  YOUR_ATTRIBUTE_KEY_STRING,
  new Date(secondsFromEpoch * 1000)
);

カスタム属性配列の要素は最大25個まで持つことができる。データ型を手動で設定した(自動検出しない)個々のアレイは、Brazeダッシュボードの「データ設定」>「カスタム属性」で100まで増やすことができる。この上限を増やしたい場合は、Brazeアカウントマネージャーに連絡すること。

配列 が要素数の最大値を超える場合、要素数の最大値に切り詰められます。

array 、カスタム属性を設定する:

1
2
3
4
5
6
7
braze.getUser().setCustomUserAttribute(YOUR_ATTRIBUTE_KEY_STRING, YOUR_ARRAY_OF_STRINGS);

// Adding a new element to a custom attribute with an array value
braze.getUser().addToCustomAttributeArray(YOUR_ATTRIBUTE_KEY_STRING, "new string");

// Removing an element from a custom attribute with an array value
braze.getUser().removeFromCustomAttributeArray(YOUR_ATTRIBUTE_KEY_STRING, "value to be removed");

Googleタグマネージャのスクリプト言語が制限されているため、カスタムユーザー 属性は使用できません。カスタム属性s を記録するには、次の内容でカスタムHTML タグを作成します。

1
2
3
4
5
<script>
  // Note: If using SDK version 3.x or below, use `window.appboy` instead of `window.braze`
  // Version 4 or greater should use `window.braze`
window.braze.getUser().setCustomUserAttribute("attribute name", "attribute value");
</script>

カスタム属性の設定を解除する

カスタム属性を解除するには、関連するメソッドにnull

1
braze.getUser().setCustomUserAttribute(YOUR_ATTRIBUTE_KEY_STRING, null);

階層化カスタム属性

また、カスタム属性の中にプロパティを入れ子にすることもできる。以下の例では、階層化プロパティを持つfavorite_book オブジェクトが、ユーザープロファイルのカスタム属性として設定されている。詳しくは、階層化カスタム属性を参照のこと。

1
2
3
4
5
6
7
8
9
import * as braze from "@braze/web-sdk";

const favoriteBook = {
  title: "The Hobbit",
  author: "J.R.R. Tolkien",
  publishing_date: "1937"
};

braze.getUser().setCustomUserAttribute("favorite_book", favoriteBook);

REST API の使用

また、REST APIを使用して、ユーザー属性を設定または解除することもできる。詳細については、ユーザーデータエンドポイントを参照してください。

ユーザーサブスクリプションの設定

ユーザーのサブスクリプション (メールまたはプッシュ) を設定するには、それぞれ関数 setEmailNotificationSubscriptionType() または setPushNotificationSubscriptionType() を呼び出します。どちらの関数も引数としてenumbraze.User.NotificationSubscriptionTypes を取る。この型には、次の 3 つの状態があります。

ユーザーがプッシュに登録されると、ブラウザは通知を許可するかブロックするかを選択させ、プッシュを許可することを選択した場合、デフォルトでOPTED_INに設定されます。

ユーザーのサブスクリプションの管理を訪れて、サブスクリプションと明示的なオプトインの実装に関する詳細情報をご覧ください。

ユーザーのメール配信停止

1
braze.getUser().setEmailNotificationSubscriptionType(braze.User.NotificationSubscriptionTypes.UNSUBSCRIBED);

ユーザーのプッシュ配信停止

1
braze.getUser().setPushNotificationSubscriptionType(braze.User.NotificationSubscriptionTypes.UNSUBSCRIBED);

前提条件

この機能を使用する前に、Unity Braze SDKを統合する必要があります。

デフォルトのユーザー属性

定義済みのメソッド

Brazeは、BrazeBinding オブジェクトを使用して以下のユーザー属性を設定するための定義済みメソッドを提供する。詳しくはBraze Unity宣言ファイルを参照のこと。

  • ユーザーのメールアドレス
  • 性別
  • 生年月日
  • ユーザー国
  • ユーザーの市区町村
  • ユーザーのメールサブスクリプション
  • ユーザプッシュサブスクリプション
  • ユーザーの電話番号

デフォルト属性の設定

デフォルト属性を設定するには、BrazeBinding オブジェクトの関連メソッドを呼び出す。

1
BrazeBinding.SetUserFirstName("first name");
1
BrazeBinding.SetUserLastName("last name");
1
BrazeBinding.SetUserEmail("[email protected]");
1
BrazeBinding.SetUserGender(Appboy.Models.Gender);
1
BrazeBinding.SetUserDateOfBirth("year(int)", "month(int)", "day(int)");
1
BrazeBinding.SetUserCountry("country name");
1
BrazeBinding.SetUserHomeCity("city name");
1
BrazeBinding.SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType);
1
BrazeBinding.SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType);
1
BrazeBinding.SetUserPhoneNumber("phone number");

デフォルト属性の設定を解除する

デフォルトのユーザー属性を解除するには、関連するメソッドにnull

1
BrazeBinding.SetUserFirstName(null);

カスタムユーザー属性

デフォルトのユーザー属性に加え、Brazeではいくつかのデータタイプを使用してカスタム属性を定義することができる。各属性のセグメンテーションオプションの詳細については、ユーザーデータ収集を参照のこと。

カスタム属性の設定

カスタム属性を設定するには、属性タイプに対応するメソッドを使用する:

1
AppboyBinding.SetCustomUserAttribute("custom string attribute key", "string custom attribute");
1
2
3
4
// Set Integer Attribute
AppboyBinding.SetCustomUserAttribute("custom int attribute key", 'integer value');
// Increment Integer Attribute
AppboyBinding.IncrementCustomUserAttribute("key", increment(int))
1
AppboyBinding.SetCustomUserAttribute("custom double attribute key", 'double value');
1
AppboyBinding.SetCustomUserAttribute("custom boolean attribute key", 'boolean value');
1
AppboyBinding.SetCustomUserAttributeToNow("custom date attribute key");
1
AppboyBinding.SetCustomUserAttributeToSecondsFromEpoch("custom date attribute key", 'integer value');
1
2
3
4
5
6
// Setting An Array
AppboyBinding.SetCustomUserAttributeArray("key", array(List), sizeOfTheArray(int))
// Adding to an Array
AppboyBinding.AddToCustomUserAttributeArray("key", "Attribute")
// Removing an item from an Array
AppboyBinding.RemoveFromCustomUserAttributeArray("key", "Attribute")

カスタム属性の設定を解除する

カスタム属性を解除するには、UnsetCustomUserAttribute メソッドに関連する属性キーを渡す。

1
AppboyBinding.UnsetCustomUserAttribute("custom attribute key");

REST API の使用

また、REST APIを使用して、ユーザー属性を設定または解除することもできる。詳細については、ユーザーデータエンドポイントを参照してください。

ユーザーサブスクリプションの設定

ユーザーにメールまたはプッシュサブスクリプションを設定するには、以下のいずれかの機能を呼び出す。

1
2
3
4
5
// Email notifications
AppboyBinding.SetUserEmailNotificationSubscriptionType()

// Push notifications
AppboyBinding.SetPushNotificationSubscriptionType()`

どちらの関数も引数としてAppboy.Models.AppboyNotificationSubscriptionType 、3つの異なる状態を持つ:

メールサブスクリプションの設定

1
AppboyBinding.SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType.OPTED_IN);

プッシュ通知サブスクリプションの設定

1
AppboyBinding.SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType.OPTED_IN);

デフォルトユーザー属性

サポートされている属性

UBrazeUser オブジェクトでは、以下の属性を設定する必要があります。

  • SetFirstName
  • SetLastName
  • SetEmail
  • SetDateOfBirth
  • SetCountry
  • SetLanguage
  • SetHomeCity
  • SetPhoneNumber
  • SetGender

デフォルト属性の設定

ユーザーにデフォルト属性を設定するには、共有UBrazeUser オブジェクトのGetCurrentUser() メソッドを呼び出し、アプリの現在のユーザーへの参照を取得する。そして、ユーザー属性を設定するメソッドを呼び出すことができる。

1
2
3
4
5
UBraze->GetCurrentUser([](UBrazeUser* BrazeUser) {
    if (BrazeUser) {
        BrazeUser->SetFirstName(TEXT("Alex"));
    }
});

カスタムユーザー属性

デフォルトのユーザー属性に加え、Brazeではいくつかのデータタイプを使用してカスタム属性を定義することができる。各属性のセグメンテーションオプションの詳細については、ユーザーデータ収集を参照のこと。

string 、カスタム属性を設定する:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), TEXT("your_attribute_value"));

integer 、カスタム属性を設定する:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), 42);

Braze では、データベース内での float 値と double 値の扱いが同じです。カスタム属性に2倍の値を設定する:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), 3.14);

boolean 、カスタム属性を設定する:

1
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), true);

date 、カスタム属性を設定する:

1
2
FDateTime YourDateTime = FDateTime(2023, 5, 10);
UBrazeUser->SetCustomUserAttribute(TEXT("your_attribute_key"), YourDateTime);

array 、カスタム属性を設定する:

1
2
3
4
5
6
7
8
9
// Setting a custom attribute with an array value
TArray<FString> Values = {TEXT("value1"), TEXT("value2")};
UBrazeUser->SetCustomAttributeArray(TEXT("array_name"), Values);

// Adding to a custom attribute with an array value
UBrazeUser->AddToCustomAttributeArray(TEXT("array_name"), TEXT("value3"));

// Removing a value from an array type custom attribute
UBrazeUser->RemoveFromCustomAttributeArray(TEXT("array_name"), TEXT("value2"));

ユーザーサブスクリプションの設定

ユーザーにメールまたはプッシュサブスクリプションを設定するには、以下の方法を使用できる。

サブスクリプションの設定

1
2
3
4
5
UBraze->GetCurrentUser([](UBrazeUser* BrazeUser) {
    if (BrazeUser) {
        BrazeUser->SetEmailSubscriptionType(EBrazeSubscriptionType::Subscribed);
    }
});

アトリビューション・データの設定

1
2
3
4
5
UBraze->GetCurrentUser([](UBrazeUser* BrazeUser) {
    if (BrazeUser) {
        BrazeUser->SetPushSubscriptionType(EBrazeSubscriptionType::OptedIn);
    }
});
New Stuff!