iOS SDK Integration — Legacy (Shoppable Ads)
This guide is for the Direct Rokt SDK. For new integrations, we recommend the iOS SDK Integration guide which uses SDK+.
This guide covers how to integrate Shoppable Ads into your native iOS app using the Direct Rokt SDK. Shoppable Ads enable post-purchase upsell offers with in-app catalog browsing and instant checkout (via Apple Pay or Stripe) — all within the Rokt placement.
For the general Rokt iOS SDK reference, see the iOS SDK Integration Guide.
PrerequisitesPrerequisites への直接リンク
- iOS 15.0+ deployment target
- Rokt-Widget 5.2+ and RoktPaymentExtension 2.0+ (see Minimum versions below)
- A Rokt account with Shoppable Ads enabled — contact your Rokt account manager
Step 1: Install dependenciesStep 1: Install dependencies への直接リンク
Swift Package ManagerSwift Package Manager への直接リンク
Add the following packages in Xcode (File > Add Package Dependencies):
| Package | URL | Product | Minimum version |
|---|---|---|---|
| Rokt SDK | https://github.com/ROKT/rokt-sdk-ios.git | Rokt-Widget | 5.2.0 |
| Payment Extension | https://github.com/ROKT/rokt-payment-extension-ios.git | RoktPaymentExtension | 2.0.0 |
Or add to your Package.swift:
dependencies: [
.package(url: "https://github.com/ROKT/rokt-sdk-ios.git", from: "5.2.0"),
.package(url: "https://github.com/ROKT/rokt-payment-extension-ios.git", from: "2.0.0"),
]
CocoaPodsCocoaPods への直接リンク
pod 'Rokt-Widget', '~> 5.2'
pod 'RoktPaymentExtension', '~> 2.0'
Minimum versionsMinimum versions への直接リンク
| Capability | Minimum versions |
|---|---|
| Shoppable Ads (base) | Rokt-Widget 5.0+ / RoktPaymentExtension 1.0+ |
| Afterpay / Clearpay | Rokt-Widget 5.1+ / RoktPaymentExtension 1.0+ / RoktContracts 2.0+ |
| PayPal, card forwarding (iOS built-in) | Rokt-Widget 5.2+ / RoktPaymentExtension 2.0+ |
If you pin RoktContracts in your Podfile, use '~> 2.0'.
Step 2: Initialize the SDKStep 2: Initialize the SDK への直接リンク
SDK initialization is the same as for standard placements. See Integrating and initializing the iOS SDK.
Step 3: Configure Apple Pay (if using Apple Pay)Step 3: Configure Apple Pay (if using Apple Pay) への直接リンク
If you plan to offer Apple Pay in Shoppable Ads, create an Apple Pay merchant ID, configure your Xcode project, and generate a Payment Processing Certificate.
Follow the steps in Apple Pay — iOS setup, then return here.
Step 4: Register a payment extensionStep 4: Register a payment extension への直接リンク
Register a RoktPaymentExtension after SDK initialization. This is required for all Shoppable Ads placements on iOS.
import Rokt_Widget
import RoktPaymentExtension
// Register after SDK initialization, before selectShoppableAds
if let paymentExtension = RoktPaymentExtension(
applePayMerchantId: "merchant.com.rokt.sample", // omit if not offering Apple Pay
urlScheme: "myapp" // omit if not offering Afterpay / Clearpay
) {
Rokt.registerPaymentExtension(paymentExtension, config: ["stripeKey": "pk_test_placeholder"])
}
At least one of applePayMerchantId or urlScheme must be provided.
For the direct SDK path, you must provide your Stripe publishable key explicitly in the config dictionary.
You must call registerPaymentExtension after SDK initialization (Step 2) and before selectShoppableAds (Step 6). If no payment extension is registered, selectShoppableAds will fire a PlacementFailure event.
Afterpay / Clearpay (optional)Afterpay / Clearpay (optional) への直接リンク
- Register a URL scheme in
Info.plistunderCFBundleURLTypes. - Pass the matching
urlSchemewhen creatingRoktPaymentExtension. - Forward redirect URLs to Rokt — see Step 5.
Step 5: Forward redirect URLsStep 5: Forward redirect URLs への直接リンク
Afterpay, Clearpay, and PayPal redirect back to your app after authentication. Forward incoming URLs to the Rokt SDK:
SceneDelegate:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
if Rokt.handleURLCallback(with: urlContext.url) {
return
}
}
}
AppDelegate:
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return Rokt.handleURLCallback(with: url)
}
Step 6: Display Shoppable AdsStep 6: Display Shoppable Ads への直接リンク
Shoppable Ads always display as an overlay — no embedded views are needed.
import Rokt_Widget
let attributes: [String: String] = [
"email": "j.smith@example.com",
"firstname": "Jane",
"lastname": "Smith",
"confirmationref": "ORD-8829-XK2",
"amount": "52.25",
"currency": "USD",
"paymenttype": "visa",
"shippingaddress1": "123 Main St",
"shippingcity": "Brooklyn",
"shippingstate": "NY",
"shippingzipcode": "11201",
"shippingcountry": "US"
]
Rokt.selectShoppableAds(
identifier: "ConfirmationPage",
attributes: attributes,
config: nil,
onEvent: { event in
switch event {
case let e as RoktEvent.CartItemInstantPurchase:
print("Purchase completed: \(e.catalogItemId) — \(e.totalPrice ?? 0) \(e.currency)")
case let e as RoktEvent.CartItemInstantPurchaseFailure:
print("Purchase failed: \(e.error ?? "unknown")")
case is RoktEvent.InstantPurchaseDismissal:
print("User dismissed purchase")
case is RoktEvent.PlacementClosed:
print("Shoppable Ads placement closed")
default:
break
}
}
)
Step 7: Handle eventsStep 7: Handle events への直接リンク
Shoppable Ads emit the following events in addition to the standard placement events. All event types are defined in the RoktContracts package.
| Event (Swift) | Event (ObjC) | Description | Properties |
|---|---|---|---|
RoktEvent.CartItemInstantPurchaseInitiated | RoktCartItemInstantPurchaseInitiated | Purchase flow started — user tapped "Buy" | identifier, catalogItemId, cartItemId |
RoktEvent.CartItemInstantPurchase | RoktCartItemInstantPurchase | Purchase completed successfully | identifier, name, cartItemId, catalogItemId, currency, description, linkedProductId, providerData, quantity, totalPrice, unitPrice |
RoktEvent.CartItemInstantPurchaseFailure | RoktCartItemInstantPurchaseFailure | Purchase failed | identifier, catalogItemId, cartItemId, error |
RoktEvent.CartItemDevicePay | RoktCartItemDevicePay | Apple Pay / device payment triggered | identifier, catalogItemId, cartItemId, paymentProvider |
RoktEvent.InstantPurchaseDismissal | RoktInstantPurchaseDismissal | User dismissed the purchase overlay | identifier |
Recommended attributesRecommended attributes への直接リンク
The iOS SDK uses the same attributes as the Web SDK. The following attributes are particularly important for Shoppable Ads:
| Attribute | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Customer email (unhashed). Used for order confirmation. |
confirmationref | string | Yes | Order or transaction reference number. |
amount | string | Recommended | Decimal transaction amount (e.g., "52.25"). |
currency | string | Recommended | ISO 4217 currency code (e.g., "USD"). |
paymenttype | string | Recommended | Payment method used for the primary purchase (e.g., "visa", "apple_pay"). Used for payment method prioritization. |
shippingaddress1 | string | Recommended | Shipping street address. |
shippingcity | string | Recommended | Shipping city. |
shippingstate | string | Recommended | Shipping state or province. |
shippingzipcode | string | Recommended | Shipping postal code. |
shippingcountry | string | Recommended | ISO Alpha-2 country code (e.g., "US"). |
For the full list of supported attributes, see the recommended attributes table.
If your platform does not have shipping address details (e.g., ticket or digital goods purchases), pass billing address details instead. Rokt will provide a UI for the customer to confirm or edit their shipping address before completing the purchase.
Payment methodsPayment methods への直接リンク
| Method | iOS setup |
|---|---|
| Apple Pay | Apple Pay merchant ID + RoktPaymentExtension |
| PayPal | Built into the Rokt SDK — forward return URLs via Rokt.handleURLCallback(with:) (Step 5) |
| Afterpay / Clearpay | URL scheme in Info.plist + urlScheme on RoktPaymentExtension + Step 5 |
| Card Forwarding | Partner Payment Sharing API + partnerpaymentreference / last4digits attributes |