基本機能の移行

基本機能の移行 #

SDKの初期化 #

主な変更点 #

  • setup メソッドのパラメータが変更になりました。また、パラメータ指定方式にはビルダーパターンが採用されています。
  • setSiteHostName は廃止され、契約ドメインの設定は setup パラメータに組み込まれました。

サンプルコード #

v5.0 #

try Rtoaster.setup(RtoasterSetupParameter.Builder()
    .trackingId("RTA-xxxx-xxxxxxxxxxxx")
    .password("abcdefghijkl")
    .defaultConnectionAuthorizationStatus(.authorized)
    .hostName("https://www.brainpad.co.jp")
    .build()
)

v4.x #

Rtoaster.setup(
    withAccountId: "RTA-xxxx-xxxxxxxxxxxx",
    basicUsername: "RTA-xxxx-xxxxxxxxxxxx",
    basicPassword: "abcdefghijkl",
    pushEnvironmentType: PushDisabled,
    defaultAuthorizationStatus: RtoasterAuthorizationStatusAuthorized
)

v5.0 #

Rtoaster.setup(RtoasterSetupParameter {
    application(this)
    trackingId("RTA-xxxx-xxxxxxxxxxxx")
    password("abcdefghijkl")
    defaultConnectionAuthorizationStatus(Rtoaster.ConnectionAuthorizationStatus.Authorized)
    hostName("https://www.brainpad.co.jp")
})

v4.x #

Rtoaster.setup(
    this,
    "RTA-xxxx-xxxxxxxxxxxx",
    "RTA-xxxx-xxxxxxxxxxxx",
    "abcdefghijkl",
    Rtoaster.PushEnvironmentType.Disabled,
    Rtoaster.AuthorizationStatus.Authorized
)

ユーザーIDの設定・取得 #

主な変更点 #

  • メソッド名が変更になりました。

サンプルコード #

v5.0 #

// ユーザ−IDの設定
try Rtoaster.setUserId("USER_ID")

// ユーザーIDの取得
let userId = try Rtoaster.userId

v4.x #

// ユーザ−IDの設定
Rtoaster.setMemberId("USER_ID")

// ユーザーIDの取得
let userId = Rtoaster.getMemberId()

v5.0 #

// ユーザ−IDの設定
Rtoaster.setUserId("USER_ID")

// ユーザーIDの取得
val userId = Rtoaster.userId

v4.x #

// ユーザ−IDの設定
Rtoaster.setMemberId("USER_ID")

// ユーザーIDの取得
val userId = Rtoaster.getMemberId()

オプトアウト・オプトイン #

主な変更点 #

  • optIn メソッドのパラメータが変更され、呼び出し直前に setUserId メソッドを呼び出す必要があります。

サンプルコード #

v5.0 #

// オプトアウト
try Rtoaster.optOut()

// オプトイン
try Rtoaster.setUserId("USER_ID")
try Rtoaster.optIn()

v4.x #

// オプトアウト
Rtoaster.optOut()

// オプトイン
Rtoaster.optIn("USER_ID")

v5.0 #

// オプトアウト
Rtoaster.optOut()

// オプトイン
Rtoaster.setUserId("USER_ID")
Rtoaster.optIn()

v4.x #

// オプトアウト
Rtoaster.optOut()

// オプトイン
Rtoaster.optIn("USER_ID")

トラッキング処理の移行 #

主な変更点 #

  • track メソッドのパラメータが変更になりました。また、パラメータ指定方式にはビルダーパターンが採用されています。
  • コールバックの形式が変更されています。

サンプルコード #

カスタム変数の利用 #

カスタム変数 app_1"A" を設定し、トラッキングを行っているサンプルです。

v5.0 #

let customValues = [
    "app_1": "A"
]

do {
    try Rtoaster.track(.Builder()
        .location(Location("testLocation"))
        .values(TrackingValues.Builder()
            .customValues(customValues)
            .build()
        )
        .build()
    ).onFailure { [weak self] error in
        print("Communication error: \(error.toMap())")
    }
} catch {
    print("Parameter error: \(error.toMap())")
}

v4.x #

let customValues = [
    "app_1": "A"
]

Rtoaster.track(
    withLocation: "testLocation",
    withAppKeys: customValues,
    withCompletionHandler: { [self] result in
        if let error = result.error {
            print("error: \(error)")
        }
    }
)

v5.0 #

val customValues = mapOf(
    "app_1" to "A"
)

