This document explains how the getRecommendation public method works in the dengage-ios-sdk and dengage-android-sdk, how it differs from the WebSDK getRecommendation, and how to integrate it into an app.
TL;DR — On the WebSDK, getRecommendation is a data API: you pass a containerKey plus a callback and it returns an array of product objects, without rendering anything.
On the mobile SDK it is a view API: you pass a property id and a RecommendationView, and the SDK finds the matching recommendation in-app campaign configured on the D·engage panel and renders it into your view.
The product fetch (the WebSDK-style call) still happens—but it is performed inside the campaign HTML through the JavaScript bridge, not in your app code.
1. Public API
iOS
public static func getRecommendation(
recommendationPropertyId: String,
recommendationView: RecommendationView,
screenName: String? = nil,
customParams: [String: String]? = nil
)Android
fun getRecommendation(
recommendationPropertyId: String,
recommendationView: RecommendationView,
activity: Activity,
screenName: String? = null,
customParams: HashMap<String, String>? = null
)Parameters
| Parameter | Type (iOS / Android) | Description | Required |
|---|---|---|---|
recommendationPropertyId | String / String | The platform selector / property id of the recommendation campaign, configured on the D·engage panel. The SDK matches this against the campaign's inline-target selector (inlineTarget.iosSelector on iOS). | ✅ |
recommendationView | RecommendationView / RecommendationView | The view that will host and render the recommendation. WKWebView subclass on iOS, WebView subclass on Android—place it in your layout beforehand. | ✅ |
activity | — / Activity | Android only. Host activity, needed for rendering, deeplink navigation and the in-app browser. | ✅ (Android) |
screenName | String? / String? | Optional screen-name filter. When provided, campaigns whose screen name filters match this value are preferred; falls back to campaigns without screen filters. | – |
customParams | [String: String]? / HashMap<String, String>? | Optional key/value pairs evaluated against the campaign's real-time display rules (displayRuleSet). Use these to gate which campaign is selected. | – |
There is no completion/callback parameter — the result is the rendered view, not a returned product array.
2. RecommendationView
A subclass of the platform WebView (WKWebView on iOS, WebView on Android) that hosts the campaign HTML with the DengageBridge attached, plus a native Dn JavaScript interface for the legacy Dn.* API.
Auto-height: a MutationObserver reports document.body.scrollHeight and the view resizes itself.
On iOS you can observe this via the onHeightChange closure or let the view manage its own internal height constraint; on Android the view resizes its layoutParams.height to fit the content.
Item tap → navigation: tapping a product opens its URL.
On Android, deeplinks (dengagesample://...) are dispatched via ACTION_VIEW / the deeplink-retrieve broadcast and external URLs can open in the in-app browser; on iOS the URL is opened through the delegate.
On both platforms a recommendation item tap does not emit a dismiss event.
Add it to your view hierarchy (iOS: with a WKWebViewConfiguration; Android: in XML or programmatically) before calling getRecommendation.
3. Full example
iOS
import UIKit
import WebKit
import Dengage
final class RecommendationViewController: UIViewController {
private lazy var recommendationView: RecommendationView = {
let rv = RecommendationView(frame: .zero,configuration:
WKWebViewConfiguration())
rv.translatesAutoresizingMaskIntoConstraints = false
rv.isHidden = true // reveal once content loads
return rv
}()
override func viewDidLoad() \{
super.viewDidLoad()
view.addSubview(recommendationView)
NSLayoutConstraint.activate([
recommendationView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
recommendationView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
recommendationView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
showRecommendation()
}
private func showRecommendation() {
Dengage.getRecommendation(
recommendationPropertyId: "1", // panel iOS selector
recommendationView: recommendationView,
screenName: "recommendation", // optional
customParams: ["segment": "premium"] // optional real-time rules
)
}
}
```Android
class RecommendationFragment : BaseDataBindingFragment<FragmentRecommendationBinding>() {
override fun getLayoutRes() = R.layout.fragment_recommendation
override fun init() {
binding.btnShowRecommendation.setOnClickListener {
val customParams = hashMapOf<String, String>().apply {
put("segment", "premium") // optional real-time rules
}
Dengage.getRecommendation(
recommendationPropertyId = "1", // panel Android selector
recommendationView = binding.recommendationView,
activity = requireActivity(),
screenName = "recommendation", // optional
customParams = customParams.ifEmpty { null }
)
}
}
}Layout (fragment_recommendation.xml):
<com.dengage.sdk.ui.recommendation.RecommendationView
android:id="@+id/recommendationView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />