Android SDK+ 統合ガイド
このページでは、Rokt Ecommerce Android SDK+の実装方法について説明します。SDK+は、設定された画面でユーザーとトランザクションデータをRoktに渡し、Roktが確認画面などで関連するエクスペリエンスを表示できるようにします。
1. Add the Rokt SDK+ to Your Android App#
Rokt SDK+は、最低Android APIレベル21+(Android 5.0 Lollipop)が必要です。
必要な依存関係を含めるためにGradleファイルを更新してください:
dependencies {
implementation("com.mparticle:android-rokt-kit:6.0.0")
implementation("com.mparticle:android-core:6.0.0")
}
dependencies {
implementation "com.mparticle:android-rokt-kit:6.0.0"
implementation "com.mparticle:android-core:6.0.0"
}
2. Initialize the Rokt SDK+#
次の初期化スニペットを、onCreate()クラスのApplicationメソッドに挿入します。SDK+は、他のSDK+ API呼び出しの前に初期化される必要があります。your-keyとyour-secretを、Roktチームから提供されたキーとシークレットに置き換えてください。
import com.mparticle.MParticle
import com.mparticle.MParticleOptions
import com.mparticle.networking.NetworkOptions
class YourApplicationClass : Application() {
override fun onCreate() {
super.onCreate()
// Identify the current user:
// If you do not have the user's email address, you can pass in a null value
val identifyRequest = IdentityApiRequest.withEmptyUser()
// Preferred: pass the customer's raw, unhashed email via .email().
// If you can only provide a SHA-256-hashed email, remove .email() and use .userIdentity(Other) instead — do not pass both.
.email("j.smith@example.com")
.userIdentity(MParticle.IdentityType.Other, "SHA-256 hashed email") // only if raw email unavailable
// If you can only provide a SHA-256-hashed mobile number, use 'other2' instead of MobileNumber — do not pass both.
.userIdentity(MParticle.IdentityType.Other2, "SHA-256 hashed mobile number") // only if raw mobile unavailable
// Customer phone number in E.164 format.
.userIdentity(MParticle.IdentityType.MobileNumber, "+13125551515")
// Partner's internal customer/account identifier (if the user is logged in).
.customerId("cust_10482")
.build()
// If the user is identified with their email address, set additional user attributes.
val identifyTask = BaseIdentityTask()
.addSuccessListener { identityApiResult ->
val user = identityApiResult.user
user.setUserAttribute("example attribute key", "example attribute value")
}
// Enter your custom subdomain if you are using a first-party domain configuration (optional)
val networkOptions = NetworkOptions.builder()
.setCustomBaseURL("https://rkt.example.com")
.build()
val options: MParticleOptions = MParticleOptions.builder(this)
.credentials(
"your-key", // The key provided by your Rokt account manager
"your-secret" // The secret provided by your Rokt account manager
)
// Specify the data environment with environment:
// Set it to Development if you are still testing your integration.
// Set it to Production if your integration is ready for production data.
// The default is AutoDetect which attempts to detect the environment automatically.
.environment(MParticle.Environment.Development)
.networkOptions(networkOptions)
.identify(identifyRequest)
.identifyTask(identifyTask)
.build()
MParticle.start(options)
}
}
Applicationクラスに初期化スニペットを挿入すると、次のカスタマイズ可能なフィールドが表示されます:
1Entering your Rokt key and secret#
your-key内のyour-secretとcredentialsを、Roktアカウントマネージャーから提供されたキーとシークレットの値に設定します。
2Setting your data environment#
テスト中は、environmentをMParticle.Environment.Developmentに設定してデータを開発環境にルーティングし、ライブ顧客活動を本番環境に送信するにはMParticle.Environment.Productionに設定します。
3Entering a custom first-party domain#
First-Party Domain Configurationの指示に従い、customBaseURLをNetworkOptionsに設定してカスタムサブドメインを指定します。Rokt SDK+を独自のドメイン経由でルーティングすることで、広告ブロッカーやブラウザによる広告やデータのブロックのリスクを軽減できます。networkOptionsを省略すると、Roktのデフォルトエンドポイントにトラフィックが送信されます。
4Identifying your user and setting attributes#
identifyRequestで、ユーザーの生のハッシュされていないメールを.email()を通じて渡します。ハッシュされたメールやその他の識別子については、Supported User Identifiersを参照してください。識別された後、identifyTaskの成功リスナーを使用して追加のユーザー属性を設定します。推奨されるリストについてはUser Attributesを参照してください。
val identifyTask = BaseIdentityTask()
.addSuccessListener { identityApiResult ->
val user = identityApiResult.user
user.setUserAttribute("example attribute key", "example attribute value")
}
初期化スニペットには必ずidentifyRequestを含めてください。初期化時にユーザーのメールがない場合は、.email()呼び出しを省略してください。SDK+は依然として初期化され、後で3. Identify the Userを通じてユーザーを識別できます。addFailureListenerコールバックの処理方法については、Error Handlingを参照してください。エラーハンドリングがないと、大規模なデータの一貫性の問題が発生する可能性があります。
Initializing with fontsInitializing with fonts への直接リンク
One Platformでフォントを提供する代わりに、またはそれに加えて、アプリケーションに既にバンドルされているフォントを使用することができます。これにより、初期化時にフォントがダウンロードされる可能性がなくなり、ネットワークの利用が削減され、ダウンロードエラーの可能性が減少します。
フォントアセットの使用フォントアセットの使用 への直接リンク
フォントのPostScript名をroktOptionsビルダーメソッドにマップし、assetsディレクトリ内のファイルパスにマップします。レイアウトで使用されているPostScript名が不明な場合は、アカウントマネージャーに確認してください。
import com.mparticle.MParticle
import com.mparticle.MParticleOptions
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
val options: MParticleOptions = MParticleOptions.builder(this)
.credentials("your-key", "your-secret")
.environment(MParticle.Environment.Development)
.roktOptions(RoktOptions(fontFilePathMap = mapOf("Arial-Bold" to "fonts/arialbold.otf")))
.build()
MParticle.start(options)
}
}
3. Identify the User#
SDK+ 初期化スクリプトは、スクリプトのidentifyRequestオブジェクトで提供された識別子を使用して現在のユーザーを識別します。SDKの初期化後、ユーザーがログイン、ログアウト、または識別子を提供するたびに(例えば、チェックアウト時)、以下に説明する適切な方法を使用してユーザーの識別情報を同期させ続ける必要があります。
サポートされているユーザー識別子サポートされているユーザー識別子 への直接リンク
サポートされているユーザー識別子を表示
| フィールド | 型 | 説明 |
|---|---|---|
email | string | 顧客の生のハッシュされていないメールアドレスを .email("j.smith@example.com") を介して渡します。 |
mobile | string | 顧客の電話番号を E.164 形式で .userIdentity(MParticle.IdentityType.MobileNumber, "+13125551515") を介して渡します。 |
customerid | string | 内部の顧客/アカウント識別子を .customerId("cust_10482") を介して渡します。ログインしているユーザーにはすべての画面で送信してください。 |
other | string | SHA-256 ハッシュされたメールを .userIdentity(MParticle.IdentityType.Other, "hashed email") を介して渡します。生のメールを提供できない場合にのみ使用してください。 |
other2 | string | SHA-256 ハッシュされた携帯番号を .userIdentity(MParticle.IdentityType.Other2, "hashed mobile") を介して渡します。 |
ユーザーを識別するには:
1Create an identifyRequest object#
ユーザーの識別子を含む identifyRequest オブジェクトを作成します。ユーザーの生のハッシュされていないメールアドレスを email フィールドに統合する必要があります。
2Create an identityCallback#
追加のユーザー属性を設定するには、identityCallback を作成します。identifyRequest が成功した場合、コールバック内で設定したユーザー属性は識別されたユーザーに割り当てられます。
3Send the request using the method that matches the user's action#
ユーザーのアクションに一致するメソッドに identifyRequest(およびオプションの identityCallback)を渡します:
MParticle.getInstance()?.Identity()?.login: ユーザーがログインまたはアカウントを作成したときに呼び出します。MParticle.getInstance()?.Identity()?.identify: ログイン遷移なしでセッション中にユーザーのメールを取得したときに呼び出します(例:ゲストがチェックアウト時にメールを入力した場合)。MParticle.getInstance()?.Identity()?.logout: ユーザーがログアウトしたときに呼び出します。
これらのメソッドを呼び出すと、SDK の現在のユーザーの状態の記録が移行されます。login および logout メソッドは、Rokt のアトリビューションを改善するために対応するイベントを自動的にログに記録します。
例えば、Jane Smith という名前のユーザーをメールアドレス j.smith@example.com、携帯番号 +13125551515、顧客 ID cust_10482 で識別するには:
// 1. Create the identifyRequest object
val identifyRequest = IdentityApiRequest.withEmptyUser()
// Preferred: pass the customer's raw, unhashed email via .email().
// If you can only provide a SHA-256-hashed email, remove .email() and use .userIdentity(Other) instead — do not pass both.
.email("j.smith@example.com")
.userIdentity(MParticle.IdentityType.Other, "SHA-256 hashed email") // only if raw email unavailable
// If you can only provide a SHA-256-hashed mobile number, use 'other2' instead of MobileNumber — do not pass both.
.userIdentity(MParticle.IdentityType.Other2, "SHA-256 hashed mobile number") // only if raw mobile unavailable
.userIdentity(MParticle.IdentityType.MobileNumber, "+13125551515")
.customerId("cust_10482")
.build()
// 2. Optionally set user attributes once the request succeeds.
val identityCallback = BaseIdentityTask()
.addSuccessListener { identityApiResult ->
val user = identityApiResult.user
user.setUserAttribute("firstname", "Jane")
user.setUserAttribute("lastname", "Smith")
}
// 3. Call one of the following methods that best matches the user's action:
MParticle.getInstance()?.Identity()?.login(identifyRequest, identityCallback) // Call when the user logs in or creates an account
MParticle.getInstance()?.Identity()?.identify(identifyRequest, identityCallback) // Call when you obtain the user's email mid-session, but not during a login
MParticle.getInstance()?.Identity()?.logout() // Call when the user logs out
4. Set User Attributes#
ユーザーがアプリをナビゲートする際に、段階的にユーザー属性を設定してください。チェックアウト時だけではありません。設定する属性が多いほど、Rokt は顧客を解決し、関連するオファーを提供するのに役立ちます。
import com.mparticle.MParticle
// Retrieve the current user. This will only succeed if you have identified the user during SDK+ initialization or by calling the identify method.
val currentUser = MParticle.getInstance()?.Identity()?.currentUser
// Once you have successfully set the current user to `currentUser`, you can set user attributes with:
currentUser?.setUserAttribute("custom-attribute-name", "custom-attribute-value")
// Note: all user attributes (including list attributes and tags) must have distinct names.
// Rokt recommends setting as many of the following user attributes as possible:
currentUser?.setUserAttribute("firstname", "John")
currentUser?.setUserAttribute("lastname", "Doe")
// Phone numbers can be formatted either as '1234567890', or '+1 (234) 567-8901'
currentUser?.setUserAttribute("mobile", "3125551515")
currentUser?.setUserAttribute("age", "33")
currentUser?.setUserAttribute("gender", "M")
currentUser?.setUserAttribute("billingcity", "Brooklyn")
currentUser?.setUserAttribute("billingstate", "NY")
currentUser?.setUserAttribute("billingzipcode", "123456")
currentUser?.setUserAttribute("dob", "yyyymmdd")
currentUser?.setUserAttribute("title", "Mr")
currentUser?.setUserAttribute("language", "en")
currentUser?.setUserAttribute("predictedltv", "136.23")
// You can create a user attribute to contain a list of values
currentUser?.setUserAttributeList("favorite-genres", listOf("documentary", "comedy", "romance", "drama"))
// To remove a user attribute, call removeUserAttribute and pass in the attribute name. All user attributes share the same key space.
currentUser?.removeUserAttribute("attribute-to-remove")
ユーザー属性ユーザー属性 への直接リンク
収集可能な限り、以下の項目を設定してください:
すべてのユーザー属性を表示
| フィールド | タイプ | 説明 |
|---|---|---|
firstname | string | 顧客の名。パーソナライズに使用されます。 |
lastname | string | 顧客の姓。パーソナライズに使用されます。 |
mobile | string | 電話番号は 1112345678 または +1 (222) 345-6789 の形式で。アイデンティティ解決と関連性に使用されます。 |
birthyear | integer | 顧客の出生年(例: 1990)。推奨される生年月日フィールド。代替: dob, age。適格性と関連性に使用されます。 |
age | integer | 顧客の年齢。dob の代替。適格性と関連性に使用されます。 |
dob | string | 生年月日、yyyymmdd。age の代替。適格性と関連性に使用されます。 |
gender | string | 顧客の性別。例: M, F, Male, または Female。関連性に使用されます。 |
title | string | 敬称。例: Mr, Mrs, Ms。パーソナライズに使用されます。 |
language | string | 購入に関連するISO 639-1言語コード。関連性に使用されます。 |
billingaddress1 | string | 住所(例: 123 Main St)。アイデンティティ解決と関連性に使用されます。 |
billingaddress2 | string | アパート/ユニット(例: Apt 4B)。アイデンティティ解決に使用されます。 |
billingcity | string | 請求先都市。関連性に使用されます。 |
billingstate | string | 請求先州/省/地域。関連性と適格性に使用されます。 |
billingzipcode | string | 完全なZIPまたは郵便番号(米国の優先はZIP+4)。アイデンティティ解決と関連性に使用されます。 |
country | string | ISO 3166-1 alpha-2国コード(例: US, GB, AU)。適格性と関連性に使用されます。 |
newcustomer | boolean | 初回購入者かどうか。関連性に使用されます。 |
customertype | string | ユーザーが認証されているかどうか(guest / logged_in)。関連性に使用されます。 |
loyaltytier | string | パートナーのロイヤルティプログラムの階層。関連性と適格性に使用されます。 |
loyaltyid | string | ロイヤルティプログラムのメンバーID。アイデンティティ解決に使用されます。 |
predictedltv | decimal | 予測される生涯価値(通常はパートナーのMLモデルから)。関連性に使用されます。 |
subscriptionstatus | string | 該当する場合のサブスクリプション状態 (active, trial, churned, paused, none)。関連性と適格性に使用されます。 |
customersegment | string | パートナー内部のセグメンテーション(例: vip, at_risk, new, reactivated)。関連性に使用されます。 |
acquisitionchannel | string | 顧客が最初に取得された方法。関連性に使用されます。 |
すべてのユーザー属性(リスト属性を含む)は、異なる名前を持たなければなりません。
5. Log Events#
Roktが各顧客がどの段階にいるかを理解できるように、画面ビュー、コマースイベント、およびカスタムイベントを追跡します。
画面の名前(例: "homepage", "product_detail_page")を指定して、MParticle.getInstance()?.logScreen()を呼び出します。追加のカスタム属性を情報マップに含めます。
MParticle.getInstance()?.logScreen(
"homepage",
mapOf("custom-attribute" to "custom-value")
)
コマースイベントは、ユーザーのジャーニーにおける製品レベルの詳細を運びます。顧客が行う各製品アクションに対して、別々のコマースイベントをトリガーします。
完全なコマースイベントカバレッジへの投資は、統合中にできる最も効果的なことの一つです。各イベントは、顧客がどの段階にいるかについてRoktに異なる情報を伝えます:製品ビューは探索を示し、カートへの追加は検討を示し、チェックアウトの開始は購入意図を示し、購入完了はコンバージョンを確認します。より豊かなシグナルを持つことで、Roktはオファーをより効果的にパーソナライズし、配置のパフォーマンスを正確に測定し、コンバージョンを正しいタッチポイントに帰属させることができます。この作業を初期の統合中に行うことで、後での改修を避けることができます。シグナルは時間とともに蓄積されます:Roktが受け取る各イベントは、パーソナライズを鋭くし、帰属の精度を向上させ、将来の訪問で顧客ベースをより良く解決し、セグメント化するために使用されるコンテキストを追加します。
コマースイベントは、CommerceEventを使用してログに記録され、顧客のアクションを識別する製品アクション定数(製品の表示、カートへの追加、チェックアウトの開始、購入の完了など)を使用します。
すべての製品アクションタイプを表示
| 顧客のアクション | 製品アクション定数 |
|---|---|
| 製品詳細ページを表示 | Product.VIEW_DETAIL |
| 製品をクリック | Product.CLICK |
| カートに商品を追加 | Product.ADD_TO_CART |
| カートから商品を削除 | Product.REMOVE_FROM_CART |
| ウィッシュリストに商品を追加 | Product.ADD_TO_WISHLIST |
| ウィッシュリストから商品を削除 | Product.REMOVE_FROM_WISHLIST |
| チェックアウトフローを開始 | Product.CHECKOUT |
| チェックアウトオプションを選択 | Product.CHECKOUT_OPTION |
| 注文が確認されました | Product.PURCHASE |
| 注文が返金されました | Product.REFUND |
コマースイベントを追跡するには、3つのフェーズがあります:
1Define the product#
ProductをProduct.Builderで構築します。名前、SKU、価格をコンストラクタ引数として設定し、quantity、category、brand、variantのような追加フィールドはビルダー呼び出しで設定します。
val product = Product.Builder("Double Room - Econ Rate", "econ-1", 100.00)
.quantity(4.0)
.category("room")
.brand("lodge-o-rama")
.variant("standard")
.build()
2Summarize the transaction#
TransactionAttributesをPurchase、Checkout、およびCheckoutOptionイベント用に構築します。適用可能な場合は、配送および注文レベルのクーポンを含めます — 注文レベルのクーポンはここに属し、個々の製品には属しません。
val transactionAttributes = TransactionAttributes("ORDER-12345")
.setRevenue(149.99)
.setTax(12.50)
.setShipping(5.99)
.setCouponCode("SUMMER20")
3Log the commerce event#
CommerceEventをCommerceEvent.Builderで構築し、上記のテーブルから製品アクション定数と製品を渡します。適用可能な場合はtransactionAttributesを添付し、その後MParticle.getInstance()?.logEvent(event)を呼び出します。ログに記録したい顧客アクションを選択します:
製品リストページ(またはカテゴリページ)のビューを製品インプレッションとしてログに記録します。CommerceEventでaddImpressionを使用してすべての表示製品を単一のイベントとして渡し、インプレッションのリスト名を顧客が閲覧しているリスト/カテゴリに設定します。
| Field | Type | Required | Description |
|---|---|---|---|
Name | string | yes | リストまたはカテゴリ名(例:"Mens Running Shoes")。list_nameになります。 |
Products | array | yes | createProductからの製品オブジェクト。各アイテムの1インデックスのランクにPositionを設定します。 |
currency | string | yes | ISO 4217通貨コード(イベントレベルのカスタム属性として渡されます)。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Impression
import com.mparticle.commerce.Product
val product = Product.Builder("Trail Runner v3", "SKU-001", 129.95)
.quantity(1.0)
.category("Shoes")
.brand("BrandX")
.position(1)
.build()
val impression = Impression("Mens Running Shoes", product)
val event = CommerceEvent.Builder(impression)
.customAttributes(mapOf("currency" to "USD"))
.build()
MParticle.getInstance()?.logEvent(event)
顧客が製品詳細ページを開いたときにログを記録します。
| Field | Type | Required | Description |
|---|---|---|---|
productsku | string | yes | 製品SKU。 |
productname | string | yes | 表示名。 |
itemprice | decimal | yes | ビュー時の単価。 |
currency | string | yes | ISO 4217通貨コード。 |
list_name | string | no | ユーザーがPLPから来た場合に設定します。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
val product = Product.Builder("Trail Runner v3", "SKU-001", 129.95)
.quantity(1.0)
.build()
val event = CommerceEvent.Builder(Product.VIEW_DETAIL, product)
.customAttributes(mapOf("currency" to "USD", "list_name" to "PLP-Running"))
.build()
MParticle.getInstance()?.logEvent(event)
顧客がカートにアイテムを追加したときにログを記録します。
| Field | Type | Required | Description |
|---|---|---|---|
productsku | string | yes | 製品SKU。 |
quantity | integer | yes | 追加されたユニット数。 |
itemprice | decimal | yes | 追加時の単価。 |
currency | string | yes | ISO 4217通貨コード。 |
couponCode | string | no | 追加時に適用された場合の注文レベルのクーポン。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
val product = Product.Builder("Trail Runner v3", "SKU-001", 129.95)
.quantity(1.0)
.build()
val event = CommerceEvent.Builder(Product.ADD_TO_CART, product)
.customAttributes(mapOf("currency" to "USD"))
.build()
MParticle.getInstance()?.logEvent(event)
顧客がカートから商品を削除したときにログを記録します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
productsku | string | yes | 商品のSKU。 |
quantity | integer | yes | 削除された単位数。 |
currency | string | yes | ISO 4217通貨コード。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
val product = Product.Builder("Trail Runner v3", "SKU-001", 129.95)
.quantity(1.0)
.build()
val event = CommerceEvent.Builder(Product.REMOVE_FROM_CART, product)
.customAttributes(mapOf("currency" to "USD"))
.build()
MParticle.getInstance()?.logEvent(event)
顧客がカートページに到着したときにログを記録します。カートページビューにはネイティブな商品アクションがないため、イベント名"view_cart"とEventType.Otherを使用してMPEvent.Builderを使用します。カートの全内容をカスタム属性として渡します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
event_name | string | yes | 常に"view_cart"。 |
event_type | EventType | yes | MParticle.EventType.Otherを使用します。 |
cartitems | array | yes | カートの全内容を、カスタム属性として渡す前にJSON文字列化します。 |
cartitemcount | integer | yes | カートの行数。 |
totalprice | decimal | yes | カートの合計。 |
currency | string | yes | ISO 4217通貨コード。 |
couponcode | string | no | 適用された場合の注文レベルのプロモーション。 |
cartitems配列の各エントリは次の形状を持ちます:
| Field | Type | Description |
|---|---|---|
cartitemid | string | Stable partner-side cart-line identifier. Usually equals productsku when there is one line per SKU; use a unique value if you allow multiple lines for the same SKU (e.g. gift-wrap variants). |
productsku | string | Product SKU / stock identifier. |
productname | string | Product display name. |
productcategory | string | Product category / taxonomy leaf. |
productbrand | string | Product brand. |
productvariant | string | Variant identifier (size, color, etc.). |
itemprice | decimal | Per-unit price at event time. |
unitprice | decimal | Per-unit list price pre-discount. Omit if equal to itemprice. |
quantity | integer | Units in this line. |
currency | string | ISO 4217 code. Omit if matches the top-level currency. |
couponcode | string | Coupon applied to this line (if any). Order-level promos belong in transactionAttributes.Coupon. |
productposition | integer | 1-indexed rank of the product within a list or search results. |
val cartItems = """[
{"cartitemid":"SKU-001","productsku":"SKU-001","productname":"Trail Runner v3","itemprice":129.95,"quantity":1},
{"cartitemid":"SKU-002","productsku":"SKU-002","productname":"Cushion Insole","itemprice":19.95,"quantity":2}
]"""
val cartEvent = MPEvent.Builder("view_cart", EventType.Other)
.customAttributes(mapOf(
"cartitemcount" to "3",
"totalprice" to "169.85",
"currency" to "USD",
"couponcode" to "SUMMER20",
"cartitems" to cartItems
))
.build()
MParticle.getInstance()?.logEvent(cartEvent)
顧客がチェックアウトフローに入ったときにログを記録します。カート内の全商品のセットとTransactionAttributesの概要を送信します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
cartitems | array | yes | カートの全内容を、カスタム属性として渡す前にJSON文字列化します。 |
totalprice | decimal | yes | 税/送料前のカートの合計。 |
cartitemcount | integer | yes | カートの行数。 |
currency | string | yes | ISO 4217通貨コード。 |
couponCode | string | no | 適用された場合の注文レベルのプロモーション。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
import com.mparticle.commerce.TransactionAttributes
val product1 = Product.Builder("Trail Runner v3", "SKU-001", 129.95).quantity(1.0).build()
val product2 = Product.Builder("Cushion Insole", "SKU-002", 19.95).quantity(2.0).build()
val transactionAttributes = TransactionAttributes()
.setCouponCode("SUMMER20")
.setRevenue(169.85)
val event = CommerceEvent.Builder(Product.CHECKOUT, product1)
.products(listOf(product1, product2))
.transactionAttributes(transactionAttributes)
.customAttributes(mapOf(
"currency" to "USD",
"cartitemcount" to "3",
"totalprice" to "169.85"
))
.build()
MParticle.getInstance()?.logEvent(event)
顧客が配送ステップを完了したときにログを記録します。Product.CHECKOUT_OPTIONアクションを使用し、checkoutOptions("shipping")を設定し、配送選択をカスタム属性として渡します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
cartitems | array | yes | カートの全内容。カスタム属性として渡す前にJSON文字列化されます。 |
shippingmethod | string | yes | standard / express / next_day. |
zipcode | string | yes | 配送の郵便番号。 |
country | string | yes | ISO 3166-1 alpha-2 国コード。 |
totalprice | decimal | yes | カートの合計。 |
currency | string | yes | ISO 4217 通貨コード。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
val product1 = Product.Builder("Trail Runner v3", "SKU-001", 129.95).quantity(1.0).build()
val product2 = Product.Builder("Cushion Insole", "SKU-002", 19.95).quantity(2.0).build()
val event = CommerceEvent.Builder(Product.CHECKOUT_OPTION, product1)
.products(listOf(product1, product2))
.checkoutOptions("shipping")
.customAttributes(mapOf(
"shippingmethod" to "express",
"zipcode" to "94103",
"country" to "US",
"totalprice" to "169.85",
"currency" to "USD"
))
.build()
MParticle.getInstance()?.logEvent(event)
顧客が支払いステップを完了したときにログを記録します。Product.CHECKOUT_OPTION アクションを使用し、checkoutOptions("payment") を設定し、選択された支払い方法をカスタム属性として渡します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
cartitems | array | yes | カートの全内容。カスタム属性として渡す前にJSON文字列化されます。 |
paymenttype | string | yes | credit_card / paypal / apple_pay / etc. |
payment_method | string | no | 関連する場合の特定の方法(例:カードブランド)。 |
paymentServiceProvider | string | no | PSP識別子(例:stripe)。キャメルケースである必要があります。 |
ccbin | string | no | カードが使用された場合の最初の6-8桁。 |
totalprice | decimal | yes | カートの合計。 |
currency | string | yes | ISO 4217 通貨コード。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
val product1 = Product.Builder("Trail Runner v3", "SKU-001", 129.95).quantity(1.0).build()
val product2 = Product.Builder("Cushion Insole", "SKU-002", 19.95).quantity(2.0).build()
val event = CommerceEvent.Builder(Product.CHECKOUT_OPTION, product1)
.products(listOf(product1, product2))
.checkoutOptions("payment")
.customAttributes(mapOf(
"paymenttype" to "credit_card",
"payment_method" to "visa",
"paymentServiceProvider" to "stripe",
"ccbin" to "424242",
"totalprice" to "169.85",
"currency" to "USD"
))
.build()
MParticle.getInstance()?.logEvent(event)
注文が確認されたときにログを記録します。注文ID、収益、税金、配送、および注文レベルのクーポンを含む TransactionAttributes の概要とともに、カート商品の全セットを送信します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
cartitems | array | yes | 注文時のカートの全内容。カスタム属性として渡す前にJSON文字列化されます。 |
transactionId | string | yes | 注文/取引識別子。 |
totalprice | decimal | yes | 注文の合計(収益)。 |
tax | decimal | yes | 注文に対する総税額。 |
shipping | decimal | yes | 配送料。 |
currency | string | yes | ISO 4217 通貨コード。 |
couponCode | string | no | 適用された場合の注文レベルのプロモーション。 |
cartitemcount | integer | no | カートの行数。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
import com.mparticle.commerce.TransactionAttributes
val product1 = Product.Builder("Trail Runner v3", "SKU-001", 129.95).quantity(1.0).build()
val product2 = Product.Builder("Cushion Insole", "SKU-002", 19.95).quantity(2.0).build()
val transactionAttributes = TransactionAttributes("ORDER-10482")
.setRevenue(169.85)
.setTax(14.20)
.setShipping(5.99)
.setCouponCode("SUMMER20")
val event = CommerceEvent.Builder(Product.PURCHASE, product1)
.products(listOf(product1, product2))
.transactionAttributes(transactionAttributes)
.customAttributes(mapOf("currency" to "USD", "cartitemcount" to "3"))
.build()
MParticle.getInstance()?.logEvent(event)
注文(またはその中のライン)が返金されたときにログを記録します。返金される商品のみを送信し、元の注文を参照するTransactionAttributesオブジェクトを含めます。
| フィールド | タイプ | 必須 | 説明 |
|---|---|---|---|
productsku | string | yes | 返金されたラインのSKU。 |
quantity | integer | yes | 返金された単位数。 |
transactionId | string | yes | 返金対象の元の注文ID。 |
totalprice | decimal | yes | 返金額。 |
currency | string | yes | ISO 4217通貨コード。 |
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
import com.mparticle.commerce.TransactionAttributes
val refundedProduct = Product.Builder("Trail Runner v3", "SKU-001", 129.95)
.quantity(1.0)
.build()
val transactionAttributes = TransactionAttributes("ORDER-10482")
.setRevenue(129.95)
val event = CommerceEvent.Builder(Product.REFUND, refundedProduct)
.transactionAttributes(transactionAttributes)
.customAttributes(mapOf("currency" to "USD"))
.build()
MParticle.getInstance()?.logEvent(event)
MPEvent.Builderを使用してカスタムイベントを追跡し、イベント名、イベントタイプ、およびオプションのカスタム属性を渡します。
カスタムイベントタイプを表示
| タイプ | 使用目的 |
|---|---|
EventType.Navigation | アプリ内のユーザーのナビゲーションフローと画面遷移。 |
EventType.Location | 位置情報に基づくインタラクションと移動。 |
EventType.Search | 検索クエリと検索関連のアクション。 |
EventType.Transaction | 金融取引と購入関連の活動。 |
EventType.UserContent | レビュー、コメント、投稿などのユーザー生成コンテンツ。 |
EventType.UserPreference | ユーザー設定、好み、カスタマイズの選択。 |
EventType.Social | ソーシャルメディアのインタラクションと共有活動。 |
EventType.Other | 上記のカテゴリに当てはまらないもの。 |
val event = MPEvent.Builder("video_watched", EventType.Navigation)
.customAttributes(mapOf("category" to "Destination Intro", "title" to "Paris"))
.build()
MParticle.getInstance()?.logEvent(event)
6. Show a Placement#
すべての支払いおよび確認画面でselectPlacementsを呼び出し、Roktがコンテンツをレンダリングするようにします。画面タイプとテストまたは本番用であるかを指定するために、次のページ識別子のいずれかを含めます。
stg.rokt.conf: A confirmation screen in a staging (or testing) environment.prod.rokt.conf: A confirmation screen in a production environment.stg.rokt.payments: A payments screen in a staging (or testing) environment.prod.rokt.payments: A payments screen in a production environment.
配置属性配置属性 への直接リンク
これらの属性は、attributes マップ内の selectPlacements に渡します。常に最新の値を提供してください。ここで渡された属性は、以前の setUserAttribute 呼び出しを上書きします。
すべての配置属性を表示
| フィールド | タイプ | 説明 |
|---|---|---|
email | string | 顧客のメールアドレス(ハッシュ化されていない)。アイデンティティ解決に使用されます。 |
firstname | string | 顧客の名前。パーソナライズに使用されます。 |
lastname | string | 顧客の姓。パーソナライズに使用されます。 |
mobile | string | E.164形式の顧客の携帯電話番号。アイデンティティ解決に使用されます。 |
confirmationref | string | 注文/確認参照番号。関連性と重複排除に使用されます。 |
currency | string | トランザクション通貨(ISO 4217、例: USD, GBP, AUD)。関連性に使用されます。 |
country | string | ISO 3166-1 alpha-2 国コード。適格性と関連性に使用されます。 |
language | string | 顧客の希望言語(ISO 639-1)。関連性に使用されます。 |
totalprice | decimal | 税金と送料を含むカートの合計値。関連性に使用されます。 |
amount | decimal | 税金と送料を除いたカートの小計。totalprice とは異なります。関連性に使用されます。 |
cartItems | array | カートラインオブジェクトの構造化された配列。キャメルケースである必要があります。関連性に使用されます。 |
couponcode | string | 注文に適用されたプロモーションコード(ある場合)。関連性に使用されます。 |
newcustomer | boolean | 初回購入者かどうか。関連性に使用されます。 |
customertype | string | guest または logged_in。関連性に使用されます。 |
value | decimal | 顧客の累積購入価値。関連性に使用されます。 |
subscriptionstatus | string | 該当する場合のサブスクリプション状態(active, trial, churned, paused, none)。関連性と適格性に使用されます。 |
customersegment | string | パートナー内部セグメンテーション(例: vip, at_risk, new, reactivated)。関連性に使用されます。 |
paymenttype | string | 選択された支払い方法 (credit_card, paypal, apple_pay など)。Pay+ の適格性に使用されます。 |
paymentServiceProvider | string | 画面で受け入れられる支払い方法のカンマ区切りリスト (例: applepay,paypal,cardpayment)。値は小文字でスペースを含まない必要があります。受け入れられる値の完全なリストについては、Payment Service Provider を参照してください。Pay+ の適格性に使用されます。 |
ccbin | string | クレジットカードのBIN (6-8桁)。関連性に使用されます。 |
billingaddress1 | string | 請求先の住所。アイデンティティ解決と関連性に使用されます。 |
billingaddress2 | string | 請求先のアパート/ユニット。アイデンティティ解決に使用されます。 |
billingcity | string | 請求先の市区町村。関連性に使用されます。 |
billingstate | string | 請求先の州または県。関連性に使用されます。 |
billingzipcode | string | 請求先の郵便番号。アイデンティティ解決と関連性に使用されます。 |
billingname | string | 請求先住所のカード名義人のフルネーム。アイデンティティ解決に使用されます。 |
shippingmethod | string | 選択された配送方法 (standard, express, next_day)。関連性に使用されます。 |
shippingname | string | 配送先住所の受取人のフルネーム。関連性に使用されます。 |
shippingaddress1 | string | 配送先の住所。関連性に使用されます。 |
shippingcity | string | 配送先の市区町村。関連性に使用されます。 |
shippingstate | string | 配送先の州または県。関連性に使用されます。 |
shippingzipcode | string | 配送先の郵便番号。関連性に使用されます。 |
shippingcountry | string | 配送先の国 (ISO 3166-1 alpha-2)。関連性に使用されます。 |
partnerpaymentreference | string | 顧客の保存された支払い方法の推測不可能な識別子。Shoppable Ads カードの転送に使用されます。 |
last4digits | string | 使用されたカードの最後の4桁。アイデンティティ解決に使用されます。 |
plcc | string | "yes" または "no" — 顧客がプライベートラベルのクレジットカードを持っているかどうか。Pay+ の関連性に使用されます。 |
discountamount | decimal | 注文レベルで適用された割引。Pay+ の関連性に使用されます。 |
prescreen | string | "yes" または "no" — 顧客がクレジットオファーの事前審査を受けたかどうか。Pay+ の関連性に使用されます。 |
adsexperience | string | Shoppable Adsのエクスペリエンスをターゲットにする場合は、"shoppable"を渡します。 |
オーバーレイプレースメントは、Roktが管理するコンテナ内で確認画面の上にレンダリングされ、アプリの既存のレイアウトに変更を加える必要はありません。
オーバーレイプレースメントを挿入するには、確認画面が読み込まれた後にselectPlacementsを呼び出します:
import com.mparticle.MParticle
import com.mparticle.rokt.RoktConfig
val attributes = mapOf(
// Identity
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"mobile" to "+13125551515",
// Transaction
"confirmationref" to "54321",
"currency" to "USD",
"country" to "US",
"language" to "en",
"totalprice" to "149.99",
"couponcode" to "SUMMER20",
// Customer context
"newcustomer" to "false",
"customertype" to "logged_in",
"value" to "2340.00",
"subscriptionstatus" to "active",
"customersegment" to "vip",
// Payment (include paymenttype and paymentServiceProvider for Pay+)
"paymenttype" to "credit_card",
"paymentServiceProvider" to "cardpayment",
"ccbin" to "411112",
// Billing address
"billingaddress1" to "123 Main St",
"billingcity" to "Brooklyn",
"billingstate" to "NY",
"billingzipcode" to "11201",
// Shipping
"shippingmethod" to "express",
"shippingaddress1" to "175 Varick St",
"shippingcity" to "New York",
"shippingstate" to "NY",
"shippingzipcode" to "10014",
"shippingcountry" to "US"
)
val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()
MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
config = roktConfig
)
埋め込みプレースメントは、アプリ内の固定位置にインラインでレンダリングされます(例:カート画面の支払いオプションの上)。ThanksとPay+の両方が埋め込みプレースメントを使用しますが、Pay+は埋め込みプレースメントを使用する必要があります。
1Add RoktEmbeddedView to your layout XML#
レイアウトXMLにRoktEmbeddedViewを追加し、プレースメントをレンダリングしたい位置に配置します。その高さをwrap_contentに設定し、プレースメントが動的にサイズを変更できるようにします。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mparticle.rokt.RoktEmbeddedView
android:id="@+id/roktEmbeddedView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2Wire up callbacks and call selectPlacements#
プレースメントイベント(ロード、アンロード、ローディングインジケータの状態など)に応答するために、MpRoktEventCallbackインターフェースを使用し、埋め込みビュー、コールバック、および設定を渡してアクティビティからselectPlacementsを呼び出します。
import com.mparticle.rokt.RoktConfig
import com.mparticle.rokt.RoktEmbeddedView
import com.mparticle.MpRoktEventCallback
import com.mparticle.UnloadReasons
class ConfirmActivity : Activity() {
val callbacks = object : MpRoktEventCallback {
override fun onLoad() {
// Optional callback for when the Rokt placement loads
}
override fun onUnload(reason: UnloadReasons) {
// Optional callback for when the Rokt placement unloads
}
override fun onShouldShowLoadingIndicator() {
// Optional callback to show a loading indicator
}
override fun onShouldHideLoadingIndicator() {
// Optional callback to hide a loading indicator
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val attributes = mapOf(
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"billingzipcode" to "90210",
"confirmationref" to "54321"
)
val roktWidget = findViewById<RoktEmbeddedView>(R.id.roktEmbeddedView)
val embeddedViews = mapOf("RoktEmbedded1" to WeakReference(roktWidget))
val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()
MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
callbacks = callbacks,
embeddedViews = embeddedViews,
config = roktConfig
)
}
}
Pay+プレースメントの場合、各画面でのselectPlacements呼び出しにpaymenttypeとpaymentServiceProviderを含めます。paymentServiceProviderは、支払い画面で利用可能な支払い方法を伝え、paymenttypeはユーザーが支払った方法を伝えます。
オプション機能オプション機能 への直接リンク
| 機能 | 目的 |
|---|---|
Rokt.close() | オーバーレイプレースメントを自動的に閉じます。 |
追加設定追加設定 への直接リンク
オプションのパラメータとしてRoktConfigを渡し、プレースメントUIをカスタマイズします(例:ダーク/ライトモード、キャッシング)。フォントの書体は、PostScript名をTypefaceオブジェクトにマップとして提供することもできます。
val fontTypefaces: MutableMap<String, WeakReference<android.graphics.Typeface>> = HashMap()
fontTypefaces["Arial-Bold"] = WeakReference(yourTypefaceObject)
val roktConfig = RoktConfig.Builder().colorMode(RoktConfig.ColorMode.LIGHT).build()
MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
fontTypefaces = fontTypefaces,
config = roktConfig
)
識別子RoktExperienceまたは埋め込み識別子RoktEmbedded1を別の値に更新したい場合は、Roktアカウントマネージャーに連絡して、Roktプレースメントが一貫して設定されていることを確認してください。
Events APIEvents API への直接リンク
SDK+は、MParticle.getInstance()?.Rokt()?.events APIを通じて、配置のライフサイクルイベントをストリームとして提供します。Kotlin Flowを使用して、SDK+が生成するイベントを消費します。
import com.mparticle.MParticle
// owner: LifecycleOwner
owner.lifecycleScope.launch {
owner.lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
MParticle.getInstance()?.Rokt()?.events("RoktExperience")?.collect { roktEvent ->
// Handle the event
}
}
}
標準イベント標準イベント への直接リンク
すべての標準イベントを表示
| イベント | 説明 | パラメータ |
|---|---|---|
| ShowLoadingIndicator | SDK+がRoktバックエンドを呼び出す前にトリガーされます。 | |
| HideLoadingIndicator | SDK+がRoktバックエンドからの成功または失敗を受け取ったときにトリガーされます。 | |
| PlacementInteractive | 配置がレンダリングされ、操作可能になったときにトリガーされます。 | placementId: String |
| PlacementReady | 配置が表示準備が整ったが、まだコンテンツがレンダリングされていないときにトリガーされます。 | placementId: String |
| OfferEngagement | ユーザーがオファーに関与したときにトリガーされます。 | placementId: String |
| PositiveEngagement | ユーザーがオファーに対して積極的に関与したときにトリガーされます。 | placementId: String |
| FirstPositiveEngagement | ユーザーが初めてオファーに対して積極的に関与したときにトリガーされます。 | placementId: String, fulfillmentAttributes: FulfillmentAttributes |
| OpenUrl | ユーザーがパートナーアプリに送信するように設定されたURLを押したときにトリガーされます。 | placementId: String, url: String |
| PlacementClosed | ユーザーによって配置が閉じられたときにトリガーされます。 | placementId: String |
| PlacementCompleted | オファーの進行が終了し、表示するオファーがなくなったときにトリガーされます。また、キャッシュがヒットしたが、以前に却下されたために取得されたプレースメントが表示されない場合にもトリガーされます。 | placementId: String |
| PlacementFailure | プレースメントが何らかの失敗により表示できなかった場合、または表示するプレースメントがない場合にトリガーされます。 | placementId: String (optional) |
| CartItemInstantPurchase | ユーザーによってカタログアイテムの購入が開始されたときにトリガーされます。 | placementId: String, cartItemId: String, catalogItemId: String, currency: String, description: String, linkedProductId: String, totalPrice: Double, quantity: Int, unitPrice: Double |
グローバルイベントグローバルイベント への直接リンク
特定のプレースメントに結びつかないSDK+レベルのイベントを購読するには、Rokt.globalEvents()を使用します。
import com.rokt.roktsdk.RoktEvent
// owner: LifecycleOwner
owner.lifecycleScope.launch {
Rokt.globalEvents().collect { event ->
if (event is RoktEvent.InitComplete) {
// SDK+ initialization is complete
}
}
}
7. Appendix#
付録A: アプリ設定付録A: アプリ設定 への直接リンク
アプリケーションは、RoktConfigを通じて設定を渡すことができ、Android SDK+がシステムのデフォルトではなくアプリのカスタム設定を使用するようにします。
ColorModeオブジェクトColorModeオブジェクト への直接リンク
| 値 | 説明 |
|---|---|
| LIGHT | アプリケーションはライトモードです |
| DARK | アプリケーションはダークモードです |
| SYSTEM | アプリケーションはシステムのカラーモードをデフォルトとします |
EdgeToEdgeDisplayEdgeToEdgeDisplay への直接リンク
| 値 | 説明 |
|---|---|
true (default) | アプリケーションはエッジからエッジへの表示モードをサポートしています |
false | アプリケーションはエッジからエッジへの表示モードをサポートしていません |
import com.mparticle.MParticle
import com.mparticle.rokt.RoktConfig
val roktConfig = RoktConfig.Builder()
.colorMode(RoktConfig.ColorMode.LIGHT)
.edgeToEdgeDisplay(true)
.build()
MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
config = roktConfig
)
CacheConfigオブジェクトCacheConfigオブジェクト への直接リンク
| パラメータ | 説明 |
|---|---|
cacheDurationInSeconds | Rokt SDK+がエクスペリエンスをキャッシュする秒単位のオプションの期間です。最大許容値は90分で、指定されていないか無効な場合はデフォルトで90分です。 |
cacheAttributes | キャッシュキーとして使用されるオプションの属性です。nullの場合、selectPlacementsで送信されたすべての属性がキャッシュキーとして使用されます。 |
import com.mparticle.rokt.CacheConfig
import com.mparticle.rokt.RoktConfig
// Cache the experience for 1200 seconds, using email and orderNumber as the cache key.
val roktConfig = RoktConfig.Builder()
.cacheConfig(CacheConfig(
cacheDurationInSeconds = 1200,
cacheAttributes = mapOf("email" to "j.smith@example.com", "orderNumber" to "123")
))
.build()
MParticle.getInstance()?.Rokt()?.selectPlacements(
identifier = "RoktExperience",
attributes = attributes,
config = roktConfig
)
Appendix B: Jetpack ComposeサポートとRoktLayoutAppendix B: Jetpack ComposeサポートとRoktLayout への直接リンク
Jetpack Composeを使用して実装された画面の場合、SDK+はRoktプレースメントのモダンで宣言的な統合のためにRoktLayoutコンポーザブルを提供します。RoktLayoutは、selectPlacementsを手動で呼び出すことなく、Overlay、BottomSheet、およびEmbeddedプレースメントタイプをサポートします。
import com.mparticle.kits.RoktLayout
import com.mparticle.MpRoktEventCallback
import com.mparticle.UnloadReasons
@Composable
fun MainScreen(modifier: Modifier = Modifier) {
Column(
modifier = modifier
.background(Color.LightGray)
.padding(8.dp),
) {
val attributes = mapOf(
"email" to "j.smith@example.com",
"firstname" to "Jenny",
"lastname" to "Smith",
"billingzipcode" to "90210",
"confirmationref" to "54321"
)
val callbacks = object : MpRoktEventCallback {
override fun onLoad() = println("View loaded")
override fun onUnload(reason: UnloadReasons) = println("View unloaded due to: $reason")
override fun onShouldShowLoadingIndicator() = println("Show loading indicator")
override fun onShouldHideLoadingIndicator() = println("Hide loading indicator")
}
val roktConfig = RoktConfig.Builder()
.colorMode(RoktConfig.ColorMode.DARK)
.cacheConfig(CacheConfig(
cacheDurationInSeconds = 1200,
cacheAttributes = mapOf("email" to "j.smith@example.com")
))
.build()
RoktLayout(
sdkTriggered = true,
identifier = "RoktExperience",
attributes = attributes,
location = "RoktEmbedded1",
modifier = Modifier
.fillMaxWidth()
.background(Color.Black),
mpRoktEventCallback = callbacks,
config = roktConfig
)
}
}
パラメータパラメータ への直接リンク
| パラメータ | 型 | 説明 |
|---|---|---|
sdkTriggered | Boolean | プレースメントをトリガーするタイミングを制御します。 |
identifier | String | Roktエクスペリエンスの識別子(例: "RoktExperience")。 |
location | String? | 埋め込みプレースメントのためのオプションのロケーション名(例: "RoktEmbedded1")。 |
attributes | Map<String, String> | プレースメントに渡す属性のマップ。 |
modifier | Modifier | レイアウト、スタイリング、UIの動作をカスタマイズするためのCompose Modifier。 |
mpRoktEventCallback | MpRoktEventCallback | プレースメントイベント(ロード、アンロード、ロード状態)を処理するためのオプションのコールバック。 |
config | RoktConfig? | カラーモード、キャッシングなどのためのオプションの設定。 |
Appendix C: エラーハンドリングAppendix C: エラーハンドリング への直接リンク
IDSync APIはアプリの状態にとって中心的なものであり、高速で高可用性を持つように設計されています。アプリがインターネット接続なしでユーザーのログイン、ログアウト、または状態の変更を防ぐのと同様に、これらのAPIをゲート操作として扱い、一貫したユーザー状態を維持します。SDK+はAPIコールを自動的に再試行しませんが、ビジネスロジックに応じて再試行できるようにコールバックAPIを提供します。
エラーハンドリングを実装しない場合、大規模なデータの一貫性の問題が発生する可能性があります。
SDK+は常に基礎となるHTTPレスポンスのHTTPステータスとボディを返します。クライアント側の問題(デバイスの範囲外、クライアント側のタイムアウト、無効なアイデンティティリクエスト)については、SDK+はIdentityApi.UNKNOWN_ERRORとともに情報的なエラーメッセージを返します。
MParticle.getInstance()?.Identity()?.identify(identifyRequest)
?.addFailureListener { identityHttpResponse ->
if (identityHttpResponse?.httpCode == IdentityApi.UNKNOWN_ERROR) {
// Device is likely offline — retry the request
} else if (identityHttpResponse?.httpCode == IdentityApi.THROTTLE_ERROR) {
// Throttled (429) — retry with backoff
}
}
?.addSuccessListener { identityApiResult ->
// Proceed with the identified user
}
MParticle.getInstance().Identity().identify(identifyRequest)
.addFailureListener(new TaskFailureListener() {
@Override
public void onFailure(IdentityHttpResponse identityHttpResponse) {
if (identityHttpResponse.getHttpCode() == IdentityApi.UNKNOWN_ERROR) {
// Device is likely offline — retry the request
} else if (identityHttpResponse.getHttpCode() == IdentityApi.THROTTLE_ERROR) {
// Throttled (429) — retry with backoff
}
}
})
.addSuccessListener(new TaskSuccessListener() {
@Override
public void onSuccess(IdentityApiResult identityApiResult) {
// Proceed with the identified user
}
});
付録 D: WebからネイティブへのセッションIDの受け渡し付録 D: WebからネイティブへのセッションIDの受け渡し への直接リンク
ユーザージャーニーがWebとネイティブプラットフォームの両方にまたがる場合、Web SDK+からAndroid SDK+にセッションIDを渡すことで、一貫したRoktセッションを維持できます。これは、ユーザーがWebView(支払いページなど)でアクションを完了し、ネイティブアプリに戻って確認を行うハイブリッドフローに役立ちます。
Web SDK+からセッションIDを取得するWeb SDK+からセッションIDを取得する への直接リンク
selectPlacementsを呼び出した後、セッションIDは選択コンテキストで利用可能です。
const selection = await launcher.selectPlacements({
identifier: "checkout",
attributes: {
email: "user@example.com",
// ... other attributes
}
});
const sessionId = await selection.context.sessionId;
The session ID is a unique GUID assigned to the current user journey. It is useful for debugging and for correlating a user's activity across your web and native surfaces.
ディープリンクを介してネイティブアプリに渡すディープリンクを介してネイティブアプリに渡す への直接リンク
ディープリンクを使用して、セッションIDをネイティブアプリに渡します。
const deepLink = `myapp://confirmation?sessionId=${encodeURIComponent(sessionId)}`;
window.location.href = deepLink;
セッションIDの設定セッションIDの設定 への直接リンク
ディープリンクからセッションIDを抽出し、selectPlacementsを呼び出す前にSDK+に渡します。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent.data?.getQueryParameter("sessionId")?.let { sessionId ->
MParticle.getInstance()?.Rokt()?.setSessionId(sessionId)
}
// Proceed with your confirmation flow
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri data = getIntent().getData();
if (data != null) {
String sessionId = data.getQueryParameter("sessionId");
if (sessionId != null) {
MParticle.getInstance().Rokt().setSessionId(sessionId);
}
}
// Proceed with your confirmation flow
}
注意事項注意事項 への直接リンク
- セッションを使用するために、
setSessionIdをselectPlacementsの前に呼び出してください。 - 空の文字列は無視され、セッションは更新されません。
- セッションIDをクエリパラメータとして渡す際には、常にURLエンコードしてください。
8. Test Your Integration#
SDK+が正しく初期化され、イベントが正しくログに記録されることを確認するには:
1Enable verbose SDK+ logging#
初期化前に詳細なSDK+ログを有効にして、送信される内容を確認できるようにします。
MParticle.setLogLevel(MParticle.LogLevel.VERBOSE)
2Build and run your app#
environment = MParticle.Environment.Developmentでアプリをビルドして実行します。
3Trigger selectPlacements#
配置がレンダリングされるべき画面でselectPlacementsをトリガーし、配置がロードされることを確認します。
4Verify events#
イベントがログに記録され、identifyRequest呼び出しが成功することを確認します。
トラブルシューティングトラブルシューティング への直接リンク
プレースメントが表示されない、またはイベントが表示されない場合は、Android LogcatでRokt SDK+のエラーを確認してください。一般的な問題:
初期化エラー初期化エラー への直接リンク
credentialsキーとシークレットがRoktアカウントマネージャーから提供された値と一致していることを確認してください。MParticle.start(options)がApplication.onCreate()内で、いかなるselectPlacementsやlogEvent呼び出しの前に実行されていることを確認してください。
アイデンティティエラーアイデンティティエラー への直接リンク
identifyTask の失敗リスナーが発火した場合、エラーハンドリング を参照して IdentityApi のエラーコードと再試行ガイダンスを確認してください。エラーハンドリングを行わないと、大規模なデータ整合性の問題が発生する可能性があります。
プレースメントが表示されないプレースメントが表示されない への直接リンク
- プレースメントの
identifier(例:RoktExperience) がRoktアカウントマネージャーが設定したものと一致していることを確認してください。 - 埋め込みプレースメントの場合、埋め込みビューの識別子 (例:
RoktEmbedded1) がレイアウト設定と一致していることを確認してください。 - 属性マップに少なくとも
email、firstname、lastname、billingzipcode、およびconfirmationrefが含まれていることを確認してください。
プロキシ使用時のSSLハンドシェイクエラープロキシ使用時のSSLハンドシェイクエラー への直接リンク
開発環境でテストしている際に、CharlesやProxymanのようなHTTPデバッグプロキシが動作している場合や、企業ネットワークプロキシの背後にいる場合にSSLハンドシェイクエラーが発生することがあります。これは予想される動作です: SDK+はSSL証明書をピン留めしており、プロキシは独自の証明書を提示してHTTPSをインターセプトするため、ピン留めが失敗します。
プロキシがSDK+トラフィックを検査できるようにするには、開発ビルドでピン留めを無効にし、setPinningDisabledInDevelopment(true) を SDK+初期化スクリプト 内の NetworkOptions ビルダーに追加してください。
val networkOptions = NetworkOptions.builder()
// Only takes effect in the development environment; production builds stay pinned.
.setPinningDisabledInDevelopment(true)
.build()