try {
    Rtoaster.track(TrackingParameter {
        location(Location("testLocation"))
        values(TrackingValues {
            customValues(customValues)
        })
    }).onFailure {
        Log.d("Rtoaster", "Communication error", it)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

v4.x #

val customValues = mapOf(
    "app_1" to "A"
)

try {
    Rtoaster.track(
        "testLocation",
        null,
        HashMap<String, String>(customValues)
    ) { exception ->
        Log.d("Rtoaster", "Communication error", exception)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

アイテムコードとセッションID指定 #

閲覧学習のためにアイテムコードとレコメンド結果から受け取ったセッションIDを指定しているサンプルです。

v5.0 #

do {
    let trackingValues = try BrowsingValues.Builder()
        .itemCode("item_12345") // アイテムコード
        .sessionId(SessionId("xxyyxxyyxxyyxxyyxxyyxxyy")) // 効果測定ID
        .build()

    try Rtoaster.track(.Builder()
        .location(Location("testLocation"))
        .values(trackingValues)
        .build()
    ).onFailure { [weak self] error in
        print("Communication error: \(error.toMap())")
    }
} catch {
    print("Parameter error: \(error.toMap())")
}

v4.x #

let customValues = [
    "item_code": "item_12345", // アイテムコード
    "_rt.sid": "xxyyxxyyxxyyxxyyxxyyxxyy" // 効果測定ID
]

Rtoaster.track(
    withLocation: "testLocation",
    withAppKeys: customValues,
    withCompletionHandler: { [self] result in
        if let error = result.error {
            print("error: \(error)")
        }
    }
)

v5.0 #

val trackingValues = BrowsingValues {
    itemCode("item_12345") // アイテムコード
    sessionId(SessionId("xxyyxxyyxxyyxxyyxxyyxxyy")) // 効果測定ID
}

try {
    Rtoaster.track(TrackingParameter {
        location(Location("testLocation"))
        values(trackingValues)
    }).onFailure {
        Log.d("Rtoaster", "Communication error", it)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

v4.x #

val customValues = mapOf(
    "item_code" to "item_12345" // アイテムコード
    "_rt.sid" to "xxyyxxyyxxyyxxyyxxyyxxyy" // 効果測定ID
)

try {
    Rtoaster.track(
        "testLocation",
        null,
        HashMap<String, String>(customValues)
    ) { exception ->
        Log.d("Rtoaster", "Communication error", exception)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

残留カート情報の収集 #

残留カート情報を設定しているサンプルです。

v5.0 #

do {
    let trackingValues = try CartValues.Builder()
        .cartItemCodes(["item_12345"]) // アイテムコード
        .build()

    try Rtoaster.track(.Builder()
        .location(Location("testLocation"))
        .values(trackingValues)
        .build()
    ).onFailure { [weak self] error in
        print("Communication error: \(error.toMap())")
    }
} catch {
    print("Parameter error: \(error.toMap())")
}

v4.x #

let customValues = [
    "item1_code": "item_12345" // アイテムコード
]

Rtoaster.track(
    withLocation: "testLocation",
    withAppKeys: customValues,
    withCompletionHandler: { [self] result in
        if let error = result.error {
            print("error: \(error)")
        }
    }
)

v5.0 #

val trackingValues = CartValues {
    .cartItemCodes(setOf("item_12345"))
}

try {
    Rtoaster.track(TrackingParameter {
        location(Location("testLocation"))
        values(trackingValues)
    }).onFailure {
        Log.d("Rtoaster", "Communication error", it)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

v4.x #

val customValues = mapOf(
    "item1_code" to "item_12345" // アイテムコード
)

try {
    Rtoaster.track(
        "testLocation",
        null,
        HashMap<String, String>(customValues)
    ) { exception ->
        Log.d("Rtoaster", "Communication error", exception)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

購買学習 #

購買学習を行うサンプルです。

v5.0 #

do {
    let trackingValues = PurchasingValues.Builder()
        .purchasingItems([
            try PurchasingValues.PurchasingItem(
                itemCode: "item_12345", // アイテムコード
                price: 1000 // アイテムの単価
            )
        ])
        .build()

    try Rtoaster.track(.Builder()
        .location(Location("testLocation"))
        .values(trackingValues)
        .build()
    ).onFailure { [weak self] error in
        print("Communication error: \(error.toMap())")
    }
} catch {
    print("Parameter error: \(error.toMap())")
}

v4.x #

let customValues = [
    "item1_code": "item_12345", // アイテムコード
    "item1_price": "1000" // アイテムの単価
]

Rtoaster.track(
    withLocation: "testLocation",
    withAppKeys: customValues,
    withCompletionHandler: { [self] result in
        if let error = result.error {
            print("error: \(error)")
        }
    }
)

v5.0 #

val trackingValues = PurshasingValues {
    .purchasingItems(
        arrayListOf(
            PurchasingValues.PurchasingItem("item_12345")
        )
    )
}

try {
    Rtoaster.track(TrackingParameter {
        location(Location("testLocation"))
        values(trackingValues)
    }).onFailure {
        Log.d("Rtoaster", "Communication error", it)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

v4.x #

val customValues = mapOf(
    "item1_code" to "item_12345" // アイテムコード
)

try {
    Rtoaster.track(
        "testLocation",
        null,
        HashMap<String, String>(customValues)
    ) { exception ->
        Log.d("Rtoaster", "Communication error", exception)
    }
} catch (e: Exception) {
    Log.d("Rtoaster", "Parameter error", e)
}

レコメンド処理の移行 #

主な変更点 #

  • trackRecommend メソッドは track メソッドとrecommendメソッドに分割されました。
  • recommendメソッドはトラッキングを行っていることが前提となります。
  • 1回のトラッキングごとにrecommendメソッドを呼び出せるのは1回だけです。

サンプルコード #

v5.0 #

do {
    let recommendationValues = try RecommendationValues.Builder()
        .itemCodes(["item_12345"])
        .build()

    try Rtoaster.track(.Builder()  // レコメンドするためのトラッキング
        .location(Location("top_page"))
        .build()
    )
    .onFailure { err in
        print("Tracking error: \(error.toMap())")
    }
    .recommend(.Builder()
        .elementIds(["element_1"])
        .values(recommendationValues)
        .build()
    )
    .onSuccess { result in
        print("SUCCESS: Recommendation")
        print(result)
    }
    .onFailure { err in
        print("Recommendation error: \(error.toMap())")
    }
} catch {
    print("Parameter error: \(error.toMap())")
}

v4.x #

let recommendAppKeys = [
    "item1_code": "item_12345"
]

Rtoaster.trackRecommend(
    withElementIds: ["element_1"],
    withLocation: "top_page",
    withAppKeys: [:],
    withRecommendAppKeys: recommendAppKeys,
    withTargetItems: [:],
    withOmittedItems: [],
    withCompletionHandler: { [self] result in
        print(result)
    }
)

v5.0 #

val recommendationValues = RecommendationValues {
    itemCodes(arrayOf("item_12345").toSet())
}

try	{
    Rtoaster.track(TrackingParameter {  // レコメンドするためのトラッキング
        location(Location("testLocation"))
    }).onFailure {
        Log.d("Rtoaster", "Tracking error", it)
    }.recommend(RecommendationParameter {
        elementIds("element_1")
        values(recommendationValues)
    }).onSuccess {
        for (result in it.results) {
            Log.d("Rtoaster", "Content: ${result.contents.toString()}")
        }
    }.onFailure {
        Log.d("Rtoaster", "Recommendation error", it)
    }
} catch (e: Exception) {
    Log.e("Rtoaster", "Recommendation Error", e)
}

v4.x #

val customValues = mapOf(
    "item1_code" to "item_12345"
)

try	{
    Rtoaster.trackRecommend(
        "top_page",
        arrayOf("element_1").asList(),
        emptyMap<String, String>() as java.util.HashMap<String, String>,
        customValues.toMap() as java.util.HashMap<String, String>,
        emptyMap<String, String>() as java.util.HashMap<String, String>,
        emptyArray<String>().asList() as ArrayList<String>,
        object : Rtoaster.RecommendListener {
            override fun onResult(contents: List<HashMap<String?, String?>?>?) {
                if (contents != null) {
                    for (content in contents) {
                        // サンプルのため、ログに出力するのみ
                        Log.d("Recommended Content", content.toString())
                    }
                }
            }
            override fun onError(exception: RtoasterInvalidParameterException?) {
                Log.e("Rtoaster", "onError", exception)
            }
        }
    )
} catch (e: Exception) {
    Log.e("Rtoaster", "trackRecommend Error", e)
}

アプリポップアップ・アプリアンケート #

主な変更点 #

  • アプリポップアップおよびアプリアンケート専用のメソッドは廃止されました。
  • recommend メソッドの結果に対して、 view メソッドを呼び出すとコンテンツの種類に応じてポップアップまたはアンケートが自動的に表示されます。

廃止されたメソッド #

機能 メソッド名
ポップアップの表示 presentRecommendPopup
trackAndPresentRecommendPopup
アンケートの表示 presentQuestionnairePopup
trackAndPresentQuestionnairePopup

変更されたメソッド #

すべてのポップアップを閉じる #

v5.0 v4.x
Rtoaster.closeAllViews Rtoaster.closeAllPopup