@crowdfarming/marketing-cloud
v1.1.0
Published
Capacitor plugin for the Salesforce Marketing Cloud MobilePush SDK
Maintainers
Readme
@crowdfarming/marketing-cloud
Capacitor plugin for the Salesforce Marketing Cloud MobilePush SDK (iOS + Android).
v1.0.0 replaces the old Cordova plugin (
@crowdfarming/cordova-plugin-marketingcloudsdk). Works with both CocoaPods and Swift Package Manager on iOS.
Install
npm install @crowdfarming/marketing-cloud
npx cap syncConfiguration
iOS
The SDK is initialized on plugin load from capacitor.config.ts:
plugins: {
MarketingCloud: {
appId: '...',
accessToken: '...',
serverUrl: 'https://xxxx.device.marketingcloudapis.com/',
analyticsEnabled: true,
delayRegistrationUntilContactKeyIsSet: true
}
}The APNs device token must be forwarded to the SDK from the app's AppDelegate:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
SFMCSdk.mp.setDeviceToken(deviceToken)
}Android
The SDK is initialized before Application.onCreate by a ContentProvider that reads
the Cordova-style preferences from res/xml/config.xml, generated by Capacitor from
capacitor.config.ts:
cordova: {
preferences: {
"com.salesforce.marketingcloud.app_id": "...",
"com.salesforce.marketingcloud.access_token": "...",
"com.salesforce.marketingcloud.tenant_specific_endpoint": "https://xxxx.device.marketingcloudapis.com/",
"com.salesforce.marketingcloud.notification_small_icon": "ic_notification",
"com.salesforce.marketingcloud.analytics": "true",
"com.salesforce.marketingcloud.delay_registration_until_contact_key_is_set": "true"
}
}The consuming app must add the Salesforce Maven repository to its root android/build.gradle:
allprojects {
repositories {
google()
mavenCentral()
maven { url = "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
}
}API
import { MarketingCloud } from '@crowdfarming/marketing-cloud';
await MarketingCloud.isInitialized(); // { initialized: boolean }
await MarketingCloud.setContactKey({ contactKey: 'SF_CONTACT_ID' });
await MarketingCloud.setAttribute({ key: 'brand', value: 'CROWDFARMING' });
await MarketingCloud.getSystemToken(); // { token: string }
await MarketingCloud.enableLogging(); // verbose native SDK logs (QA)
await MarketingCloud.logSdkState(); // dumps SDK state to device logOnly the surface used by cf-shell-app is exposed. The rest of the MobilePush SDK
(tags, analytics toggles, events…) can be added on demand.
