Skip to content

Commit ecf17a3

Browse files
committed
flutter rokt poc, checkout - working on web
1 parent 7b2c9e3 commit ecf17a3

6 files changed

Lines changed: 92 additions & 1 deletion

File tree

android/src/main/kotlin/com/mparticle/mparticle_flutter_sdk/MparticleFlutterSdkPlugin.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler {
208208
}
209209
result.success(true)
210210
}
211+
"roktSelectPlacements" -> this.roktSelectPlacements(call, result)
211212
else -> {
212213
result.notImplemented()
213214
}
@@ -673,6 +674,33 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler {
673674
} ?: result.error(TAG, "No mParticle instance exists", null)
674675
}
675676

677+
private fun roktSelectPlacements(call: MethodCall, result: Result) {
678+
try {
679+
val placementId: String? = call.argument("placementId")
680+
val attributes: Map<String, Any?>? = call.argument("attributes")
681+
Log.d(TAG, "roktSelectPlacements - placementId: $placementId")
682+
Log.d(TAG, "roktSelectPlacements - attributes: $attributes")
683+
684+
if (placementId == null) {
685+
result.error(TAG, "Missing placementId", null)
686+
return
687+
}
688+
689+
val stringAttributes: MutableMap<String, String> = mutableMapOf()
690+
attributes?.forEach { (key, value) ->
691+
stringAttributes[key] = value?.toString() ?: ""
692+
}
693+
694+
Log.d(TAG, "roktSelectPlacements - stringAttributes: $stringAttributes")
695+
MParticle.getInstance()?.let { instance ->
696+
instance.Rokt()?.selectPlacements(placementId, stringAttributes)
697+
result.success(true)
698+
} ?: result.error(TAG, "No mParticle instance exists", null)
699+
} catch (e: Exception) {
700+
result.error(TAG, e.localizedMessage, null)
701+
}
702+
}
703+
676704
private fun ConvertIdentityHttpResponseToString(response: IdentityHttpResponse?): String {
677705
val map = mutableMapOf<String, Any?>()
678706

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id "com.android.application"
3-
id "dev.flutter.flutter-gradle-plugin"
43
id "org.jetbrains.kotlin.android"
4+
id "dev.flutter.flutter-gradle-plugin"
55
}
66

77
def localProperties = new Properties()

example/lib/main.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,20 @@ class _MyAppState extends State<MyApp> {
558558
mpInstance?.setATTStatus(
559559
attStatus: MPATTAuthorizationStatus.Authorized);
560560
}),
561+
Center(
562+
child: Text('ROKT'),
563+
),
564+
buildButton('Select Placements', () async {
565+
mpInstance?.rokt.selectPlacements(
566+
placementId: 'mp-layout-test-2',
567+
attributes: {
568+
'email': 'rob@ing.com',
569+
'key2': 'value2',
570+
'userId': '12345'
571+
}
572+
);
573+
print('Rokt selectPlacements called');
574+
}),
561575
],
562576
),
563577
),

ios/Classes/SwiftMparticleFlutterSdkPlugin.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,16 @@ public class SwiftMparticleFlutterSdkPlugin: NSObject, FlutterPlugin {
488488
} else {
489489
print("Incorrect argument for \(call.method) iOS method")
490490
}
491+
case "roktSelectPlacements":
492+
if let callArguments = call.arguments as? [String: Any],
493+
let placementId = callArguments["placementId"] as? String {
494+
let attributes = callArguments["attributes"] as? [String: Any] ?? [:]
495+
MParticle.sharedInstance().rokt.selectPlacements(placementId, attributes: attributes)
496+
result(true)
497+
} else {
498+
print("Incorrect argument for \(call.method) iOS method")
499+
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Missing placementId", details: nil))
500+
}
491501
default:
492502
print("mParticle flutter SDK for iOS does not support \(call.method)")
493503
}

lib/mparticle_flutter_sdk.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class MparticleFlutterSdk {
5050
/// The identity API to make identity calls.
5151
Identity identity = new Identity._();
5252

53+
/// The Rokt API to make Rokt-specific calls.
54+
Rokt rokt = new Rokt._();
55+
5356
/// Returns the appName set in your web SDK. There is no iOS or Android equivalent.
5457
Future<String?> get getAppName async {
5558
final String? appName = await _channel.invokeMethod('getAppName');
@@ -268,3 +271,27 @@ class Identity {
268271
.invokeMethod('aliasUsers', {'aliasRequest': aliasRequestObj});
269272
}
270273
}
274+
275+
/// The Rokt API
276+
class Rokt {
277+
Rokt._();
278+
279+
static const MethodChannel _channel =
280+
const MethodChannel('mparticle_flutter_sdk');
281+
282+
/// Selects placements with a [placementId] and optional [attributes].
283+
///
284+
/// This method calls the Rokt selectPlacements API on each platform:
285+
/// - Web: mParticle.Rokt.selectPlacements()
286+
/// - Android: MParticle.getInstance()?.Rokt().selectPlacements()
287+
/// - iOS: MParticle.sharedInstance().rokt.selectPlacements()
288+
Future<void> selectPlacements({
289+
required String placementId,
290+
Map<String, dynamic>? attributes,
291+
}) async {
292+
return await _channel.invokeMethod('roktSelectPlacements', {
293+
'placementId': placementId,
294+
'attributes': attributes,
295+
});
296+
}
297+
}

lib/mparticle_flutter_sdk_web.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,18 @@ class MparticleFlutterSdkWeb {
524524
user.callMethod('setConsentState', [consentState]);
525525
}
526526
break;
527+
case 'roktSelectPlacements':
528+
final mpRokt = JsObject.fromBrowserObject(context['mParticle']['Rokt']);
529+
final placementId = call.arguments['placementId'];
530+
final attributes = call.arguments['attributes'] ?? {};
531+
532+
mpRokt.callMethod('selectPlacements', [
533+
JsObject.jsify({
534+
'identifier': placementId,
535+
'attributes': attributes
536+
})
537+
]);
538+
break;
527539
default:
528540
throw PlatformException(
529541
code: 'Unimplemented',

0 commit comments

Comments
 (0)