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

Flutter SDK Integration — Legacy (Shoppable Ads)

注記

This guide is for the Legacy Rokt SDK (rokt_sdk). For new integrations, we recommend the Flutter SDK+ Integration guide which uses SDK+.

This guide covers how to integrate Shoppable Ads into your Flutter app using the Legacy 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 Flutter SDK reference, see the Flutter SDK documentation.

注記

Shoppable Ads in Flutter are currently supported on iOS only.

PrerequisitesPrerequisites への直接リンク

  • iOS 15.0+ deployment target
  • rokt_sdk 5.x
  • RoktStripePaymentExtension CocoaPods pod (required for Apple Pay / Stripe payment processing)
  • A Rokt account with Shoppable Ads enabled — contact your Rokt account manager

Step 1: Install dependenciesStep 1: Install dependencies への直接リンク

FlutterFlutter への直接リンク

Add the Rokt SDK to your pubspec.yaml:

pubspec.yaml
dependencies:
rokt_sdk: ^5.0.0

Then run:

flutter pub get

iOS native (Podfile)iOS native (Podfile) への直接リンク

Add the Stripe payment extension to your ios/Podfile:

ios/Podfile
pod 'RoktStripePaymentExtension', '~> 0.1'

Then install the pods:

cd ios && pod install

Step 2: Initialize the SDKStep 2: Initialize the SDK への直接リンク

SDK initialization is the same as for standard placements. See Integrating and initializing the Flutter 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 extension (native)Step 4: Register a payment extension (native) への直接リンク

After configuring Apple Pay, set up the payment extension factory in your native iOS code. This enables Apple Pay and Stripe payment processing within the placement.

ios/Runner/AppDelegate.swift
import RoktStripePaymentExtension
import rokt_sdk

// In application(_:didFinishLaunchingWithOptions:), after GeneratedPluginRegistrant.register:
SwiftRoktSdkPlugin.paymentExtensionFactory = { type, config in
switch type {
case "stripe":
guard let merchantId = config["applePayMerchantId"] else { return nil }
return RoktStripePaymentExtension(
applePayMerchantId: merchantId,
countryCode: config["countryCode"] ?? "US"
)
default:
return nil
}
}
注記

For the Legacy SDK path, you must provide your Stripe publishable key explicitly in the config dictionary when calling registerPaymentExtension from Dart (Step 5).

Step 5: Register payment extension from DartStep 5: Register payment extension from Dart への直接リンク

Register the payment extension from Dart after initialize and before selectShoppableAds:

import 'package:rokt_sdk/rokt_sdk.dart';

RoktSdk.registerPaymentExtension(
extensionType: 'stripe',
config: {
'stripeKey': 'YOUR_STRIPE_PUBLISHABLE_KEY',
'applePayMerchantId': 'merchant.com.yourapp.rokt',
},
);
注意

You must call registerPaymentExtension after SDK initialization (Step 2) and before calling selectShoppableAds (Step 6) from your Dart code. If no payment extension is registered, selectShoppableAds will fire a PlacementFailure event.

Step 6: Display Shoppable AdsStep 6: Display Shoppable Ads への直接リンク

Shoppable Ads always display as an overlay — no embedded views or placeholders are needed.

Call selectShoppableAds from your Dart code once all required attributes are available:

import 'package:rokt_sdk/rokt_sdk.dart';

final attributes = {
"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",
};

RoktSdk.selectShoppableAds(
viewName: "ConfirmationPage",
attributes: attributes,
);

Step 7: Handle eventsStep 7: Handle events への直接リンク

Shoppable Ads emit the following events in addition to the standard placement events. Subscribe to events using the RoktEvents EventChannel:

import 'package:flutter/services.dart';

final EventChannel roktEventChannel = EventChannel('RoktEvents');

roktEventChannel.receiveBroadcastStream().listen((dynamic event) {
switch (event["event"]) {
case "CartItemInstantPurchaseInitiated":
debugPrint("Purchase started: ${event["catalogItemId"]}");
break;
case "CartItemInstantPurchase":
debugPrint("Purchase completed: ${event["catalogItemId"]} — ${event["totalPrice"]} ${event["currency"]}");
break;
case "CartItemInstantPurchaseFailure":
debugPrint("Purchase failed: ${event["error"]}");
break;
case "CartItemDevicePay":
debugPrint("Device payment triggered: ${event["paymentProvider"]}");
break;
case "InstantPurchaseDismissal":
debugPrint("User dismissed purchase");
break;
case "PlacementClosed":
debugPrint("Shoppable Ads placement closed");
break;
default:
break;
}
});

Shoppable Ads eventsShoppable Ads events への直接リンク

EventDescriptionProperties
CartItemInstantPurchaseInitiatedPurchase flow started — user tapped "Buy"identifier, catalogItemId, cartItemId
CartItemInstantPurchasePurchase completed successfullyidentifier, cartItemId, catalogItemId, currency, description, linkedProductId, quantity, totalPrice, unitPrice
CartItemInstantPurchaseFailurePurchase failedidentifier, catalogItemId, cartItemId, error
CartItemDevicePayApple Pay / device payment triggeredidentifier, catalogItemId, cartItemId, paymentProvider
InstantPurchaseDismissalUser dismissed the purchase overlayidentifier

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
この記事は役に立ちましたか?