高度なプッシュ通知の例
以下のガイドでは、Braze SDKの高度なプッシュ通知の例をいくつか取り上げている。
前提条件
この機能を使用する前に、Android Braze SDKを統合する必要があります。 プッシュ通知の設定も必要です。
カスタム通知レイアウト
ブレーズ通知はデータメッセージとして送信されます。これは、アプリケーションがバックグラウンドであっても(通知メッセージとは対照的に、アプリがバックグラウンドにあるときにシステムによって自動的に処理される)、常に応答し、それに従って動作を実行する機会があることを意味します。そのため、通知トレイに配信される通知にパーソナライズされた UI 要素を表示するなどして、アプリケーションでエクスペリエンスをカスタマイズできます。この方法でプッシュを実装することに慣れていない方もいるかもしれませんが、Braze でよく知られている機能の 1 つであるプッシュ通知ストーリーは、カスタムビューコンポーネントを使用して魅力的なエクスペリエンスを生み出す機能の良い例です。
Android では、カスタム通知ビューを実装するために使用できるコンポーネントにいくつかの制限があります。通知ビューレイアウトには、RemoteViews フレームワークと互換性のある View オブジェクト_のみ_を含める必要があります。
パーソナライズされたプッシュ通知
プッシュ通知では、カスタムビュー階層内にユーザー固有の情報を表示できます。次の例では、API-trigger を使用してパーソナライズされたプッシュ通知をユーザに送信し、アプリで特定のタスクを完了した後で現在の進行状況を追跡できるようにします。
ダッシュボードでパーソナライズされたプッシュを設定するには、表示する特定のカテゴリを登録し、Liquid を使用して表示したい関連するユーザー属性を設定します。
前提条件
この機能を使用する前に、Swift Braze SDKを統合する必要があります。 You’ll also need to set up push notifications.
This implementation guide is centered around a Swift implementation, but Objective-C snippets are provided for those interested.
Notification content app extensions
Notification content app extensions provide you a great option for push notification customization. Notification content app extensions display a custom interface for your app’s notifications when a push notification is expanded.
Push notifications can be expanded in three different ways:
- A long press on the push banner
- Swiping down on the push banner
- Swiping the banner to the left and selecting “View”
These custom views offer smart ways to engage customers by displaying distinct types of content, including interactive notifications, notifications populated with user data, and even push messages that can capture information like phone numbers and email. One of our well-known features at Braze, Push Stories, are a prime example of what a push notification content app extension can look like!
Requirements
- Push notifications successfully integrated in your app
- The following files generated by Xcode based on your coding language:
Swift
NotificationViewController.swift
MainInterface.storyboard
Objective-C
NotificationViewController.h
NotificationViewController.m
MainInterface.storyboard
Interactive push notification
Push notifications can respond to user actions inside a content app extension. For users running iOS 12 or later, this means you can turn your push notifications into fully interactive messages! This provides an exciting option to introduce interactivity to your promotions and applications. For example, your push notification can include a game for users to play, a spin-to-win wheel for discounts, or a “like” button to save a listing or song.
The following example shows a push notification where users are able to play a match game inside the expanded notification.
Dashboard configuration
To create an interactive push notification, you must set a custom view in your dashboard.
- From the Campaigns page, click Create Campaign to start a new push notification campaign.
- On the Compose tab, toggle on Notification Buttons.
- Enter a custom iOS category in the iOS Notification Category field.
- In the
.plist
of your Notification Content Extension Target, set theUNNotificationExtensionCategory
attribute to your custom iOS category. The value given here must match what is set in the Braze dashboard under iOS Notification Category. - Set the
UNNotificationExtensionInteractionEnabled
key totrue
to enable user interactions in a push notification.
Personalized push notifications
Push notifications can display user-specific information inside a content extension. This allows you to create user-focused push content, such as adding the option to share your progress across different platforms, show unlocked achievements, or display onboarding checklists. This example shows a push notification displayed to a user after they have completed a specific task in the Braze Learning course. By expanding the notification, the user can see their progress through their learning path. The information provided here is user-specific and can be fired off as a session is completed or a specific user action is taken by leveraging an API trigger.
Dashboard configuration
To create a personalized push notification, you must set a custom view in your dashboard.
- From the Campaigns page, click Create Campaign to start a new push notification campaign.
- On the Compose tab, toggle on Notification Buttons.
- Enter a custom iOS category in the iOS Notification Category field.
- In the Settings tab, create key-value pairs using standard Liquid. Set the appropriate user attributes you want the message to show. These views can be personalized based on specific user attributes of a specific user profile.
- In the
.plist
of your Notification Content Extension Target, set theUNNotificationExtensionCategory
attribute to your custom iOS category. The value given here must match what is set in the Braze dashboard under iOS Notification Category.
Handling key-value pairs
The method didReceive
is called when the notification content app extension has received a notification. This method can be found within the NotificationViewController
. The key-value pairs provided in the dashboard are represented in the code through the use of a userInfo
dictionary.
Parsing Key-Value Pairs from Push Notifications
1
2
3
4
5
6
7
8
9
func didReceive(_ notification: UNNotification) {
let userInfo = notification.request.content.userInfo
guard let value = userInfo["YOUR-KEY-VALUE-PAIR"] as? String,
let otherValue = userInfo["YOUR-OTHER-KEY-VALUE-PAIR"] as? String,
else { fatalError("Key-Value Pairs are incorrect.")}
...
}
1
2
3
4
5
6
7
8
9
10
11
- (void)didReceiveNotification:(nonnull UNNotification *)notification {
NSDictionary *userInfo = notification.request.content.userInfo;
if (userInfo[@"YOUR-KEY-VALUE-PAIR"] && userInfo[@"YOUR-OTHER-KEY-VALUE-PAIR"]) {
...
} else {
[NSException raise:NSGenericException format:@"Key-Value Pairs are incorrect"];
}
}
Information capture push notification
Push notifications can capture user information inside a content app extension, pushing the limits of what is possible with a push. Requesting user input through push notifications allows you to not only request basic information like name or email, but also prompt users to submit feedback or complete an unfinished user profile.
For more information, see Logging push notification data.
In the following flow, the custom view is able to respond to state changes. Those state change components are represented in each image.
- User receives a push notification.
- Push is opened. After expanded, the push prompts the user for information. In this example, the user’s email address is requested, but you could request any sort of information.
- Information is provided, and if in the expected format, the registration button is shown.
- Confirmation view is displayed, and push gets dismissed.
Dashboard configuration
To create an information capture push notification, you must set a custom view in your dashboard.
- From the Campaigns page, click Create Campaign to start a new push notification campaign.
- On the Compose tab, toggle on Notification Buttons.
- Enter a custom iOS category in the iOS Notification Category field.
- In the Settings tab, create key-value pairs using standard Liquid. Set the appropriate user attributes you want the message to show.
- In the
.plist
of your Notification Content Extension Target, set theUNNotificationExtensionCategory
attribute to your custom iOS category. The value given here must match what is set in the Braze dashboard under iOS Notification Category.
As seen in the example, you may also include an image in your push notification. To do this, you must integrate rich notifications, set the notification style in your campaign to Rich Notification, and include a rich push image.
Handling button actions
Each action button is uniquely identified. The code checks if your response identifier is equal to the actionIndentifier
, and if so, knows that the user clicked the action button.
Handling Push Notification Action Button Responses
1
2
3
4
5
6
7
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
if response.actionIdentifier == "YOUR-REGISTER-IDENTIFIER" {
// do something
} else {
// do something else
}
}
1
2
3
4
5
6
7
- (void)didReceiveNotificationResponse:(UNNotificationResponse *)response completionHandler:(void (^)(UNNotificationContentExtensionResponseOption))completion {
if ([response.actionIdentifier isEqualToString:@"YOUR-REGISTER-IDENTIFIER"]) {
completion(UNNotificationContentExtensionResponseOptionDismiss);
} else {
completion(UNNotificationContentExtensionResponseOptionDoNotDismiss);
}
}
Dismissing pushes
Push notifications can be automatically dismissed from an action button press. There are three pre-built push dismissal options that we recommend:
completion(.dismiss)
- Dismisses the notificationcompletion(.doNotDismiss)
- Notification stays opencompletion(.dismissAndForward)
- Push dismisses and the user gets forwarded into the application