|
1 | | -import 'package:flutter/material.dart'; |
2 | 1 | import 'dart:async'; |
| 2 | +import 'dart:io'; |
3 | 3 |
|
| 4 | +import 'package:flutter/foundation.dart'; |
| 5 | +import 'package:flutter/material.dart'; |
4 | 6 | import 'package:mparticle_flutter_sdk/mparticle_flutter_sdk.dart'; |
5 | 7 | import 'package:mparticle_flutter_sdk/events/event_type.dart'; |
6 | 8 | import 'package:mparticle_flutter_sdk/events/commerce_event.dart'; |
@@ -443,7 +445,7 @@ class _MyAppState extends State<MyApp> { |
443 | 445 | child: Text('NATIVE ONLY METHODS'), |
444 | 446 | ), |
445 | 447 | buildButton('is Braze kit active?', () async { |
446 | | - print(await mpInstance?.isKitActive(kit: Kits['Braze']!)); |
| 448 | + print(await mpInstance?.isKitActive(kit: Kits['Rokt']!)); |
447 | 449 | }), |
448 | 450 | buildButton('Get opt out', () async { |
449 | 451 | print(await mpInstance?.getOptOut); |
@@ -561,16 +563,84 @@ class _MyAppState extends State<MyApp> { |
561 | 563 | Center( |
562 | 564 | child: Text('ROKT'), |
563 | 565 | ), |
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' |
| 566 | + buildButton('Web - Select Placements', () async { |
| 567 | + if (kIsWeb) { |
| 568 | + // Ensure user is identified before calling Rokt |
| 569 | + var identityRequest = MparticleFlutterSdk.identityRequest; |
| 570 | + identityRequest.setIdentity( |
| 571 | + identityType: IdentityType.CustomerId, |
| 572 | + value: 'web-test-user-${DateTime.now().millisecondsSinceEpoch}'); |
| 573 | + |
| 574 | + await mpInstance?.identity.identify(identityRequest: identityRequest); |
| 575 | + |
| 576 | + mpInstance?.rokt.selectPlacements( |
| 577 | + placementId: 'web-placement-test', |
| 578 | + attributes: { |
| 579 | + 'email': 'web-user@example.com', |
| 580 | + 'platform': 'web', |
| 581 | + 'userId': 'web-12345' |
| 582 | + } |
| 583 | + ); |
| 584 | + print('Web Rokt selectPlacements called'); |
| 585 | + } else { |
| 586 | + print('This button is for Web platform only'); |
| 587 | + } |
| 588 | + }), |
| 589 | + buildButton('Android - Select Placements', () async { |
| 590 | + if (!kIsWeb && Platform.isAndroid) { |
| 591 | + // Ensure user is identified before calling Rokt |
| 592 | + var identityRequest = MparticleFlutterSdk.identityRequest; |
| 593 | + identityRequest.setIdentity( |
| 594 | + identityType: IdentityType.CustomerId, |
| 595 | + value: 'android-test-user-${DateTime.now().millisecondsSinceEpoch}'); |
| 596 | + |
| 597 | + try { |
| 598 | + await mpInstance?.identity.identify(identityRequest: identityRequest); |
| 599 | + |
| 600 | + mpInstance?.rokt.selectPlacements( |
| 601 | + placementId: 'RoktExperience', |
| 602 | + attributes: { |
| 603 | + 'email': 'android-user@example.com', |
| 604 | + 'platform': 'android', |
| 605 | + 'userId': 'android-67890', |
| 606 | + 'deviceType': 'mobile' |
| 607 | + } |
| 608 | + ); |
| 609 | + print('Android Rokt selectPlacements called'); |
| 610 | + } catch (e) { |
| 611 | + print('Error calling Android Rokt selectPlacements: $e'); |
571 | 612 | } |
572 | | - ); |
573 | | - print('Rokt selectPlacements called'); |
| 613 | + } else { |
| 614 | + print('This button is for Android platform only'); |
| 615 | + } |
| 616 | + }), |
| 617 | + buildButton('iOS - Select Placements', () async { |
| 618 | + if (!kIsWeb && Platform.isIOS) { |
| 619 | + // Ensure user is identified before calling Rokt |
| 620 | + var identityRequest = MparticleFlutterSdk.identityRequest; |
| 621 | + identityRequest.setIdentity( |
| 622 | + identityType: IdentityType.CustomerId, |
| 623 | + value: 'ios-test-user-${DateTime.now().millisecondsSinceEpoch}'); |
| 624 | + |
| 625 | + try { |
| 626 | + await mpInstance?.identity.identify(identityRequest: identityRequest); |
| 627 | + |
| 628 | + mpInstance?.rokt.selectPlacements( |
| 629 | + placementId: 'ios-placement-test', |
| 630 | + attributes: { |
| 631 | + 'email': 'ios-user@example.com', |
| 632 | + 'platform': 'ios', |
| 633 | + 'userId': 'ios-54321', |
| 634 | + 'deviceType': 'mobile' |
| 635 | + } |
| 636 | + ); |
| 637 | + print('iOS Rokt selectPlacements called'); |
| 638 | + } catch (e) { |
| 639 | + print('Error calling iOS Rokt selectPlacements: $e'); |
| 640 | + } |
| 641 | + } else { |
| 642 | + print('This button is for iOS platform only'); |
| 643 | + } |
574 | 644 | }), |
575 | 645 | ], |
576 | 646 | ), |
|
0 commit comments