Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.mparticle.commerce.*
import com.mparticle.consent.CCPAConsent
import com.mparticle.consent.ConsentState
import com.mparticle.consent.GDPRConsent
import com.mparticle.internal.Logger
import com.mparticle.rokt.CacheConfig
import com.mparticle.rokt.RoktConfig
import com.mparticle.rokt.RoktEmbeddedView
Expand Down Expand Up @@ -235,6 +236,7 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware
result.success(true)
}
"roktSelectPlacements" -> this.roktSelectPlacements(call, result)
"roktSelectShoppableAds" -> this.roktSelectShoppableAds(call, result)
"roktPurchaseFinalized" -> this.roktPurchaseFinalized(call, result)
else -> {
result.notImplemented()
Expand Down Expand Up @@ -806,6 +808,12 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware
}
}

private fun roktSelectShoppableAds(call: MethodCall, result: Result) {
// Parity with RN bridge: Android API is exposed but not implemented yet.
Comment thread
denischilik marked this conversation as resolved.
Logger.warning("selectShoppableAds is not yet supported on Android")
result.success(true)
}

private fun String.toColorMode(): RoktConfig.ColorMode =
when (this) {
"dark" -> RoktConfig.ColorMode.DARK
Expand Down
21 changes: 21 additions & 0 deletions ios/Classes/SwiftMparticleFlutterSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,27 @@ public class SwiftMparticleFlutterSdkPlugin: NSObject, FlutterPlugin {
print("Incorrect argument for \(call.method) iOS method")
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Missing placementId or catalogItemId or success", details: nil))
}
case "roktSelectShoppableAds":
if let callArguments = call.arguments as? [String: Any],
let identifier = callArguments["identifier"] as? String {
let attributes = callArguments["attributes"] as? [String: String] ?? [:]
var roktConfig: RoktConfig?
if let configMap = callArguments["config"] as? [String: Any] {
roktConfig = buildRoktConfig(configMap: configMap)
}

roktEventHandler.subscribeToEvents(identifier: identifier)
MParticle.sharedInstance().rokt.selectShoppableAds(
identifier,
attributes: attributes,
config: roktConfig,
onEvent: nil
)
result(true)
} else {
print("Incorrect argument for \(call.method) iOS method")
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Missing identifier", details: nil))
}
default:
print("mParticle flutter SDK for iOS does not support \(call.method)")
}
Expand Down
4 changes: 1 addition & 3 deletions ios/mparticle_flutter_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ mParticle Flutter Wrapper
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
# SDK 9.0 split requires both umbrella and ObjC pods.
# SDK 9.0 umbrella pod pulls required transitive dependencies.
s.dependency 'mParticle-Apple-SDK', '~> 9.0'
s.dependency 'mParticle-Apple-SDK-ObjC', '~> 9.0'
s.dependency 'RoktContracts', '~> 0.1'
s.platform = :ios, '15.6'

# Flutter.framework does not contain a i386 slice.
Expand Down
18 changes: 18 additions & 0 deletions lib/mparticle_flutter_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ class Rokt {
return await _channel.invokeMethod('roktSelectPlacements', params);
}

/// Selects shoppable ads with a [identifier], optional [attributes], and optional [roktConfig].
///
/// This method is currently implemented only on iOS.
///
/// Android keeps a no-op bridge for API compatibility, and web does not
/// implement this method yet.
Future<void> selectShoppableAds({
required String identifier,
Map<String, dynamic>? attributes,
RoktConfig? roktConfig,
}) async {
return await _channel.invokeMethod('roktSelectShoppableAds', {
'identifier': identifier,
'attributes': attributes,
'config': _roktConfigToMap(config: roktConfig),
});
}

/// Notifies Rokt that a purchase has been finalized
///
/// Use this method to inform Rokt that a purchase has been completed or failed
Expand Down
28 changes: 28 additions & 0 deletions test/mparticle_flutter_sdk_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,33 @@ void main() {
'success': true,
}));
});

test('rokt select shoppable ads', () async {
final roktConfig = RoktConfig(
colorMode: ColorMode.dark,
cacheConfig: CacheConfig(
cacheDurationInSeconds: 100,
cacheAttributes: {'key1': 'value1'}));

await mp.rokt.selectShoppableAds(
identifier: 'identifier1',
attributes: {'attr1': 'val1'},
roktConfig: roktConfig,
);

expect(
methodCall,
isMethodCall('roktSelectShoppableAds', arguments: {
'identifier': 'identifier1',
'attributes': {'attr1': 'val1'},
'config': {
'colorMode': 'dark',
'cacheConfig': {
'cacheDurationInSeconds': 100,
'cacheAttributes': {'key1': 'value1'}
}
},
}));
});
});
}
Loading