Skip to main content

Add a placement (legacy)

The Rokt SDK for Flutter can be used to display overlay and embedded placements within your app's content.

Before you beginDirect link to Before you begin

Ensure that the Rokt Flutter SDK has already been integrated into your application.

Select placementsDirect link to Select placements

Import the SDKDirect link to Import the SDK

Import the SDK into your application's dart file:

import 'package:rokt_sdk/rokt_sdk.dart';

Call selectPlacementsDirect link to Call selectPlacements

Call selectPlacements at the desired point by adding the appropriate customer attributes. The Rokt placement will then display after a short delay that is configurable via the Rokt platform.

You can dictate what customer attributes are included in your Rokt integration. More information on available data fields can be found on the attributes page. If you want to integrate more attributes, you can add additional lines of code for each new attribute to the samples below.

RoktSdk.selectPlacements(
viewName: "RoktExperience",
attributes: {
"email": "j.smith@example.com",
"firstname": "Jenny",
"lastname": "Smith",
"mobile": "(555)867-5309",
"postcode": "90210",
"country": "US"
},
);
note

The viewName ("RoktExperience") can be modified when calling the SDK in multiple locations to display a different experience according to the context of where in the app the SDK is being called. If modifying the viewName, work with the Rokt team to ensure matching adjustments are made within the Rokt system.

Embedded placementsDirect link to Embedded placements

For embedded placements, add a RoktWidget into the build function of your view before calling selectPlacements. The Rokt widget will be injected into this placeholder when selectPlacements is called.

const RoktWidget(placeholderName: "RoktEmbedded1")

RoktWidget has a callback to notify when the widget is created which can be utilized:

RoktWidget(placeholderName: "RoktEmbedded1", onWidgetCreated: () { showWidget() })

Make sure the view is created in the visible area of the screen before calling selectPlacements.

note

If modifying the viewName or placeholderName ("RoktEmbedded1"), please work with the Rokt team to ensure matching adjustments are made within the Rokt system.

EventsDirect link to Events

The Rokt SDK exposes an EventChannel for SDK events. This is the recommended way to observe placement lifecycle events.

final EventChannel roktEventChannel = EventChannel('RoktEvents');
//...
roktEventChannel.receiveBroadcastStream().listen((dynamic event) {
debugPrint("Rokt event received $event");
switch (event["event"]) {
case "InitComplete":
debugPrint("Init status: ${event["status"]}");
break;
case "ShowLoadingIndicator":
debugPrint("Event ${event["viewName"]}");
break;
case "HideLoadingIndicator":
debugPrint("Event ${event["viewName"]}");
break;
case "OfferEngagement":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "PositiveEngagement":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "FirstPositiveEngagement":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "PlacementInteractive":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "PlacementReady":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "PlacementClosed":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "PlacementCompleted":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "PlacementFailure":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}");
break;
case "EmbeddedSizeChanged":
debugPrint("Event ${event["identifier"]}, height: ${event["selectedHeight"]}");
break;
case "OpenUrl":
debugPrint("Event ${event["viewName"]}, ${event["identifier"]}, url: ${event["url"]}");
break;
case "CartItemInstantPurchaseInitiated":
debugPrint("Purchase started: ${event["catalogItemId"]}");
break;
case "CartItemInstantPurchase":
debugPrint("Purchase completed: ${event["catalogItemId"]}");
break;
case "CartItemInstantPurchaseFailure":
debugPrint("Purchase failed: ${event["error"]}");
break;
case "CartItemDevicePay":
debugPrint("Device payment triggered: ${event["paymentProvider"]}");
break;
case "InstantPurchaseDismissal":
debugPrint("Purchase dismissed");
break;
default:
break;
}
});

Event objectsDirect link to Event objects

EventDescriptionProperties
InitCompleteTriggered when SDK initialization completesstatus: String
ShowLoadingIndicatorTriggered before the SDK calls the Rokt backendviewName: String
HideLoadingIndicatorTriggered when the SDK receives a success or failure from the Rokt backendviewName: String
OfferEngagementTriggered when the user engages with the offerviewName: String, identifier: String
PositiveEngagementTriggered when the user positively engages with the offerviewName: String, identifier: String
FirstPositiveEngagementTriggered when the user positively engages with the offer for the first timeviewName: String, identifier: String
PlacementInteractiveTriggered when a placement has been rendered and is interactableviewName: String, identifier: String
PlacementReadyTriggered when a placement is ready to display but has not rendered content yetviewName: String, identifier: String
PlacementClosedTriggered when a placement is closed by the userviewName: String, identifier: String
PlacementCompletedTriggered when the offer progression reaches the end and no more offers are available to display. Also triggered when cache is hit but the retrieved placement will not be displayed as it has previously been dismissedviewName: String, identifier: String
PlacementFailureTriggered when a placement could not be displayed due to some failure or when no placements are available to showviewName: String, identifier: String (optional)
EmbeddedSizeChangedTriggered when an embedded placement's height changesidentifier: String, selectedHeight: Double
OpenUrlTriggered when the user presses a URL that is configured to be sent to the partner appviewName: String, identifier: String, url: String
CartItemInstantPurchaseInitiatedPurchase flow started — user tapped "Buy" (Shoppable Ads, iOS only)identifier: String, catalogItemId: String, cartItemId: String
CartItemInstantPurchasePurchase completed successfully (Shoppable Ads, iOS only)identifier: String, catalogItemId: String, cartItemId: String, totalPrice: String, currency: String
CartItemInstantPurchaseFailurePurchase failed (Shoppable Ads, iOS only)identifier: String, catalogItemId: String, cartItemId: String, error: String
CartItemDevicePayApple Pay / device payment triggered (Shoppable Ads, iOS only)identifier: String, catalogItemId: String, cartItemId: String, paymentProvider: String
InstantPurchaseDismissalUser dismissed the purchase overlay (Shoppable Ads, iOS only)identifier: String

Shoppable Ads (iOS only)Direct link to Shoppable Ads (iOS only)

Shoppable Ads allow users to make instant purchases directly from ad placements. This feature is currently available on iOS only.

For the full integration guide, see the Flutter Shoppable Ads Integration (Legacy) guide.

PrerequisitesDirect link to Prerequisites

  • iOS 15.0+ deployment target
  • rokt_sdk 5.x
  • RoktStripePaymentExtension CocoaPods pod

iOS native setupDirect link to iOS native setup

  1. Add the payment extension to your iOS Podfile:
ios/Podfile
pod 'RoktStripePaymentExtension', '~> 0.1'
  1. Set the payment extension factory in your AppDelegate.swift:
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
}
}

Register the payment extensionDirect link to Register the payment extension

Register from Dart after initialize and before selectShoppableAds:

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

Display Shoppable AdsDirect link to Display Shoppable Ads

RoktSdk.selectShoppableAds(
viewName: "ConfirmationPage",
attributes: {
"email": "j.smith@example.com",
"firstname": "Jenny",
"lastname": "Smith",
"confirmationref": "ORD-12345",
"amount": "52.25",
"currency": "USD",
"paymenttype": "visa",
"shippingaddress1": "123 Main St",
"shippingcity": "New York",
"shippingstate": "NY",
"shippingzipcode": "10001",
"shippingcountry": "US",
},
);

Shoppable Ads events are delivered via the RoktEvents EventChannel — see the Events section above.

Was this article helpful?