バナー配置を管理する
Braze SDKでバナー配置の作成と管理方法を学びます。配置固有のプロパティへのアクセスやインプレッションの記録についても説明します。一般的な情報については、バナーについてを参照してください。
配置リクエストについて
アプリやWeb サイトで配置を作成すると、アプリは各配置に対応するバナーメッセージを取得するため、Brazeにリクエストを送信する。
- 1回の更新リクエストにつき、最大10件の配置をリクエストできる。
- 各配置において、Brazeはユーザーが受け取る資格のある最高優先度のバナーを返す。
- リフレッシュ時に10件を超える配置が要求された場合、最初の10件のみが返され、残りは破棄される。
例えば、アプリがリフレッシュリクエストで3つの配置を要求する場合がある: homepage_promo, cart_abandonment, および seasonal_offer。各リクエストは、その配置に対して最も関連性の高いバナーを返す。
更新リクエストのレート制限
古いSDKバージョン(SWIFT 13.1.0以前、Android 38.0.0以前、Web 6.1.0以前、React Native 17.0.0以前、Flutter 15.0.0以前)を使用している場合、ユーザーセッションごとにリフレッシュリクエストは1回のみ許可される。
新しい最小SDKバージョン(SWIFT 13.1.0以上、Android 38.0.0以上、Web 6.1.0以上、React Native 17.0.0以上、Flutter 15.0.0以上)を使用している場合、リフレッシュリクエストは過剰なポーリングを防ぐためトークンバケットアルゴリズムでコントロールされる:
- 各ユーザーセッションは、5つのリフレッシュトークンから始まる。
- トークンは180秒(3分)ごとに1個補充される。
各呼び出しはトークンをrequestBannersRefresh一つ消費する。トークンが利用できない状態で更新を試みると、SDKはリクエストを送信せず、トークンが補充されるまでエラーをログに記録する。これはセッション途中やトリガー発生時の更新において重要だ。ダイナミックな更新を実装する場合(例えば、ユーザーが同じページでアクションを完了した後など)、カスタムイベントが記録された後にリフレッシュメソッドを呼び出す。ただし、ユーザーが別のバナーキャンペーンの対象となる前に、Brazeがイベントを取り込んで処理するのに必要な遅延に注意すること。
配置を作成する
前提条件
バナー配置を作成するために必要な最小SDKバージョンは以下の通りです。
ステップ 1: Braze での配置の作成
まだ作成していない場合は、アプリまたはサイトでバナーを表示できる場所を定義するために使用するバナーの配置をBrazeで作成する必要があります。配置を作成するには、Settings > Banners Placementsに移動し、配置の作成を選択します。

配置に名前を付け、配置ID を割り当てます。ID はカードのライフサイクル全体で使用されるため、後で変更しないでください。ID を割り当てる前に、他のチームに相談してください。詳細については、配置IDを参照してください。

