React Native SDK+ 統合ガイド
このページでは、Rokt Ecommerce React Native SDK+ の実装方法について説明します。SDK+ は、設定された画面でユーザーおよびトランザクションデータを Rokt に渡し、Rokt が確認画面でのオファーなどの関連するエクスペリエンスを表示できるようにします。
上記の Target および Language セレクターを使用して、デプロイメントプラットフォームと、従いたいネイティブコードの例を選択します。
SDK+を初期化する際に、ステップ2でネイティブコードを数行書きます。他のステップはすべて、react-native-mparticleパッケージを通じてJavaScriptを使用します。
1. Add the Rokt SDK+ to Your React Native App#
1Install the React Native package#
React Native SDK+をアプリケーションの依存関係として追加します:
npm install react-native-mparticle --save
2Import the package into your app#
パッケージをReact Nativeアプリコードにインポートし、SDKのインスタンスを取得します:
import MParticle from 'react-native-mparticle';
ネイティブプロジェクトでSDK+の設定を続行します。Targetピルを使用して、iOSとAndroidを切り替えます。
上記のNPMインストールステップは、ReactフレームワークとコアiOSフレームワークを自動的に取り込みます。Rokt SDK+ for iOSは、ios/Podfileにポッド依存関係として追加されます。
3Add the Rokt SDK pod to your Podfile#
Rokt SDK+ポッドをios/Podfileに追加します:
pod 'RoktSDKPlus', '~> 9.2'
RoktのiOS SDKにはSwiftコードが含まれているため、React Nativeのデフォルトの静的リンクをpre_install例外で保持するか、プロジェクトをフレームワークに切り替える必要があります。プロジェクトに合ったパスを選択してください:
4Configure your Podfile#
次のpre_installブロックをios/Podfileに追加します:
pre_install do |installer|
installer.pod_targets.each do |pod|
if pod.name == 'RoktSDKPlus' || pod.name == 'mParticle-Apple-SDK' || pod.name == 'mParticle-Rokt' || pod.name == 'Rokt-Widget'
def pod.build_type
Pod::BuildType.new(:linkage => :dynamic, :packaging => :framework)
end
end
end
end
5Install pods#
変更を適用するためにpod installを実行します:
bundle exec pod install
4Configure your Podfile#
ios/PodfileにFlipper設定行がある場合はコメントアウトします:
# :flipper_configuration => flipper_config,
5Install pods#
pod installを使用してUSE_FRAMEWORKSを実行し、変更を適用します。プロジェクトに基づいてstaticまたはdynamicを選択します:
USE_FRAMEWORKS=static bundle exec pod install
# or
USE_FRAMEWORKS=dynamic bundle exec pod install
2. Initialize the Rokt SDK+#
ネイティブ側でRokt SDK+を初期化します。SDK+は他のSDK+ API呼び出しの前に初期化する必要があります。Targetピルを使用して、iOSとAndroidを切り替えます。
AppDelegate ファイルに初期化スニペットを挿入します。your-key と your-secret を、Roktアカウントマネージャーから提供された値に置き換えてください。
registerPaymentExtension を MParticle.sharedInstance().start(with:) の後、selectShoppableAds の前に呼び出してください。これはiOSでのShoppable Ads配置に必要です。
import mParticle_Apple_SDK
import RoktPaymentExtension
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Initialize the SDK
let options = MParticleOptions(key: "your-key",
secret: "your-secret")
// 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
options.environment = .development
MParticle.sharedInstance().start(with: options)
// Register after MParticle.sharedInstance().start(), before selectShoppableAds
if let paymentExt = RoktPaymentExtension(
applePayMerchantId: "merchant.com.yourapp.rokt"
) {
MParticle.sharedInstance().rokt.registerPaymentExtension(paymentExt)
}
return true
}
初期化スニペットを挿入すると、以下のカスタマイズ可能なフィールドが表示されます:
1Entering your Rokt key and secret#
your-key と your-secret を MParticleOptions(key:secret:) に設定し、Roktアカウントマネージャーから提供された値に置き換えてください。
2Setting your data environment#
options.environment をテスト中は .development に設定してデータを開発環境にルーティングし、ライブ顧客活動を本番環境に送信するには .production に設定します。
3Registering the payment extension#
RoktPaymentExtension を MParticle.sharedInstance().start(with:) の後、selectShoppableAds の前に登録して、Shoppable Adsの支払い(Apple Payを含む)を有効にします。merchant.com.yourapp.rokt をApple PayのマーチャントIDに置き換えてください。iOSでのすべてのShoppable Ads配置に必要です。Stripeの公開可能キーはmParticle Rokt kit設定(mParticleダッシュボード)で設定されており、コードではApple PayのマーチャントIDのみを渡します。RoktPaymentExtension はSwiftタイプです。AppDelegate がObjective-Cの場合は、小さなSwiftファイルからこれを行います。
ユーザーを識別し、追加のユーザー属性を設定するには、以下のステップ3:ユーザーを識別するを参照してください。初期化時にユーザーのメールがない場合は、後でユーザーを識別できます — 身元エラーの処理についてはエラー処理を参照してください。
3. Identify the User#
SDK+初期化スクリプトは、スクリプトの identifyRequest オブジェクトで提供された識別子を使用して現在のユーザーを識別します。SDK初期化後、ユーザーがログイン、ログアウト、または識別子を提供するたびに(たとえば、チェックアウト時)、以下に説明する適切な方法を使用してユーザーの身元を同期し続ける必要があります。
サポートされているユーザー識別子サポートされているユーザー識別子 への直接リンク
サポートされているユーザー識別子を表示
| フィールド | タイプ | 説明 |
|---|---|---|
email | string | 顧客の生のハッシュされていないメールアドレスを渡します。 |
mobile | string | 顧客の電話番号をE.164形式で渡します。 |
customerid | string | 内部の顧客/アカウント識別子を渡します。ログインしているユーザーにはすべての画面で送信してください。 |
other | string | SHA-256でハッシュされたメールを渡します。生のメールを提供できない場合にのみ使用してください — email と other の両方を渡さないでください。(Androidパスのみ。) |
other2 | string | SHA-256でハッシュされた携帯番号を渡します。生の携帯番号を提供できない場合にのみ使用してください — mobile と other2 の両方を渡さないでください。(Androidパスのみ。) |
emailSha256 | string | SHA-256でハッシュされたメールを渡します。生のメールを提供できない場合にのみ使用してください — email と emailSha256 の両方を渡さないでください。(iOSパスのみ。) |
mobileSha256 | string | SHA-256でハッシュされた携帯番号を渡します。生の携帯番号を提供できない場合にのみ使用してください — mobile と mobileSha256 の両方を渡さないでください。(iOSパスのみ。) |
ユーザーを識別するには:
1Create an IdentityRequest object#
ユーザーの識別子を含む IdentityRequest オブジェクトを作成します。ユーザーの生のハッシュされていないメールアドレスを email フィールドに統合する必要があります。
2Set additional attributes via the identity callback#
追加のユーザー属性を設定するには、アイデンティティコールバックを使用します。identifyRequest が成功した場合、コールバック内で設定したユーザー属性は識別されたユーザーに割り当てられます。
3Send the request using the method that matches the user's action#
ユーザーのアクションに一致するメソッドに identifyRequest(およびオプションの identityCallback)を渡します:
MParticle.Identity.login: ユーザーがログインまたはアカウントを作成したときに呼び出します。MParticle.Identity.identify: ログイン遷移なしでセッション中にユーザーのメールを取得したときに呼び出します(例:ゲストがチェックアウト時にメールを入力する場合)。MParticle.Identity.logout: ユーザーがログアウトしたときに呼び出します。
これらのメソッドを呼び出すことで、SDKの現在のユーザーの状態の記録が遷移します。login と logout メソッドは、Roktの帰属を改善するために対応するイベントも自動的にログに記録します。
例えば、Jane Smithという名前のユーザーを j.smith@example.com というメールアドレス、+13125551515 という携帯番号、cust_10482 という顧客IDで識別するには:
// 1. Create the identifyRequest object
const request = new MParticle.IdentityRequest();
// Preferred: pass the customer's raw, unhashed email.
// If you can only provide a SHA-256-hashed email, remove .email and use other instead — do not pass both.
request.email = 'j.smith@example.com';
request.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 mobile — do not pass both.
// (Called 'other2' on Android and 'mobileSha256' on iOS; both use this same field.)
request.other2 = 'SHA-256 hashed mobile number'; // only if raw mobile unavailable
request.mobile = '+13125551515';
request.customerId = 'cust_10482';
// 2. User attributes are set using the identity callback
const identityCallback = (error, userId) => {
if (error) {
console.debug(error);
} else {
const user = new MParticle.User(userId);
user.setUserAttribute('firstname', 'Jane');
user.setUserAttribute('lastname', 'Smith');
}
};
// 3. Call one of the following methods that best matches the user's action:
MParticle.Identity.login(request, identityCallback); // Call when the user logs in or creates an account
MParticle.Identity.identify(request, identityCallback); // Call when you obtain the user's email mid-session, but not during a login
MParticle.Identity.logout({}); // Call when the user logs out
4. Set User Attributes#
ユーザーがアプリをナビゲートする際に、段階的にユーザー属性を設定します。チェックアウト時だけではありません。設定する属性が多いほど、Roktは顧客をよりよく解決し、関連するオファーを提供できます。
import MParticle from 'react-native-mparticle';
// Retrieve the current user. This will only succeed if you have identified the user during SDK+ initialization or by calling the identify method.
MParticle.Identity.getCurrentUser((currentUser) => {
if (currentUser) {
// Once you have the current user, 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.setUserAttributeArray('favorite-genres', ['documentary', 'comedy', 'romance', 'drama']);
// To remove a user attribute, call removeUserAttribute and pass in the attribute name.
currentUser.removeUserAttribute('attribute-to-remove');
}
});
ユーザー属性ユーザー属性 への直接リンク
収集できる限り多くの以下の項目を設定してください:
すべてのユーザー属性を表示
| フィールド | タイプ | 説明 |
|---|---|---|
firstname | string | 顧客の名。パーソナライズに使用されます。 |
lastname | string | 顧客の姓。パーソナライズに使用されます。 |
mobile | string | 電話番号は 1112345678 または +1 (222) 345-6789 の形式で。識別解決と関連性に使用されます。 |
age | integer | 顧客の年齢。dob の代替。適格性と関連性に使用されます。 |
dob | string | 生年月日、yyyymmdd。age の代替。適格性と関連性に使用されます。 |
gender | string | 顧客の性別。例: M、F、Male、Female。関連性に使用されます。 |
title | string | 敬称。例: Mr、Mrs、Ms。パーソナライズに使用されます。 |
language | string | 購入に関連するISO 639-1言語コード。関連性に使用されます。 |
billingcity | string | 請求先の市。関連性に使用されます。 |
billingstate | string | 請求先の州/県/地域。関連性と適格性に使用されます。 |
billingzipcode | string | 完全なZIPまたは郵便番号(米国の優先はZIP+4)。識別解決と関連性に使用されます。 |
billingaddress1 | string | 請求先の住所1行目。識別解決と関連性に使用されます。 |
billingaddress2 | string | 請求先の住所2行目。識別解決に使用されます。 |
country | string | ISO 3166-1 alpha-2国コード(例: US、GB、AU)。適格性と関連性に使用されます。 |
birthyear | integer | 顧客の生年(例: 1990)。適格性と関連性に使用されます。 |
newcustomer | boolean | 初めての購入者かどうか。関連性に使用されます。 |
customertype | string | ユーザーが認証されているかどうか(guest / logged_in)。関連性に使用されます。 |
loyaltytier | string | パートナーのロイヤルティプログラムの階層。関連性と適格性に使用されます。 |
loyaltyid | string | ロイヤルティプログラムのメンバーID。識別解決に使用されます。 |
predictedltv | decimal | 通常はパートナーの機械学習モデルからの予測される総生涯価値。関連性のために使用されます。 |
subscriptionstatus | string | 該当する場合のサブスクリプション状態 (active, trial, churned, paused, none)。関連性と適格性のために使用されます。 |
customersegment | string | パートナー内部のセグメンテーション(例: vip, at_risk, new, reactivated)。関連性のために使用されます。 |
acquisitionchannel | string | 顧客が取得されたチャネル。関連性のために使用されます。 |
すべてのユーザー属性(リスト属性を含む)は、異なる名前を持たなければなりません。
5. Track Funnel Events#
画面ビュー、コマースイベント、およびカスタムイベントを追跡し、Roktが各顧客がどの段階にいるかを理解できるようにします。
画面の名前(例: "homepage", "product_detail_page")を使用してMParticle.logScreenEvent()を呼び出します。追加のカスタム属性を情報オブジェクトに含めます。
import MParticle from 'react-native-mparticle';
MParticle.logScreenEvent('homepage', {
'custom-attribute': 'custom-value',
});
コマースイベントは、ユーザーの旅のための製品レベルの詳細を含みます。顧客が行う各製品アクションに対して別々のコマースイベントをトリガーします。
完全なコマースイベントカバレッジに投資することは、統合中にできる最も効果的なことの一つです。各イベントは、顧客がどの段階にいるかについてRoktに異なる情報を伝えます:製品ビューは探索を示し、カートへの追加は検討を示し、チェックアウト開始は購入意図を示し、購入完了はコンバージョンを確認します。より豊かなシグナルを持つことで、Roktはオファーをより効果的にパーソナライズし、配置パフォーマンスを正確に測定し、コンバージョンを正しいタッチポイントに帰属させることができます。この作業を最初の統合中に行うことで、後での改修を避けることができます。シグナルは時間とともに累積されます:Roktが受け取る各イベントは、パーソナライズを鋭くし、帰属精度を向上させ、将来の訪問で顧客ベースをより良く解決およびセグメント化するために使用されるコンテキストを追加します。
コマースイベントは、顧客のアクション(製品の閲覧、カートへの追加、チェックアウトの開始、購入の完了など)を識別する製品アクションタイプを使用してMParticle.CommerceEvent.createProductActionEventでログされます。
すべての製品アクションタイプを表示
| 顧客のアクション | 製品アクションタイプ |
|---|---|
| 製品詳細ページが表示された | MParticle.ProductActionType.ViewDetail |
| 製品がクリックされた | MParticle.ProductActionType.Click |
| アイテムがカートに追加された | MParticle.ProductActionType.AddToCart |
| アイテムがカートから削除された | MParticle.ProductActionType.RemoveFromCart |
| アイテムがウィッシュリストに追加された | MParticle.ProductActionType.AddToWishlist |
| アイテムがウィッシュリストから削除された | MParticle.ProductActionType.RemoveFromWishlist |
| チェックアウトフローが開始された | MParticle.ProductActionType.Checkout |
| チェックアウトオプションが選択された | MParticle.ProductActionType.CheckoutOption |
| 注文が確認された | MParticle.ProductActionType.Purchase |
| 注文が返金された | MParticle.ProductActionType.Refund |
コマースイベントを追跡するには、3つのフェーズがあります:
1Define the product#
製品の名前、SKU、価格、数量を含む MParticle.Product を作成します。category、brand、position などの追加フィールドをインスタンスに直接設定します。
const product = new MParticle.Product(
'Double Room - Econ Rate',
'econ-1',
100.00,
4
);
product.category = 'room';
product.brand = 'lodge-o-rama';
product.variant = 'standard';
2Summarize the transaction#
MParticle.TransactionAttributes を Purchase、Checkout、CheckoutOption イベント用に作成します。適用可能な場合は、配送と注文レベルのクーポンを含めます。注文レベルのクーポンは、個々の製品ではなくここに属します。
const transactionAttributes = new MParticle.TransactionAttributes('ORDER-12345')
.setRevenue(149.99)
.setTax(12.50)
.setShipping(5.99)
.setCouponCode('SUMMER20');
3Log the commerce event#
製品アクションタイプ、製品(複数可)、および(適用可能な場合)transactionAttributes を渡して MParticle.CommerceEvent.createProductActionEvent を使用してコマースイベントを構築します。その後、MParticle.logCommerceEvent を呼び出します。ログに記録したい顧客アクションを選択します:
製品リスト(またはカテゴリ)ページビューを製品インプレッションとしてログに記録します。すべての表示されている製品を単一の呼び出しで渡し、インプレッションの名前をリスト/カテゴリ名に設定します(Rokt はこれを listname として使用します)。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
Name | string | yes | リストまたはカテゴリ名(例: "Mens Running Shoes")。listname になります。 |
Products | array | yes | MParticle.Product からの製品オブジェクト。各アイテムの position を1から始まるランクに設定します。 |
currency | string | yes | ISO 4217 通貨コード(イベントレベルの customAttribute として渡されます)。 |
import MParticle from 'react-native-mparticle';
const product = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
product.position = 1; // 1-indexed rank in the list
const impression = new MParticle.Impression('Mens Running Shoes', [product]);
const commerceEvent = MParticle.CommerceEvent.createImpressionEvent([impression]);
commerceEvent.currency = 'USD';
MParticle.logCommerceEvent(commerceEvent);
顧客が製品詳細ページを開いたときにログを記録します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
productsku | string | yes | 製品 SKU。 |
productname | string | yes | 表示名。 |
itemprice | decimal | yes | 表示時の単価。 |
currency | string | yes | ISO 4217 通貨コード。 |
listname | string | no | ユーザーが PLP から来た場合に設定。 |
import MParticle from 'react-native-mparticle';
const product = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.ViewDetail,
[product],
);
commerceEvent.currency = 'USD';
commerceEvent.customAttributes = { 'listname': 'PLP-Running' };
MParticle.logCommerceEvent(commerceEvent);
顧客がカートにアイテムを追加したときにログを記録します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
productsku | string | yes | 製品 SKU。 |
quantity | integer | yes | 追加された単位。 |
itemprice | decimal | yes | 追加時の単価。 |
currency | string | yes | ISO 4217 通貨コード。 |
couponCode | string | no | 追加時に適用された注文レベルのクーポン。 |
import MParticle from 'react-native-mparticle';
const product = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.AddToCart,
[product],
);
commerceEvent.currency = 'USD';
MParticle.logCommerceEvent(commerceEvent);
顧客がカートからアイテムを削除したときにログを記録します。
| Field | Type | Required | Description |
|---|---|---|---|
productsku | string | yes | 製品SKU. |
quantity | integer | yes | 削除された単位数. |
currency | string | yes | ISO 4217通貨コード. |
import MParticle from 'react-native-mparticle';
const product = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.RemoveFromCart,
[product],
);
commerceEvent.currency = 'USD';
MParticle.logCommerceEvent(commerceEvent);
顧客がカートページに到着したときにログを記録します。カートページビューにはネイティブのProductActionTypeがないため、イベント名"view_cart"とイベントタイプOtherを使用してMParticle.Eventを使用します。カスタム属性としてカートの内容全体を渡します。
| Field | Type | Required | Description |
|---|---|---|---|
event_name | string | yes | 常に"view_cart". |
event_type | EventType | yes | MParticle.EventType.Otherを使用します。 |
cartitems | string | 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. |
import MParticle from 'react-native-mparticle';
const 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 },
];
const event = new MParticle.Event()
.setName('view_cart')
.setType(MParticle.EventType.Other)
.setInfo({
cartitemcount: 3,
totalprice: 169.85,
currency: 'USD',
couponcode: 'SUMMER20',
cartitems: JSON.stringify(cartitems),
});
MParticle.logMPEvent(event);
顧客がチェックアウトフローに入ったときにログを記録します。カートの合計と注文レベルのクーポンをカバーするトランザクション概要とともに、すべてのカート製品を送信します。
| Field | Type | Required | Description |
|---|---|---|---|
cartitems | array | yes | カートの内容全体。 |
totalprice | decimal | yes | 税/送料前のカート合計。 |
cartitemcount | integer | yes | カートラインの数。 |
currency | string | yes | ISO 4217通貨コード。 |
couponCode | string | no | 適用された場合の注文レベルのプロモーション。 |
import MParticle from 'react-native-mparticle';
const product1 = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const product2 = new MParticle.Product('Cushion Insole', 'SKU-002', 19.95, 2);
const transactionAttributes = new MParticle.TransactionAttributes('YOUR_CHECKOUT_ID')
.setRevenue(169.85)
.setCouponCode('SUMMER20');
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.Checkout,
[product1, product2],
transactionAttributes,
);
commerceEvent.currency = 'USD';
commerceEvent.customAttributes = { cartitemcount: 3 };
MParticle.logCommerceEvent(commerceEvent);
顧客が配送ステップを完了したときにログを記録します。checkoutOptionを"shipping"に設定し、配送選択をカスタム属性として渡します。
| Field | Type | Required | Description |
|---|---|---|---|
cartitems | array | yes | カートの内容全体。 |
option | string | yes | このイベントでは常に"shipping"です。 |
shippingmethod | string | yes | standard / express / next_day. |
zipcode | string | yes | 配送ZIP/郵便番号。 |
country | string | yes | ISO 3166-1 alpha-2国コード。 |
totalprice | decimal | yes | カートの合計。 |
currency | string | yes | ISO 4217通貨コード。 |
import MParticle from 'react-native-mparticle';
const product1 = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const product2 = new MParticle.Product('Cushion Insole', 'SKU-002', 19.95, 2);
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.CheckoutOption,
[product1, product2],
);
commerceEvent.setCheckoutOptions('shipping');
commerceEvent.currency = 'USD';
commerceEvent.customAttributes = {
shippingmethod: 'express',
zipcode: '94103',
country: 'US',
totalprice: 169.85,
};
MParticle.logCommerceEvent(commerceEvent);
顧客が支払いステップを完了したときにログを記録します。checkoutOption を "payment" に設定し、選択された支払い方法をカスタム属性として渡します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
cartitems | array | yes | カートの全内容。 |
option | string | yes | このイベントでは常に "payment"。 |
paymenttype | string | yes | credit_card / paypal / apple_pay / その他。 |
payment_method | string | no | 関連する場合の特定の方法(例:カードブランド)。 |
paymentServiceProvider | string | no | PSP識別子(例:stripe)。キャメルケースでなければなりません。 |
ccbin | string | no | カードが使用された場合の最初の6-8桁。 |
totalprice | decimal | yes | カートの合計。 |
currency | string | yes | ISO 4217通貨コード。 |
import MParticle from 'react-native-mparticle';
const product1 = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const product2 = new MParticle.Product('Cushion Insole', 'SKU-002', 19.95, 2);
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.CheckoutOption,
[product1, product2],
);
commerceEvent.setCheckoutOptions('payment');
commerceEvent.currency = 'USD';
commerceEvent.customAttributes = {
paymenttype: 'credit_card',
payment_method: 'visa',
paymentServiceProvider: 'stripe',
ccbin: '424242',
totalprice: 169.85,
};
MParticle.logCommerceEvent(commerceEvent);
注文が確認されたときにログを記録します。注文、収益、税金、送料、および注文レベルのクーポンを識別するトランザクションサマリーとともに、カート全体を送信します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
cartitems | array | yes | 注文時のカートの全内容。 |
transactionId | string | yes | 注文/トランザクション識別子。 |
totalprice | decimal | yes | 注文合計(収益)。 |
tax | decimal | yes | 注文の総税額。 |
shipping | decimal | yes | 送料。 |
currency | string | yes | ISO 4217通貨コード。 |
couponCode | string | no | 適用された場合の注文レベルのプロモーション。 |
cartitemcount | integer | no | カートラインの数。 |
import MParticle from 'react-native-mparticle';
const product1 = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const product2 = new MParticle.Product('Cushion Insole', 'SKU-002', 19.95, 2);
const transactionAttributes = new MParticle.TransactionAttributes('ORDER-10482')
.setRevenue(169.85)
.setTax(14.20)
.setShipping(5.99)
.setCouponCode('SUMMER20');
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.Purchase,
[product1, product2],
transactionAttributes,
);
commerceEvent.currency = 'USD';
commerceEvent.customAttributes = { cartitemcount: 3 };
MParticle.logCommerceEvent(commerceEvent);
注文(またはその中のライン)が返金されたときにログを記録します。返金される製品のみを送信し、元の注文IDを参照するトランザクションサマリーを送信します。
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
productsku | string | yes | 返金されたラインのSKU。 |
quantity | integer | yes | 返金された単位数。 |
transactionId | string | yes | 返金対象の元の注文ID。 |
totalprice | decimal | yes | 返金額。 |
currency | string | yes | ISO 4217通貨コード。 |
import MParticle from 'react-native-mparticle';
const refundedProduct = new MParticle.Product('Trail Runner v3', 'SKU-001', 129.95, 1);
const transactionAttributes = new MParticle.TransactionAttributes('ORDER-10482') // original order id
.setRevenue(129.95); // refunded amount
const commerceEvent = MParticle.CommerceEvent.createProductActionEvent(
MParticle.ProductActionType.Refund,
[refundedProduct],
transactionAttributes,
);
commerceEvent.currency = 'USD';
MParticle.logCommerceEvent(commerceEvent);
カスタムイベントを MParticle.Event を使用して追跡し、イベント名、イベントタイプ、およびオプションのカスタム属性を渡します。
カスタムイベントタイプを表示
| 種類 | 使用目的 |
|---|---|
MParticle.EventType.Navigation | アプリ内でのユーザーのナビゲーションフローや画面遷移。 |
MParticle.EventType.Location | 位置情報に基づくインタラクションや移動。 |
MParticle.EventType.Search | 検索クエリや検索関連のアクション。 |
MParticle.EventType.Transaction | 金融取引や購入関連の活動。 |
MParticle.EventType.UserContent | レビュー、コメント、投稿などのユーザー生成コンテンツ。 |
MParticle.EventType.UserPreference | ユーザー設定、好み、カスタマイズの選択。 |
MParticle.EventType.Social | ソーシャルメディアのインタラクションや共有活動。 |
MParticle.EventType.Other | 上記のカテゴリに当てはまらないもの。 |
import MParticle from 'react-native-mparticle';
const event = new MParticle.Event()
.setName('video_watched')
.setType(MParticle.EventType.Navigation)
.setInfo({ category: 'Destination Intro', title: 'Paris' });
MParticle.logMPEvent(event);
6. Show a Placement#
Roktがコンテンツを表示する支払い画面や確認画面ごとに、selectPlacementsを呼び出します。画面タイプとテストまたは本番環境であるかを指定するために、次のページ識別子のいずれかを含めます:
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.
画面が読み込まれるとすぐに、すべての関連属性が利用可能になったらselectPlacementsを呼び出します。最低限、email、firstname、lastname、billingzipcode、およびconfirmationrefを渡します。完全なリストはPlacement attributesを参照してください。
Pay+配置の場合、各画面でのselectPlacements呼び出しにpaymenttypeとpaymentServiceProviderを含めます。paymentServiceProviderは支払い画面で利用可能な支払い方法を伝え、paymenttypeはユーザーが支払った方法を伝えます。
配置属性配置属性 への直接リンク
これらの属性を 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 | string | 税金と送料を除くカート小計。totalprice とは異なります。関連性に使用されます。 |
couponCode | string | 注文に適用されたプロモーションコード(ある場合)。関連性に使用されます。 |
newcustomer | boolean | 初めての購入者かどうか。関連性に使用されます。 |
customertype | string | guest または logged_in。関連性に使用されます。 |
value | decimal | 顧客の累積購入額(例: "2340.00")。関連性に使用されます。 |
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桁)。関連性のために使用されます。 |
billingname | string | 請求名。アイデンティティ解決に使用されます。 |
billingaddress1 | string | 請求先の住所。アイデンティティ解決と関連性に使用されます。 |
billingaddress2 | string | 請求先のアパート/ユニット。アイデンティティ解決に使用されます。 |
billingcity | string | 請求先の市区町村。関連性のために使用されます。 |
billingstate | string | 請求先の州または省。関連性のために使用されます。 |
billingzipcode | string | 請求先の郵便番号/郵便コード。アイデンティティ解決と関連性に使用されます。 |
shippingmethod | string | 選択された配送方法(standard、express、next_day)。関連性のために使用されます。 |
shippingname | string | 配送名。関連性のために使用されます。 |
shippingaddress1 | string | 配送先の住所。関連性のために使用されます。 |
shippingcity | string | 配送先の市区町村。関連性のために使用されます。 |
shippingstate | string | 配送先の州または省。関連性のために使用されます。 |
shippingzipcode | string | 配送先の郵便番号または郵便コード。関連性のために使用されます。 |
shippingcountry | string | 配送先の国(ISO 3166-1 alpha-2)。関連性のために使用されます。 |
cartItems | array | カートラインオブジェクトの構造化された配列。関連性のために使用されます。 |
adsexperience | string | Shoppable Adsのエクスペリエンスを意図的にターゲットにする場合は"shoppable"を渡します。 |
オーバーレイプレースメントは、Roktが管理するコンテナ内で確認画面の上にレンダリングされ、アプリの既存のレイアウトに変更を加える必要はありません。
オーバーレイプレースメントを挿入するには、確認画面が読み込まれたらselectPlacementsを呼び出します:
import MParticle from 'react-native-mparticle';
const attributes = {
// Identity
'email': 'j.smith@example.com',
'firstname': 'Jenny',
'lastname': 'Smith',
'mobile': '+13125551515',
// Transaction
'confirmationref': '54321',
'currency': 'USD',
'country': 'US',
'language': 'en',
'totalprice': '149.99',
'couponCode': 'SUMMER20',
// Customer context
'newcustomer': 'false',
'customertype': 'logged_in',
'value': '2340.00',
'subscriptionstatus': 'active',
'customersegment': 'vip',
// Payment (include paymenttype and paymentServiceProvider for Pay+)
'paymenttype': 'credit_card',
'paymentServiceProvider': 'cardpayment',
'ccbin': '411112',
// Billing address
'billingaddress1': '123 Main St',
'billingcity': 'Brooklyn',
'billingstate': 'NY',
'billingzipcode': '11201',
// Shipping
'shippingmethod': 'express',
'shippingaddress1': '175 Varick St',
'shippingcity': 'New York',
'shippingstate': 'NY',
'shippingzipcode': '10014',
'shippingcountry': 'US',
};
const roktConfig = MParticle.Rokt.createRoktConfig('light');
MParticle.Rokt.selectPlacements(
'RoktExperience', // identifier
attributes, // attributes map
{}, // placeholders (empty for overlay)
roktConfig, // configuration
);
埋め込みプレースメントは、アプリ内の固定位置にインラインでレンダリングされ、ユーザーが制御します(例: カート画面の支払いオプションの上)。ThanksとPay+の両方が埋め込みプレースメントを使用しますが、Pay+は埋め込みプレースメントを使用する必要があります。
1Add RoktLayoutView to your view hierarchy#
画面にRoktLayoutViewを配置し、プレースメントをレンダリングしたい位置に設置します。refを保持して、selectPlacementsを呼び出す際にネイティブノードハンドルを解決できるようにします。
2Resolve the node handle and call selectPlacements#
findNodeHandleを使ってネイティブノードハンドルを解決し、属性を構築してplaceholdersをselectPlacementsに渡します。埋め込み画面がオファーを表示する準備ができたときにこれをトリガーします。
import React, { ComponentRef } from 'react';
import { findNodeHandle } from 'react-native';
import MParticle, { RoktLayoutView } from 'react-native-mparticle';
const placeholder1 = React.createRef<ComponentRef<typeof RoktLayoutView>>();
const showRoktLayout = () => {
const placeholders = {
RoktEmbedded1: findNodeHandle(placeholder1.current),
};
const attributes = {
'email': 'j.smith@example.com',
'firstname': 'Jenny',
'lastname': 'Smith',
'billingzipcode': '90210',
'confirmationref': '54321',
};
MParticle.Rokt.selectPlacements(
'RoktExperience',
attributes,
placeholders,
);
};
// Integrate the RoktLayoutView in the view hierarchy
<RoktLayoutView ref={placeholder1} placeholderName="RoktEmbedded1" />
ノードハンドルを手動で管理せずにRoktLayoutViewコンポーネントを使用する宣言的アプローチについては、Appendix B: RoktLayoutView componentを参照してください。
Pay+プレースメントの場合、各画面でのselectPlacements呼び出しにpaymenttypeとpaymentServiceProviderを含めます。paymentServiceProviderは支払い画面で利用可能な支払い方法を伝え、paymenttypeはユーザーが支払った方法を伝えます。
インタースティシャルプレースメントは、支払い画面と確認画面の間にレンダリングされ、顧客が追加の製品を購入できるようにします。インタースティシャルプレースメントはShoppable Adsによって使用されます。
インタースティシャルプレースメントは、React Native SDK+でiOSのみサポートされています。このSDK+のAndroidパスはインタースティシャルプレースメントをサポートしていません。以下のコードは、アプリのiOSパスでのみ呼び出す必要があります。
iOSでインタースティシャルプレースメントを有効にするには、まずiOS固有のセットアップが完了していることを確認します:
- iOSアプリ用にApple Payを設定します — Apple Pay商人IDを作成し、Xcodeプロジェクトを設定し、Apple Pay — iOS setupに従って支払い処理証明書を生成します。
RoktPaymentExtensionをReact Native iOSのAppDelegateに登録します。これは、MParticle.sharedInstance().start()の後、selectShoppableAdsの前に行います。登録スニペットは、iOS initialization code in Step 2に含まれています。支払い拡張が登録されていない場合、Shoppable AdsはPlacementFailureイベントを発生させることがあります。
Expoを使用する場合、Roktキットを設定プラグインに含めます(例:iosKits: ["mParticle-Rokt"]をapp.jsonに)。設定プラグインは支払い拡張の登録を自動的に追加しません — expo prebuildの後、生成されたAppDelegateにmParticle初期化と同じ起動パスに追加し、--cleanでネイティブプロジェクトを再生成する場合は再適用します。
その後、確認画面の識別子を使ってReact Native JavaScriptレイヤーからselectShoppableAdsを呼び出します。このメソッドはPromiseを返し、Shoppable Adsの体験をオーバーレイとしてレンダリングします — 埋め込みプレースホルダーは必要ありません。iOSでは、適格なオファーが利用可能な場合にSDK+がそれをレンダリングします。
import { Platform } from 'react-native';
import MParticle from 'react-native-mparticle';
// Interstitial placements are iOS only — do not invoke on Android
if (Platform.OS === 'ios') {
const attributes = {
// Identity
'email': 'j.smith@example.com',
'firstname': 'Jenny',
'lastname': 'Smith',
'mobile': '+13125551515',
// Transaction
'confirmationref': '54321',
'currency': 'USD',
'country': 'US',
'language': 'en',
'totalprice': '149.99',
'amount': '137.50',
// Customer context
'newcustomer': 'false',
'customertype': 'logged_in',
'value': '2340.00',
// Payment
'paymenttype': 'credit_card',
'paymentServiceProvider': 'cardpayment',
'ccbin': '411112',
// Billing address
'billingaddress1': '123 Main St',
'billingcity': 'Brooklyn',
'billingstate': 'NY',
'billingzipcode': '11201',
// Shipping (required for Shoppable Ads order fulfillment)
'shippingaddress1': '175 Varick St',
'shippingcity': 'New York',
'shippingstate': 'NY',
'shippingzipcode': '10014',
'shippingcountry': 'US',
};
const roktConfig = MParticle.Rokt.createRoktConfig('system');
// selectShoppableAds returns a Promise; listen for native Rokt events for purchase outcomes
MParticle.Rokt.selectShoppableAds(
'prod.rokt.conf', // use 'stg.rokt.conf' in test environments
attributes,
roktConfig,
).catch((error) => console.debug(error));
}
インタースティシャル体験から開始された購入フローを処理するために、Events APIを介してCartItemInstantPurchaseおよび関連するShoppable Adsイベントを購読します。
オプションの関数オプションの関数 への直接リンク
| 関数 | 目的 |
|---|---|
MParticle.Rokt.close() | オーバーレイプレースメントを自動的に閉じる。 |
追加の設定追加の設定 への直接リンク
オプションのパラメータとしてRoktConfigを渡して、プレースメントUIをカスタマイズします(例:ダーク/ライトモード、キャッシング)。
import MParticle from 'react-native-mparticle';
const roktConfig = MParticle.Rokt.createRoktConfig(
'light',
MParticle.Rokt.createCacheConfig(1200, { 'email': 'j.smith@example.com', 'orderNumber': '123' }),
);
MParticle.Rokt.selectPlacements(
'RoktExperience',
attributes,
{},
roktConfig,
);
識別子RoktExperienceまたは埋め込み識別子RoktEmbedded1を異なる値に更新したい場合は、Roktアカウントマネージャーに連絡して、Roktプレースメントが一貫して設定されていることを確認してください。
Events APIEvents API への直接リンク
SDK+は、NativeEventEmitterメカニズムを通じてプレースメントのライフサイクルイベントを提供します。
import { NativeEventEmitter } from 'react-native';
import MParticle from 'react-native-mparticle';
const eventManagerEmitter = new NativeEventEmitter(MParticle.RoktEventManager);
eventManagerEmitter.addListener('RoktEvents', data => {
console.log(`event received ${JSON.stringify(data)}`);
});
標準イベント標準イベント への直接リンク
すべての標準イベントを表示
| イベント | 説明 | パラメータ |
|---|---|---|
| ShowLoadingIndicator | SDK+がRoktバックエンドを呼び出す前にトリガーされます。 | |
| HideLoadingIndicator | SDK+がRoktバックエンドからの成功または失敗を受け取ったときにトリガーされます。 | |
| PlacementInteractive | プレースメントがレンダリングされ、操作可能になったときにトリガーされます。 | placementId: String |
| PlacementReady | プレースメントが表示準備ができたが、まだコンテンツがレンダリングされていないときにトリガーされます。 | placementId: String |
| OfferEngagement | ユーザーがオファーに関与したときにトリガーされます。 | placementId: String |
| PositiveEngagement | ユーザーがオファーに積極的に関与したときにトリガーされます。 | placementId: String |
| FirstPositiveEngagement | ユーザーが初めてオファーに積極的に関与したときにトリガーされます。 | placementId: String |
| OpenUrl | ユーザーがパートナーアプリに送信するように設定されたURLを押したときにトリガーされます。 | placementId: String, url: String |
| PlacementClosed | ユーザーによってプレースメントが閉じられたときにトリガーされます。 | placementId: String |
| PlacementCompleted | オファーの進行が終了し、表示するオファーがもうない場合にトリガーされます。また、キャッシュがヒットしたが、以前に却下されたために取得されたプレースメントが表示されない場合にもトリガーされます。 | placementId: String |
| PlacementFailure | プレースメントが何らかの失敗により表示できなかった場合、または表示するプレースメントがない場合にトリガーされます。 | placementId: String (optional) |
| CartItemInstantPurchase | カタログアイテムの購入がユーザーによって開始されたときにトリガーされます(iOSのみ)。 | placementId: String, cartItemId: String, catalogItemId: String, currency: String, description: String, linkedProductId: String, totalPrice: number, quantity: number, unitPrice: number |
7. Appendix#
Appendix A: アプリケーション設定Appendix A: アプリケーション設定 への直接リンク
アプリケーションは、RoktConfig を通じて設定を渡すことで、SDK+がシステムのデフォルトではなく、アプリのカスタム設定を使用するようにできます。
ColorMode オブジェクトColorMode オブジェクト への直接リンク
| 値 | 説明 |
|---|---|
light | アプリケーションはライトモードです |
dark | アプリケーションはダークモードです |
system | アプリケーションはシステムのカラーモードをデフォルトとします |
EdgeToEdgeDisplay (Androidのみ)EdgeToEdgeDisplay (Androidのみ) への直接リンク
このブール値は、Rokt SDK+がAndroidでエッジツーエッジのディスプレイモードでレンダリングするかどうかを制御します(デフォルトは true)。アプリがエッジツーエッジのディスプレイをサポートしていない場合は、false に設定します。
import com.mparticle.rokt.RoktConfig
val roktConfig = RoktConfig.Builder()
.edgeToEdgeDisplay(true)
.build()
CacheConfig オブジェクトCacheConfig オブジェクト への直接リンク
| パラメータ | 説明 |
|---|---|
cacheDuration | Rokt SDK+がエクスペリエンスをキャッシュする秒単位のオプションの期間です。許可される最大値は90分です。提供されないか無効な場合、デフォルトは90分です。 |
cacheAttributes | キャッシュキーとして使用するオプションの属性です。nullの場合、selectPlacements で送信されたすべての属性がキャッシュキーとして使用されます。 |
import MParticle from 'react-native-mparticle';
// Cache the experience for 1200 seconds, using email and orderNumber as the cache key.
const roktConfig = MParticle.Rokt.createRoktConfig(
'light',
MParticle.Rokt.createCacheConfig(
1200,
{ 'email': 'j.smith@example.com', 'orderNumber': '123' }
),
);
MParticle.Rokt.selectPlacements(
'RoktExperience',
attributes,
{},
roktConfig,
);
Appendix B: RoktLayoutView コンポーネントAppendix B: RoktLayoutView コンポーネント への直接リンク
埋め込みプレースメントの場合、React Native SDK+は RoktLayoutView コンポーネントを提供し、アプリのビュー階層にRoktプレースメントを統合するための宣言的アプローチを提供します。RoktLayoutView は、ノードハンドルを手動で管理する必要なく、埋め込みプレースメントタイプをサポートします。
import React from 'react';
import { findNodeHandle, View } from 'react-native';
import MParticle, { RoktLayoutView } from 'react-native-mparticle';
const MyConfirmationScreen = () => {
const placeholder1 = React.createRef();
const handleSelectPlacements = () => {
const placeholders = {
RoktEmbedded1: findNodeHandle(placeholder1.current),
};
const attributes = {
'email': 'j.smith@example.com',
'firstname': 'Jenny',
'lastname': 'Smith',
'billingzipcode': '90210',
'confirmationref': '54321',
};
MParticle.Rokt.selectPlacements(
'RoktExperience',
attributes,
placeholders,
);
};
return (
<View>
{/* Your confirmation screen content */}
<RoktLayoutView ref={placeholder1} placeholderName="RoktEmbedded1" />
</View>
);
};
パラメータパラメータ への直接リンク
| パラメータ | 型 | 説明 |
|---|---|---|
ref | Ref | プレースホルダーマップのネイティブノードハンドルを取得するために使用されるReact refです。 |
placeholderName | string | 埋め込みビューの識別子(例: "RoktEmbedded1")、selectPlacements に渡されるプレースホルダーマップのキーと一致する必要があります。 |
Appendix C: エラーハンドリングAppendix C: エラーハンドリング への直接リンク
IDSync APIはアプリの状態において中心的な役割を果たすことを目的としており、高速かつ高可用性を備えています。アプリがインターネット接続なしでユーザーのログイン、ログアウト、または状態の変更を防ぐのと同様に、これらのAPIをゲート操作として扱い、一貫したユーザー状態を維持してください。SDK+はAPIコールを自動的に再試行しませんが、ビジネスロジックに従って再試行できるようにコールバックAPIを提供します。
エラーハンドリングを実装しない場合、大規模なデータの一貫性の問題が発生する可能性があります。
import MParticle from 'react-native-mparticle';
const request = new MParticle.IdentityRequest();
request.email = 'j.smith@example.com';
MParticle.Identity.identify(request, (error, userId) => {
if (error) {
// Inspect error.code to determine the cause:
// - Network errors: retry the request
// - Throttle errors (429): retry with backoff
console.debug('Identity error:', error);
} else {
// Proceed with the identified user
const user = new MParticle.User(userId);
user.setUserAttribute('firstname', 'Jane');
}
});
iOS エラーコードiOS エラーコード への直接リンク
iOSでは、ネイティブのMPIdentityErrorResponseCode列挙型が以下のクライアント側コードを定義しています。原因を特定するために、ネイティブのonIdentifyCompleteコールバックでerror.codeを確認してください:
MPIdentityErrorResponseCode | 説明 |
|---|---|
MPIdentityErrorResponseCodeRequestInProgress | IDSync HTTPリクエストは、すでに進行中のため実行されませんでした。 |
MPIdentityErrorResponseCodeClientSideTimeout | TCP接続のタイムアウトによりIDSync HTTPリクエストが失敗しました。 |
MPIdentityErrorResponseCodeClientNoConnection | ネットワークカバレッジの不足によりIDSync HTTPリクエストが失敗しました。 |
MPIdentityErrorResponseCodeSSLError | SSL設定の問題によりIDSync HTTPリクエストが失敗しました。 |
MPIdentityErrorResponseCodeOptOut | オプトアウトのためSDK+が無効になっているためIDSync HTTPリクエストは実行されませんでした。 |
MPIdentityErrorResponseCodeUnknown | 不明なエラーによりIDSync HTTPリクエストが失敗しました。 |
上記のクライアント側コードに加えて、error.codeにはサーバー生成のHTTPステータスコードが含まれる場合があります:
| 値 | 説明 |
|---|---|
| 400 | 無効なリクエストボディによりIDSync HTTPコールが失敗しました。エラーの詳細を確認してください。 |
| 401 | 認証エラーによりIDSync HTTPコールが失敗しました。APIキーが正しいことを確認してください。 |
| 403 | この操作がアカウントに対してプロビジョニングされていないためIDSync HTTPコールが失敗しました。Roktアカウントマネージャーに連絡して有効にしてください。 |
| 429 | IDSync HTTPコールがスロットルされ、指数バックオフで再試行する必要があります。これはユーザーの「ホットキー」または予想以上のIDSyncボリュームを引き起こす不正な実装を示している可能性があります。 |
| 5xx | Roktサーバー側の問題によりIDSync HTTPコールが失敗しました。詳細についてはアカウント担当者に連絡してください。 |
Android エラーコードAndroid エラーコード への直接リンク
Androidでは、IDSync APIは常に基礎となるHTTPレスポンスのHTTPステータスコードとボディを返します。クライアント側の失敗(デバイスのオフライン、タイムアウト、無効なリクエスト)の場合、SDK+はIdentityApi.UNKNOWN_ERRORを返します。スロットリング(HTTP 429)の場合、IdentityApi.THROTTLE_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
}
}
Appendix D: WebからネイティブへのセッションIDの受け渡しAppendix D: WebからネイティブへのセッションIDの受け渡し への直接リンク
ユーザーの操作がウェブとネイティブプラットフォームの両方にまたがる場合、Web SDK+からReact Native 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を抽出し、React Nativeレイヤーがロードされる前に、SDK+に渡してからselectPlacementsを呼び出します。これをネイティブのAppDelegate(iOS)またはActivity(Android)で処理します:
import { Linking } from 'react-native';
import MParticle from 'react-native-mparticle';
// Listen for incoming deep links
Linking.addEventListener('url', ({ url }) => {
const sessionId = new URL(url).searchParams.get('sessionId');
if (sessionId) {
void MParticle.Rokt.setSessionId(sessionId);
}
});
注意事項注意事項 への直接リンク
- セッションが使用されるように、
setSessionIdをselectPlacementsの前に呼び出してください。 - 空の文字列は無視され、セッションは更新されません。
- クエリパラメータとして渡す際には、常にセッションIDをURLエンコードしてください。
8. Test Your Integration#
SDK+が正しく初期化され、イベントがログに記録されることを確認するには:
1Enable verbose SDK+ logging#
初期化前に詳細なSDK+ログを有効にして、送信されている内容を確認できるようにします。
// For iOS verbose logging, add to your Swift AppDelegate:
// MParticle.sharedInstance().logLevel = .verbose
// For Android verbose logging, add to your Application class before MParticle.start():
// MParticle.setLogLevel(MParticle.LogLevel.VERBOSE)
2Build and run against a development key#
環境をDevelopmentに設定してアプリをビルドおよび実行します。
3Trigger selectPlacements#
配置がレンダリングされるべき画面でselectPlacementsをトリガーし、配置がロードされることを確認します。
4Verify events#
イベントがログに記録され、identifyRequest呼び出しが成功することを確認します。
トラブルシューティングトラブルシューティング への直接リンク
プレースメントがレンダリングされない、またはイベントが表示されない場合は、Rokt SDK+ エラーについてネイティブコンソール(iOSの場合はXcode、Androidの場合はLogcat)を確認してください。一般的な問題は次のとおりです:
初期化エラー初期化エラー への直接リンク
- ネイティブ初期化で使用しているキーとシークレットが、Roktアカウントマネージャーから提供された値と一致していることを確認してください。
- ネイティブSDK+の
start呼び出しが、selectPlacementsやイベントログの呼び出しの前に実行されていることを確認してください。 - iOSのショッパブル広告の場合、
RoktPaymentExtensionがstart()の後、selectShoppableAdsの前に登録されていることを確認してください。
アイデンティティエラーアイデンティティエラー への直接リンク
アイデンティティコールバックがエラーとともに発生した場合、エラーコードとリトライガイダンスについては エラーハンドリング を参照してください。エラーハンドリングがないと、大規模なデータ整合性の問題が発生する可能性があります。
プレースメントがレンダリングされないプレースメントがレンダリングされない への直接リンク
- プレースメントの
identifier(例:RoktExperience)が、Roktアカウントマネージャーが設定したものと一致していることを確認してください。 - 埋め込みプレースメントの場合、埋め込みビューの識別子(例:
RoktEmbedded1)がplaceholderNameとRoktLayoutViewコンポーネントで一致していることを確認してください。 - 属性マップに少なくとも
email、firstname、lastname、billingzipcode、およびconfirmationrefが含まれていることを確認してください。 - インタースティシャルプレースメントの場合、
Platform.OS === 'ios'を確認してからselectShoppableAdsを呼び出してください — インタースティシャルプレースメントはAndroidではサポートされていません。