バナー用のカスタムコードとJavaScriptブリッジ
バナーコンポーザーでカスタムコードエディターブロックを使用する場合、クリックをログに記録するには、カスタムHTML内から``を
brazeBridge.logClick()呼び出す必要がある。バナーはHTMLアプリ内メッセージと同じJavaScriptブリッジを使用するため、同じメソッドとパターンが適用される。
バナーデザインでカスタムHTMLを使用する場合、Braze SDKはカスタムコード内の要素に自動的にクリックリスナーを添付できない。キャンペーン分析でトラッキングしたいクリック可能な要素(リンク、ボタンなど)については、明示的にbrazeBridge.logClick()呼び出す必要がある。
例えば、カスタムHTML内のボタンをユーザーがタップした際にクリックを記録するには:
1
2
3
<button onclick="brazeBridge.logClick()">
Click me
</button>
利用可能な全メソッドとクリックトラッキングオプションを含む、完全なJavaScriptブリッジリファレンスは以下のセクションを参照のこと。
JavaScriptブリッジ
Custom HTML in-app messages and Banners support a JavaScript “bridge” to interface with the Braze SDK, allowing you to trigger custom Braze actions when users click on elements with links or otherwise engage with your content. These methods exist with the global brazeBridge or appboyBridge variable.
Braze recommends that you use the global brazeBridge variable. The global appboyBridge variable is deprecated but will continue to function for existing users. If you are using appboyBridge, we suggest you migrate to brazeBridge.
appboyBridge was deprecated in the following SDK versions:
For example, to log a custom attribute and custom event, then close the message, you could use the following JavaScript within your custom HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<button id="button">Set Favorite Color</button>
<script>
// Wait for the `brazeBridge` ready event, "ab.BridgeReady"
window.addEventListener("ab.BridgeReady", function(){
// Event handler when the button is clicked
document.querySelector("#button").onclick = function(){
// Track Button 1 clicks for analytics
// Note: This requires Android SDK v8.0.0, Web SDK v2.5.0, Swift SDK v5.4.0, and iOS SDK v3.23.0
brazeBridge.logClick("0");
// Set the user's custom attribute
brazeBridge.getUser().setCustomUserAttribute("favorite color", "blue");
// Track a custom event
brazeBridge.logCustomEvent("completed survey");
// Send the enqueued data to Braze
brazeBridge.requestImmediateDataFlush();
// Close the message
brazeBridge.closeMessage();
};
}, false);
</script>
JavaScript Bridge methods
The following JavaScript methods are supported within custom HTML for in-app messages and Banners:
You cannot reference Liquid to insert customAttributes into JavaScript Bridge methods.
| メソッド名 | 説明 |
|---|---|
brazeBridge.closeMessage() |
現在のアプリ内メッセージを閉じる。アプリ内メッセージがすでに終了処理中であるか、ディープリンクの処理によって自動的に終了する場合は、このメソッドをコールしないこと。 |
window.addEventListener("ab.BridgeReady", function(){...}, false) |
brazeBridge の読み込みが終了したときのコールバックメソッド。すべてのJavaScriptコードは、このコールバック関数の中で実行されなければならない。 |
brazeBridge.requestImmediateDataFlush() |
Brazeサーバーにキューイングされたデータをフラッシュする。JS ドキュメント |
brazeBridge.logClick(button_id_string) |
指定されたボタンIDのボタンクリックを記録する。button_id_string が空白のままだと、ボディクリックが代わりに記録される。button_id_string は、アプリ内メッセージのクリックイベントで Currents を介して button_id として渡すことができます。このメソッドは Android SDK v8.0.0、Web SDK v2.5.0、iOS SDK v3.23.0 で導入されました。 button_id_string には、英数字、スペース、ダッシュ、アンダースコアのみを使用できます。アクセントのある文字(例えば、ö,â,ê)を追加すると、ボタンのクリック追跡ができなくなり、その結果、ボタンの文字列がキャンペーン分析セクションに表示されなくなり、クリック数が計算されなくなる。 |
brazeBridge.logCustomEvent(eventName,eventProperties) |
カスタムイベントを記録する。JS ドキュメント |
brazeBridge.logPurchase(productId, price, currencyCode, quantity, purchaseProperties) |
購入を記録する。JS ドキュメント |
brazeBridge.getUser().addAlias(alias, label) |
ユーザーにエイリアスを追加する。Web SDK v2.7.0、Android v8.1.0、および iOS SDK v3.26.0で導入 JS ドキュメント |
brazeBridge.getUser().addToCustomAttributeArray(key, value) |
カスタム属性配列に追加する。JS ドキュメント |
brazeBridge.getUser().addToSubscriptionGroup(subscriptionGroupId) |
ユーザーをメールまたはSMSサブスクリプショングループに追加する。JS ドキュメント。 このメソッドは Android SDK v15.0.0、Web SDK v3.4.0、iOS SDK v4.3.3 で導入されました。 |
brazeBridge.getUser().removeFromSubscriptionGroup(subscriptionGroupId) |
ユーザーをメールまたは SMS サブスクリプショングループから削除する。JS ドキュメント。 このメソッドは Android SDK v15.0.0、Web SDK v3.4.0、iOS SDK v4.3.3 で導入されました。 |
brazeBridge.getUser().setFirstName(firstName) |
ユーザーの名を設定します。JS ドキュメント |
brazeBridge.getUser().setLastName(lastName) |
ユーザーの姓を設定する。JS ドキュメント |
brazeBridge.getUser().setEmail(email) |
ユーザーのメールアドレスを設定する。JS ドキュメント |
brazeBridge.getUser().setGender(gender) |
ユーザーの性別を設定する。JS ドキュメント |
brazeBridge.getUser().setDateOfBirth(year, month, day) |
ユーザーの生年月日を設定する。JS ドキュメント |
brazeBridge.getUser().setCountry(country) |
ユーザーの国を設定する。JS ドキュメント |
brazeBridge.getUser().setHomeCity(city) |
ユーザーの市区町村を設定する。JS ドキュメント |
brazeBridge.getUser().setEmailNotificationSubscriptionType(notificationSubscriptionType) |
メール通知サブスクリプションのステータスを設定する。JS ドキュメント |
brazeBridge.getUser().setPushNotificationSubscriptionType(notificationSubscriptionType) |
プッシュ通知サブスクリプションステータスを設定する。JS ドキュメント |
brazeBridge.getUser().setPhoneNumber(phoneNumber) |
ユーザーの電話番号を設定する。JS ドキュメント |
brazeBridge.getUser().setCustomUserAttribute(key, value, merge) |
カスタムユーザー属性を設定する。JS ドキュメント |
brazeBridge.getUser().removeFromCustomAttributeArray(key, value) |
カスタムユーザー属性を削除する。JS ドキュメント |
brazeBridge.getUser().incrementCustomUserAttribute(key, incrementValue) |
カスタムユーザー属性をインクリメントする。JS ドキュメント |
brazeBridge.getUser().setLanguage(language) |
ユーザーの言語を設定する。Android SDK v5.0.0とWeb SDK v2.6.0で導入された。JS ドキュメント |
brazeBridge.getUser().setCustomLocationAttribute(key, latitude, longitude) |
カスタムロケーション属性を設定する。Android SDK v5.0.0で導入された。JS ドキュメント |
brazeBridge.web.registerAppboyPushMessages(successCallback, deniedCallback) |
Webプッシュに登録する(Webのみ)。このメソッドは、Web 以外の環境で呼び出された場合は何も実行しません。JS ドキュメント |
brazeBridge.requestPushPermission(successCallback, deniedCallback) |
Web、iOS、Androidにまたがるプッシュに登録する。注:このメソッドのコールバックはWeb上でのみサポートされている。このメソッドは、Web SDK v4.0.0、Android SDK v21.0.0、Swift SDK v5.4.0で導入されました。JS ドキュメント |
brazeBridge.changeUser(id, sdkAuthSignature?) |
一意の ID でユーザーを識別する。JS ドキュメント このメソッドはWeb SDK v4.3.0で導入された。 |
Button click tracking
Use the brazeBridge.logClick(button_id) method to track clicks in your custom HTML.
Banners: Only brazeBridge.logClick() (without arguments) is supported. Button IDs and custom button tracking are supported for in-app messages only.
For in-app messages, you can programmatically track “Button 1”, “Button 2”, and “Body Clicks” using brazeBridge.logClick('0'), brazeBridge.logClick('1'), or brazeBridge.logClick(), respectively.
| Clicks | Method | Supported |
|---|---|---|
| Body click | brazeBridge.logClick() |
In-app messages and Banners |
| Button 1 | brazeBridge.logClick('0') |
In-app messages only |
| Button 2 | brazeBridge.logClick('1') |
In-app messages only |
| Custom button tracking | brazeBridge.logClick('your custom name here') |
In-app messages only |
For in-app messages, you can track multiple button click events per impression. For example, to close a message and log a Button 2 click:
1
<a href="#" onclick="brazeBridge.logClick('1');brazeBridge.closeMessage()">✖</a>
You can also track new custom button names—up to 100 unique names per campaign. For example, brazeBridge.logClick('blue button') or brazeBridge.logClick('viewed carousel page 3').
When using JavaScript methods inside an onclick attribute, wrap string values in single quotes to avoid conflicts with the double-quoted HTML attribute.
Limitations (in-app messages only)
- You can have up to 100 unique button IDs per campaign.
- Button IDs can have up to 255 characters each.
- Button IDs can only include letters, numbers, spaces, dashes, and underscores.
GitHub でこのページを編集