ステップ2:アプリの配置を更新する
配置は、以下に説明する更新メソッドを呼び出すことで更新できます。これらの配置は、ユーザーのセッションが期限切れになったとき、またはchangeUserメソッドを使用して識別済みユーザーを変更したときに自動的にキャッシュされます。
ヒント
バナーのダウンロードや表示の遅延を避けるため、できるだけ早く配置を更新してください。
1
2
3
| import * as braze from "@braze/web-sdk";
braze.requestBannersRefresh(["global_banner", "navigation_square_banner"]);
|
1
| AppDelegate.braze?.banners.requestRefresh(placementIds: ["global_banner", "navigation_square_banner"])
|
1
2
3
4
| ArrayList<String> listOfBanners = new ArrayList<>();
listOfBanners.add("global_banner");
listOfBanners.add("navigation_square_banner");
Braze.getInstance(context).requestBannersRefresh(listOfBanners);
|
1
| Braze.getInstance(context).requestBannersRefresh(listOf("global_banner", "navigation_square_banner"))
|
1
| Braze.requestBannersRefresh(["global_banner", "navigation_square_banner"]);
|
1
| This feature is not currently supported on Unity.
|
1
| This feature is not currently supported on Cordova.
|
1
| braze.requestBannersRefresh(["global_banner", "navigation_square_banner"]);
|
1
| This feature is not currently supported on Roku.
|
ステップ3:更新をリッスンする
ヒント
このガイドのSDKメソッドを使ってバナーを挿入する場合、すべての分析イベント(インプレッションやクリックなど)は自動的に処理され、インプレッションはバナーが表示されているときのみ記録されます。
Web Braze SDKでvanilla JavaScriptを使用している場合、subscribeToBannersUpdatesを使って配置の更新をリッスンし、requestBannersRefreshを呼び出してフェッチします。
1
2
3
4
5
6
7
8
| import * as braze from "@braze/web-sdk";
braze.subscribeToBannersUpdates((banners) => {
console.log("Banners were updated");
});
// always refresh after your subscriber function has been registered
braze.requestBannersRefresh(["global_banner", "navigation_square_banner"]);
|
Web Braze SDKでReactを使用している場合、useEffectフック内でsubscribeToBannersUpdatesを設定し、リスナーを登録した後にrequestBannersRefreshを呼び出します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| import * as braze from "@braze/web-sdk";
useEffect(() => {
const subscriptionId = braze.subscribeToBannersUpdates((banners) => {
console.log("Banners were updated");
});
// always refresh after your subscriber function has been registered
braze.requestBannersRefresh(["global_banner", "navigation_square_banner"]);
// cleanup listeners
return () => {
braze.removeSubscription(subscriptionId);
}
}, []);
|
1
2
3
4
5
| let cancellable = brazeClient.braze()?.banners.subscribeToUpdates { banners in
banners.forEach { placementId, banner in
print("Received banner: \(banner) with placement ID: \(placementId)")
}
}
|
1
2
3
4
5
| Braze.getInstance(context).subscribeToBannersUpdates(banners -> {
for (Banner banner : banners.getBanners()) {
Log.d(TAG, "Received banner: " + banner.getPlacementId());
}
});
|
1
2
3
4
5
| Braze.getInstance(context).subscribeToBannersUpdates { update ->
for (banner in update.banners) {
Log.d(TAG, "Received banner: " + banner.placementId)
}
}
|
1
2
3
4
5
6
7
8
9
10
| const bannerCardsSubscription = Braze.addListener(
Braze.Events.BANNER_CARDS_UPDATED,
(data) => {
const banners = data.banners;
console.log(
`Received ${banners.length} Banner Cards with placement IDs:`,
banners.map((banner) => banner.placementId)
);
}
);
|
1
| This feature is not currently supported on Unity.
|
1
| This feature is not currently supported on Cordova.
|
1
2
3
4
5
| StreamSubscription bannerStreamSubscription = braze.subscribeToBanners((List<BrazeBanner> banners) {
for (final banner in banners) {
print("Received banner: " + banner.toString());
}
});
|
1
| This feature is not currently supported on Roku.
|
ステップ4:配置IDを使って挿入する
バナーのコンテナ要素を作成します。幅と高さを必ず設定してください。
1
| <div id="global-banner-container" style="width: 100%; height: 450px;"></div>
|
Web Braze SDKでvanilla JavaScriptを使用している場合、insertBannerメソッドを呼び出してコンテナ要素の内部HTMLを置き換えます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| import * as braze from "@braze/web-sdk";
braze.initialize("sdk-api-key", {
baseUrl: "sdk-base-url",
allowUserSuppliedJavascript: true, // banners require you to opt-in to user-supplied javascript
});
braze.subscribeToBannersUpdates((banners) => {
// get this placement's banner. If it's `null` the user did not qualify for one.
const globalBanner = braze.getBanner("global_banner");
if (!globalBanner) {
return;
}
// choose where in the DOM you want to insert the banner HTML
const container = document.getElementById("global-banner-container");
// Insert the banner which replaces the innerHTML of that container
braze.insertBanner(globalBanner, container);
// Special handling if the user is part of a Control Variant
if (globalBanner.isControl) {
// hide or collapse the container
container.style.display = "none";
}
});
braze.requestBannersRefresh(["global_banner", "navigation_square_banner"]);
|
Web Braze SDKでReactを使用している場合、insertBannerメソッドをrefと共に呼び出してコンテナ要素の内部HTMLを置き換えます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| import { useRef } from 'react';
import * as braze from "@braze/web-sdk";
export default function App() {
const bannerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const globalBanner = braze.getBanner("global_banner");
if (!globalBanner || globalBanner.isControl) {
// hide the container
} else {
// insert the banner to the container node
braze.insertBanner(globalBanner, bannerRef.current);
}
}, []);
return <div ref={bannerRef}></div>
}
|
ヒント
インプレッションをトラッキングするには、isControlの場合でも必ずinsertBannerを呼び出してください。その後、コンテナを非表示にしたり折りたたんだりできます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| // To get access to the Banner model object:
let globalBanner: Braze.Banner?
AppDelegate.braze?.banners.getBanner(for: "global_banner", { banner in
self.globalBanner = banner
})
// UIKit implementation:
// If you simply want the Banner view, initialize a `UIView` with the placement ID:
if let braze = AppDelegate.braze {
let bannerUIView = BrazeBannerUI.BannerUIView(
placementId: "global_banner",
braze: braze,
// iOS does not perform automatic resizing or visibility changes.
// Use the `processContentUpdates` parameter to adjust the size and visibility of your Banner according to your use case.
processContentUpdates: { result in
switch result {
case .success(let updates):
if let height = updates.height {
// Adjust the visibility and/or height.
}
case .failure(let error):
// Handle the error.
}
}
)
}
// SwiftUI implementation:
// Similarly, if you want a Banner view in SwiftUI, use the corresponding `BannerView` initializer:
if let braze = AppDelegate.braze {
let bannerView = BrazeBannerUI.BannerView(
placementId: "global_banner",
braze: braze,
// iOS does not perform automatic resizing or visibility changes.
// Use the `processContentUpdates` parameter to adjust the size and visibility of your Banner according to your use case.
processContentUpdates: { result in
switch result {
case .success(let updates):
if let height = updates.height {
// Adjust the visibility and/or height according to your parent controller.
}
case .failure(let error):
// Handle the error.
}
}
)
}
|
Javaコードでバナーを取得するには、以下を使用します。
1
| Banner globalBanner = Braze.getInstance(context).getBanner("global_banner");
|
次のXMLを含めることで、Androidビューレイアウトでバナーを作成できます。
1
2
3
4
5
| <com.braze.ui.banners.BannerView
android:id="@+id/global_banner_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:placementId="global_banner" />
|
Androidビューを使用している場合は、次のXMLを使用します。
1
2
3
4
5
| <com.braze.ui.banners.BannerView
android:id="@+id/global_banner_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:placementId="global_banner" />
|
Jetpack Composeを使用している場合は、次を使用できます。
1
| Banner(placementId = "global_banner")
|
Kotlinでバナーを取得するには、以下を使用します。
1
| val banner = Braze.getInstance(context).getBanner("global_banner")
|
React Nativeの新しいアーキテクチャを使用している場合は、BrazeBannerViewをFabricコンポーネントとしてAppDelegate.mmに登録する必要があります。
1
2
3
4
5
6
7
8
| #ifdef RCT_NEW_ARCH_ENABLED
/// Register the `BrazeBannerView` for use as a Fabric component.
- (NSDictionary<NSString *,Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents {
NSMutableDictionary * dictionary = [super thirdPartyFabricComponents].mutableCopy;
dictionary[@"BrazeBannerView"] = [BrazeBannerView class];
return dictionary;
}
#endif
|
最もシンプルな統合方法として、以下のJavaScript XML(JSX)スニペットをビュー階層に追加し、配置IDだけを指定します。
1
2
3
| <Braze.BrazeBannerView
placementID='global_banner'
/>
|
React Nativeでバナーのデータモデルを取得したり、ユーザーのキャッシュにその配置が存在するかどうかを確認するには、以下を使用します。
1
| const banner = await Braze.getBanner("global_banner");
|
1
| This feature is not currently supported on Unity.
|
1
| This feature is not currently supported on Cordova.
|
最もシンプルな統合方法として、以下のウィジェットをビュー階層に追加し、配置IDだけを指定します。
1
2
3
4
| BrazeBannerView(
placementId: "global_banner",
),
To get the Banner's data model in Flutter, use:
|
getBannerメソッドを使って、ユーザーのキャッシュにその配置が存在するかどうかを確認できます。
1
2
3
4
5
6
7
| braze.getBanner("global_banner").then((banner) {
if (banner == null) {
// Handle null cases.
} else {
print(banner.toString());
}
});
|
1
| This feature is not currently supported on Roku.
|
ステップ5:テストバナーを送信する(オプション)
バナーCampaignを開始する前に、テストバナーを送信して統合を確認できます。テストバナーは別のインメモリキャッシュに保存され、アプリの再起動後は保持されません。追加のセットアップは不要ですが、テストを表示できるようにテストデバイスがフォアグラウンドのプッシュ通知を受信できる必要があります。
注
テストバナーは他のバナーと同じですが、次のアプリセッションで削除される点が異なります。
インプレッションを記録する
Brazeは、SDKメソッドを使ってバナーを挿入する際に、表示されているバナーのインプレッションを自動的に記録します。そのため、インプレッションを手動でトラッキングする必要はありません。
クリックを記録する
バナーのクリックを記録するために使用するメソッドは、バナーのレンダリング方法とクリックハンドラーの配置場所によって異なります。
標準バナーコンテンツ(自動)
デフォルトの標準SDKメソッドを使ってバナーを挿入しており、バナーが標準のエディターコンポーネント(画像、ボタン、テキスト)を使用している場合、クリックは自動的にトラッキングされます。SDKがこれらの要素にクリックリスナーをアタッチするため、追加のコードは不要です。
カスタムコードブロック
バナーがBrazeダッシュボードのカスタムコードエディターブロックを使用している場合、そのカスタムHTML内からクリックを記録するにはbrazeBridge.logClick()を使用する必要があります。これは、SDKメソッドを使ってバナーをレンダリングする場合でも同様です。SDKはカスタムコード内の要素にリスナーを自動的にアタッチできないためです。
1
2
3
| <button onclick="brazeBridge.logClick()">
Click me
</button>
|
完全なリファレンスについては、バナー用のカスタムコードとJavaScriptブリッジを参照してください。brazeBridgeは、バナーの内部HTMLと親Braze SDKの間の通信レイヤーを提供します。
カスタムUI実装(ヘッドレス)
バナーのHTMLをレンダリングする代わりに、バナーのカスタムプロパティを使って完全にカスタムのUIを構築する場合、アプリケーションコードからクリックとインプレッションを手動で記録する必要があります。SDKがバナーをレンダリングしていないため、カスタムUI要素とのインタラクションを自動的にトラッキングする方法がありません。
メソッドシグネチャと詳細については、Braze SDKリファレンスドキュメントを参照してください。
インプレッションを記録する
カスタムUIがバナーを「閲覧済み」と見なしたときに、プラットフォームのバナーインプレッションメソッドを呼び出します。重複イベントを避けるために、インプレッションとしてカウントする条件について堅牢なロジックを構築してください。たとえば、バナーがビューポートに入ったとき(または同等のタイミング)にのみ記録し、同じバナーがスクロールで再び表示されたときやコンポーネントが新しいビューイベントなしに再レンダリングされたときには再度記録しないようにします。
1
2
3
4
5
6
7
| import * as braze from "@braze/web-sdk";
// Log impression when your custom UI considers the banner viewed (for example, once when it enters viewport)
const banner = braze.getBanner("placement_id_homepage_top");
if (banner) {
braze.logBannerImpressions([banner]);
}
|
Web SDKリファレンス
1
2
| // Log impression when your custom UI considers the banner viewed (for example, once when it enters viewport)
Braze.getInstance(context).logBannerImpression("placement_id_homepage_top")
|
1
2
| // Log impression when your custom UI considers the banner viewed (for example, once when it enters viewport)
Braze.getInstance(context).logBannerImpression("placement_id_homepage_top");
|
Android SDKリファレンス
1
2
3
4
| // Retrieve a banner and log an impression on it (for example, once when it enters viewport)
braze.banners.getBanner(for: "placement_id_homepage_top") { banner in
banner?.context.logImpression()
}
|
Swift SDKリファレンス
1
2
| // Log impression when your custom UI considers the banner viewed (for example, once when it enters viewport)
Braze.logBannerImpression("placement_id_homepage_top");
|
最新のメソッドシグネチャについては、React Native SDKリポジトリを参照してください。
1
2
| // Log impression when your custom UI considers the banner viewed (for example, once when it enters viewport)
braze.logBannerImpression("placement_id_homepage_top");
|
Flutter SDKリファレンス
クリックを記録する
ユーザーがカスタムバナー(または特定のボタン)をタップしたときに、プラットフォームのバナークリックメソッドを呼び出します。クリックが特定のボタンに対するものである場合は、オプションのbuttonIdを渡して、分析がクリックを正しく帰属できるようにします。
1
2
3
4
| import * as braze from "@braze/web-sdk";
// Log click
braze.logBannerClick("placement_id_homepage_top", buttonId); // buttonID is optional
|
Web SDKリファレンス
1
2
| // Log click
Braze.getInstance(context).logBannerClick("placement_id_homepage_top", buttonId) // buttonID parameter can be null
|
1
2
| // Log click
Braze.getInstance(context).logBannerClick("placement_id_homepage_top", buttonId); // buttonID parameter can be null
|
Android SDKリファレンス
1
2
3
4
| // Retrieve a banner and log a click on it
braze.banners.getBanner(for: "placement_id_homepage_top") { banner in
banner?.context.logClick(buttonId: buttonId) // buttonID is optional
}
|
Swift SDKリファレンス
1
2
| // Log click
Braze.logBannerClick("placement_id_homepage_top", buttonId); // buttonID is optional
|
最新のメソッドシグネチャについては、React Native SDKリポジトリを参照してください。
1
2
| // Log click
braze.logBannerClicked("placement_id_homepage_top", buttonId); // buttonID parameter can be null
|
Flutter SDKリファレンス
非表示を記録する
バナーの非表示は、ユーザーが能動的にバナーを閉じたときに、プログラムで配置からバナーを削除します。一度非表示にすると、そのユーザーに対してバナーは抑制されます。次に配置リストが更新されたとき、ユーザーが対象であれば新しいバナーが返されます。
重要
バナーの非表示は現在、早期アクセス段階です。早期アクセスへの参加に興味がある場合は、カスタマーサクセスマネージャーにお問い合わせください。
前提条件
バナーの非表示を記録するために必要な最小SDKバージョンは以下の通りです。
統合
標準バナー統合(ドラッグ&ドロップエディター)
バナーがドラッグ&ドロップエディターを使用しており、非表示ボタンコンポーネントが含まれている場合、追加のコードは不要です。ユーザーが非表示ボタンをクリックすると、メッセージが非表示になり、非表示がトリガーされ、分析用の非表示イベントが記録されます。
カスタムコードブロック
バナーがカスタムコードエディターブロックを使用している場合、バナーのHTML内からbrazeBridge.closeMessage()を使って直接非表示をトリガーできます。
1
2
3
| <button onclick="brazeBridge.closeMessage()">
Dismiss
</button>
|
バナー非表示時にカスタム分析を記録する
バナーの非表示時にカスタム分析の記録などの追加ロジックを実行するには、バナービューのオプションのonDismissコールバックをオーバーライドします。デフォルトでは、このコールバックは空です。
BannerViewのオプションのonDismissCallbackプロパティを設定します。
1
2
3
4
5
6
7
8
9
10
11
12
| import android.util.Log;
import com.braze.ui.banners.BannerView;
import kotlin.Unit;
// After obtaining your BannerView instance (for example from XML via findViewById, or `new BannerView(context, "global_banner")`)
bannerView.setOnDismissCallback(() -> {
Log.d(TAG, "Successfully dismissed banner with placementId: " + bannerView.getPlacementId());
// Run any custom logic here, such as logging custom analytics
return Unit.INSTANCE;
});
|
1
2
3
4
5
6
7
8
9
10
| import android.util.Log
import com.braze.ui.banners.BannerView
// After obtaining your BannerView instance (for example via findViewById or `BannerView(context, "global_banner")`)
bannerView.onDismissCallback = {
Log.d(TAG, "Successfully dismissed banner with placementId: ${bannerView.placementId}")
// Run any custom logic here, such as logging custom analytics
}
|
1
2
3
4
5
6
7
| // After initializing your banner view instance using UIKit or SwiftUI
bannerView.onDismiss = { dismissedBanner in
print("Successfully dismissed banner with placementId: \(dismissedBanner.placementId)")
// Run any custom logic here, such as logging custom analytics
}
|
保留中の非表示のストレージ上限
非表示イベントは、次のrequestBannersRefresh呼び出し時にBrazeサーバーに同期されるまで、保留中のエントリとしてローカルに保存されます。
警告
まれに、同期が成功しないまま大量の非表示が蓄積された場合、古い保留中の非表示が削除されることがあります。この場合、以前に非表示にしたバナーが次の同期が成功するまで再表示される可能性があります。このリスクを最小限に抑えるには、アプリがネットワーク接続を回復するたびにrequestBannersRefreshを呼び出してください。
サイズと寸法
バナーのサイズと寸法について知っておくべきことは以下の通りです。
- コンポーザーではさまざまなサイズでバナーをプレビューできますが、その情報は保存されず、SDKに送信されません。
- HTMLは、レンダリングされるコンテナの全幅を使用します。
- 固定サイズの要素を作成し、そのサイズをコンポーザーでテストすることをお勧めします。
カスタムプロパティ
バナーCampaignのカスタムプロパティを使って、SDKを通じてキーと値のデータを取得し、アプリの動作や外観を変更できます。たとえば、以下のようなことが可能です。
- サードパーティの分析ツールや統合サービス向けにメタデータを送信する。
timestampやJSONオブジェクトなどのメタデータを使って条件分岐ロジックをトリガーする。
ratioやformatなどのメタデータに基づいてバナーの動作をコントロールする。
前提条件
バナーCampaignにカスタムプロパティを追加する必要があります。さらに、カスタムプロパティにアクセスするために必要な最小SDKバージョンは以下の通りです。
カスタムプロパティにアクセスする
バナーのカスタムプロパティにアクセスするには、ダッシュボードで定義されたプロパティの型に基づいて、以下のいずれかのメソッドを使用します。キーがその型のプロパティと一致しない場合、またはキーが存在しない場合、メソッドはnullを返します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| // Returns the Banner instance
const banner = braze.getBanner("placement_id_homepage_top");
// banner may be undefined or null
if (banner) {
// Returns the string property
const stringProperty = banner.getStringProperty("color");
// Returns the boolean property
const booleanProperty = banner.getBooleanProperty("expanded");
// Returns the number property
const numberProperty = banner.getNumberProperty("height");
// Returns the timestamp property (as a number)
const timestampProperty = banner.getTimestampProperty("account_start");
// Returns the image URL property as a string of the URL
const imageProperty = banner.getImageProperty("homepage_icon");
// Returns the JSON object property
const jsonObjectProperty = banner.getJsonProperty("footer_settings");
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| // Passes the specified banner to the completion handler
AppDelegate.braze?.banners.getBanner(for: "placement_id_homepage_top") { banner in
// Returns the string property
let stringProperty: String? = banner.stringProperty(key: "color")
// Returns the boolean property
let booleanProperty: Bool? = banner.boolProperty(key: "expanded")
// Returns the number property as a double
let numberProperty: Double? = banner.numberProperty(key: "height")
// Returns the Unix UTC millisecond timestamp property as an integer
let timestampProperty: Int? = banner.timestampProperty(key: "account_start")
// Returns the image property as a String of the image URL
let imageProperty: String? = banner.imageProperty(key: "homepage_icon")
// Returns the JSON object property as a [String: Any] dictionary
let jsonObjectProperty: [String: Any]? = banner.jsonObjectProperty(key: "footer_settings")
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| // Returns the Banner instance
Banner banner = Braze.getInstance(context).getBanner("placement_id_homepage_top");
// banner may be undefined or null
if (banner != null) {
// Returns the string property
String stringProperty = banner.getStringProperty("color");
// Returns the boolean property
Boolean booleanProperty = banner.getBooleanProperty("expanded");
// Returns the number property
Number numberProperty = banner.getNumberProperty("height");
// Returns the timestamp property (as a Long)
Long timestampProperty = banner.getTimestampProperty("account_start");
// Returns the image URL property as a String of the URL
String imageProperty = banner.getImageProperty("homepage_icon");
// Returns the JSON object property as a JSONObject
JSONObject jsonObjectProperty = banner.getJSONProperty("footer_settings");
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| // Returns the Banner instance
val banner: Banner = Braze.getInstance(context).getBanner("placement_id_homepage_top") ?: return
// Returns the string property
val stringProperty: String? = banner.getStringProperty("color")
// Returns the boolean property
val booleanProperty: Boolean? = banner.getBooleanProperty("expanded")
// Returns the number property
val numberProperty: Number? = banner.getNumberProperty("height")
// Returns the timestamp property (as a Long)
val timestampProperty: Long? = banner.getTimestampProperty("account_start")
// Returns the image URL property as a String of the URL
val imageProperty: String? = banner.getImageProperty("homepage_icon")
// Returns the JSON object property as a JSONObject
val jsonObjectProperty: JSONObject? = banner.getJSONProperty("footer_settings")
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| // Get the Banner instance
const banner = await Braze.getBanner('placement_id_homepage_top');
if (!banner) return;
// Get the string property
const stringProperty = banner.getStringProperty('color');
// Get the boolean property
const booleanProperty = banner.getBooleanProperty('expanded');
// Get the number property
const numberProperty = banner.getNumberProperty('height');
// Get the timestamp property (as a number)
const timestampProperty = banner.getTimestampProperty('account_start');
// Get the image URL property as a string
const imageProperty = banner.getImageProperty('homepage_icon');
// Get the JSON object property
const jsonObjectProperty = banner.getJSONProperty('footer_settings');
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| // Fetch the banner asynchronously
_braze.getBanner(placementId).then(('placement_id_homepage_top') {
// Get the string property
final String? stringProperty = banner?.getStringProperty('color');
// Get the boolean property
final bool? booleanProperty = banner?.getBooleanProperty('expanded');
// Get the number property
final num? numberProperty = banner?.getNumberProperty('height');
// Get the timestamp property
final int? timestampProperty = banner?.getTimestampProperty('account_start');
// Get the image URL property
final String? imageProperty = banner?.getImageProperty('homepage_icon');
// Get the JSON object property
final Map<String, dynamic>? jsonObjectProperty = banner?.getJSONProperty('footer_settings');
// Use these properties as needed in your UI or logic
});
|