sfmc_marketingcloudsdk 1.1.0
sfmc_marketingcloudsdk: ^1.1.0 copied to clipboard
Flutter bridge for Salesforce MarketingCloudSDK (inbox, tags, analytics)
SFMC MarketingCloud SDK (Engagement) #
Salesforce Marketing Cloud Engagement SDK for Flutter — inbox, registration, tags, attributes, analytics.
Installation #
flutter pub add sfmc_marketingcloudsdk
iOS:
cd ios && pod install
Android: no additional steps — Gradle resolves the dependency automatically.
Required SDK configuration #
- Android — initialize in your
MainApplication.ktviaSFMCSdk.configure(...). See the Android SDK Integration Guide. - iOS — initialize in your
AppDelegate.swiftviaSFMCSdk.initializeSdk(...). See the iOS SDK Integration Guide. - Configure Firebase (Android) and APNs (iOS) credentials before push will deliver.
Location & proximity — config-time arming
The runtime toggles below (enableLocation(), enableProximityMessaging()) only work if the feature is armed at SDK-configuration time. Skipping this step means the runtime calls appear to succeed but no geofence transitions or beacon detections ever fire (the native SDK only logs a warning).
- Android — in
MarketingCloudConfig.builder():
Also declare.setGeofencingEnabled(true) // required for enableLocation() .setProximityEnabled(true) // required for enableProximityMessaging() .setProximityNotificationOptions( ProximityNotificationCustomizationOptions.create(iconResId), )ACCESS_FINE_LOCATION,ACCESS_BACKGROUND_LOCATION,BLUETOOTH_SCAN, andBLUETOOTH_CONNECTinAndroidManifest.xml, and request them at runtime. - iOS — in
MarketingCloudSdkConfigBuilder, call.setLocationEnabled(true). AddNSLocationWhenInUseUsageDescription,NSLocationAlwaysAndWhenInUseUsageDescription, andUIBackgroundModes → locationtoInfo.plist. Proximity (beacon) messaging is Android-only.
Usage #
import 'package:sfmc_marketingcloudsdk/sfmc_marketingcloudsdk.dart';
// Initialize the MarketingCloudSdk module
await MarketingCloudSdk.requestSdk();
// Inbox
final refreshed = await MarketingCloudSdk.refreshInbox();
final allMsgs = await MarketingCloudSdk.getAllMessages();
final unreadCount = await MarketingCloudSdk.getUnreadMessageCount();
await MarketingCloudSdk.markMessageRead('message-id');
// Tags
await MarketingCloudSdk.addTag('beta-tester');
final tags = await MarketingCloudSdk.getTags();
// Device identity
final deviceId = await MarketingCloudSdk.getDeviceId();
final contactKey = await MarketingCloudSdk.getContactKey();
// Location & proximity
await MarketingCloudSdk.enableLocation();
await MarketingCloudSdk.startWatchingLocation(); // iOS only
final lastLocation = await MarketingCloudSdk.getLastKnownLocation();
await MarketingCloudSdk.enableProximityMessaging(); // Android only
// Registration callback
await MarketingCloudSdk.setRegistrationCallback();
MarketingCloudSdk.registrationEvents.listen((registration) {
print('MC registration changed: $registration');
});
// Inbox response listener
await MarketingCloudSdk.registerInboxResponseListener((messages) {
print('Inbox updated: ${messages.length} messages');
});
// Cleanup
await MarketingCloudSdk.unsetRegistrationCallback();
API #
| Method | Return | Description |
|---|---|---|
requestSdk() |
Future<void> |
Initialize the MarketingCloudSdk module |
refreshInbox() |
Future<bool> |
Trigger server inbox refresh |
getAllMessages() |
Future<List<InboxMessage>> |
Get all inbox messages |
getUnreadMessages() |
Future<List<InboxMessage>> |
Get unread messages |
getReadMessages() |
Future<List<InboxMessage>> |
Get read messages |
getDeletedMessages() |
Future<List<InboxMessage>> |
Get deleted messages |
getMessageCount() |
Future<int?> |
Total message count |
getUnreadMessageCount() |
Future<int?> |
Unread message count |
getReadMessageCount() |
Future<int?> |
Read message count |
getDeletedMessageCount() |
Future<int?> |
Deleted message count |
markMessageRead(id) |
Future<void> |
Mark a message as read |
markMessageDeleted(id) |
Future<void> |
Mark a message as deleted |
markAllMessagesRead() |
Future<void> |
Mark all messages as read |
markAllMessagesDeleted() |
Future<void> |
Mark all messages as deleted |
trackInboxMessageOpened(id) |
Future<void> |
Track message open analytics |
addTag(tag) |
Future<void> |
Add a tag |
addTags(tags) |
Future<void> |
Add multiple tags |
removeTag(tag) |
Future<void> |
Remove a tag |
removeTags(tags) |
Future<void> |
Remove multiple tags |
getTags() |
Future<List<String>?> |
Get all tags |
getAttributes() |
Future<Map<String, String>?> |
Get all attributes |
getDeviceId() |
Future<String?> |
Get device identifier |
getContactKey() |
Future<String?> |
Get contact key |
enablePiAnalytics() |
Future<void> |
Enable PI analytics |
disablePiAnalytics() |
Future<void> |
Disable PI analytics |
isPiAnalyticsEnabled() |
Future<bool> |
Check PI analytics state |
enableAnalytics() |
Future<void> |
Enable analytics |
disableAnalytics() |
Future<void> |
Disable analytics |
isAnalyticsEnabled() |
Future<bool> |
Check analytics state |
enableLogging() |
Future<void> |
Enable debug logging |
disableLogging() |
Future<void> |
Disable debug logging |
setRegistrationCallback() |
Future<void> |
Start receiving registration change events |
unsetRegistrationCallback() |
Future<void> |
Stop receiving registration change events |
registerInboxResponseListener(listener) |
Future<void> |
Register for inbox message changes |
unregisterInboxResponseListener(listener) |
Future<void> |
Unregister inbox listener |
enableLocation() |
Future<void> |
Enable Location (geofence) messaging |
disableLocation() |
Future<void> |
Disable Location (geofence) messaging |
isLocationEnabled() |
Future<bool> |
Check whether Location (geofence) messaging is enabled |
startWatchingLocation() |
Future<void> |
Start location watching (iOS only — no-op on Android) |
stopWatchingLocation() |
Future<void> |
Stop location watching (iOS only — no-op on Android) |
isWatchingLocation() |
Future<bool> |
Check whether SDK is watching location (iOS only — always false on Android) |
getLastKnownLocation() |
Future<Map<String, String>?> |
Last known device location (iOS only — always null on Android) |
enableProximityMessaging() |
Future<void> |
Enable proximity (beacon) messaging (Android only — no-op on iOS) |
disableProximityMessaging() |
Future<void> |
Disable proximity (beacon) messaging (Android only — no-op on iOS) |
isProximityMessagingEnabled() |
Future<bool> |
Check whether proximity messaging is enabled (Android only — always false on iOS) |
Streams #
| Stream | Type | Description |
|---|---|---|
registrationEvents |
Stream<Map<String, dynamic>> |
Emitted when registration state changes |
Notes #
Installing this package auto-resolves the shared sfmc_core foundation package. sfmc_push and sfmc_iam are independent, opt-in feature packages — add them explicitly with flutter pub add sfmc_push / flutter pub add sfmc_iam if you need push or in-app messaging.
Versions #
- Flutter: >=3.3.0
- Dart SDK: >=3.0.6 <4.0.0
- Android: sfmcsdk 3.1.+, marketingcloudsdk 11.0.+
- iOS: MarketingCloudSDK ~> 11.0.0
License #
BSD 3-Clause.