メインコンテンツまでスキップ

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 SDK 5.x
  • RoktPaymentExtension package (required for payment processing)
  • 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):

PackageURLProduct
Rokt SDKhttps://github.com/ROKT/rokt-sdk-ios.gitRokt-Widget
Payment Extensionhttps://github.com/ROKT/rokt-payment-extension-ios.gitRoktPaymentExtension

CocoaPodsCocoaPods への直接リンク

pod 'Rokt-Widget', '~> 5.0'
pod 'RoktPaymentExtension', '~> 1.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 PayStep 3: Configure Apple Pay への直接リンク

Before registering a payment extension, you need to 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 to register the payment extension.

Step 4: Register a payment extensionStep 4: Register a payment extension への直接リンク

After configuring Apple Pay, register a payment extension. This enables Apple Pay and Stripe payment processing within the placement.

import Rokt_Widget
import RoktPaymentExtension

// Register after SDK initialization, before selectShoppableAds
if let paymentExtension = RoktPaymentExtension(applePayMerchantId: "merchant.com.rokt.sample") {
Rokt.registerPaymentExtension(paymentExtension, config: ["stripeKey": "pk_test_placeholder"])
}
注記

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 5). If no payment extension is registered, selectShoppableAds will fire a PlacementFailure event.

Step 5: Display Shoppable AdsStep 5: 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 6: Handle eventsStep 6: 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)DescriptionProperties
RoktEvent.CartItemInstantPurchaseInitiatedRoktCartItemInstantPurchaseInitiatedPurchase flow started — user tapped "Buy"identifier, catalogItemId, cartItemId
RoktEvent.CartItemInstantPurchaseRoktCartItemInstantPurchasePurchase completed successfullyidentifier, name, cartItemId, catalogItemId, currency, description, linkedProductId, providerData, quantity, totalPrice, unitPrice
RoktEvent.CartItemInstantPurchaseFailureRoktCartItemInstantPurchaseFailurePurchase failedidentifier, catalogItemId, cartItemId, error
RoktEvent.CartItemDevicePayRoktCartItemDevicePayApple Pay / device payment triggeredidentifier, catalogItemId, cartItemId, paymentProvider
RoktEvent.InstantPurchaseDismissalRoktInstantPurchaseDismissalUser dismissed the purchase overlayidentifier

The iOS SDK uses the same attributes as the Web SDK. The following attributes are particularly important for Shoppable Ads:

AttributeTypeRequiredDescription
emailstringYesCustomer email (unhashed). Used for order confirmation.
confirmationrefstringYesOrder or transaction reference number.
amountstringRecommendedDecimal transaction amount (e.g., "52.25").
currencystringRecommendedISO 4217 currency code (e.g., "USD").
paymenttypestringRecommendedPayment method used for the primary purchase (e.g., "visa", "apple_pay"). Used for payment method prioritization.
shippingaddress1stringRecommendedShipping street address.
shippingcitystringRecommendedShipping city.
shippingstatestringRecommendedShipping state or province.
shippingzipcodestringRecommendedShipping postal code.
shippingcountrystringRecommendedISO 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 への直接リンク

For detailed setup of individual payment methods, see:

  • Apple Pay — Native Apple Pay within the Rokt placement
  • Card Forwarding — Reuse the customer's vaulted card from the primary purchase
この記事は役に立ちましたか?