Salesforce Marketing Cloud

Push notifications and engagement tracking with Salesforce Marketing Cloud

Integrate Salesforce Marketing Cloud MobilePush into your app to manage push notifications, user contact keys, custom attributes, and tags. Median's Salesforce Marketing Cloud Native Plugin wraps the iOS SDK and Android SDK to provide native push notification support with device registration and audience targeting.

The plugin enables you to prompt for push notification permissions, set and retrieve contact keys for user identification, manage custom attributes and tags for audience segmentation, and retrieve device registration information.

App Configuration

The Salesforce Marketing Cloud plugin requires your MobilePush app credentials. Configure them in the App Studio, on the Native Plugins tab under "Advanced Mode":

{
  "salesforceCloud": {
    "active": true,
    "appID": "YOUR_APP_ID",
    "accessToken": "YOUR_ACCESS_TOKEN",
    "appEndpoint": "https://YOUR_ENDPOINT.push.salesforce.com",
    "mid": "YOUR_MID",
    "requiresUserPrivacyConsent": false,
    "delayRegistrationUntilContactKeyIsSet": false
  }
}
ParameterTypeDescription
activebooleanEnable or disable the plugin.
appIDstringYour Salesforce Marketing Cloud App ID.
accessTokenstringYour Salesforce Marketing Cloud Access Token.
appEndpointstringYour Marketing Cloud push endpoint URL.
midstringYour Marketing Cloud MID (Member ID).
requiresUserPrivacyConsentbooleanOptional. If true, the SDK waits for explicit user consent before initializing. Default: false.
delayRegistrationUntilContactKeyIsSetbooleanOptional. If true, delays SDK registration until a contact key is set. Default: false.
📘

SDK Initialization

The Salesforce Marketing Cloud SDK is automatically initialized at app launch using the credentials from the server configuration. On iOS, if requiresUserPrivacyConsent is false, the plugin also automatically prompts for notification permissions on first launch.

Implementation Guide

Prompt for Push Notifications

Request push notification permission from the user. On Android 13+ this triggers the system permission dialog. On older Android versions, notifications are enabled by default.

To prompt for push notifications:

const result = await median.salesforceCloud.promptNotification();

// result object
{
  granted: true | false
}

Check Notification Status

Check whether push notifications are currently enabled for the app.

To check notification status:

const result = await median.salesforceCloud.notificationEnabled();

// result object
{
  granted: true | false
}

Get Device Info

Retrieve the device registration information from the Salesforce Marketing Cloud SDK.

To get device registration info:

const result = await median.salesforceCloud.getInfo();

// result object
{
  deviceToken: "...",
  pushEnabled: true | false,
  deviceId: "...",
  notificationUserInfo: {}     // iOS only
}

Set Contact Key

Set the contact key (profile ID) to identify the user in Salesforce Marketing Cloud.

To set a contact key:

const result = await median.salesforceCloud.contactKey.set({
  contactKey: 'user_12345'
});

// result object
{
  success: true | false,
  error: "..."             // present on failure
}

Parameters

ParameterTypeDescription
contactKeystringRequired. The contact key to identify the user.

Get Contact Key

Retrieve the currently set contact key.

To get the current contact key:

const result = await median.salesforceCloud.contactKey.get();

// result object
{
  success: true | false,
  contactKey: "user_12345",
  error: "..."             // present on failure (iOS)
}

Set Attributes

Set custom profile attributes on the Salesforce contact for audience segmentation.

To set attributes:

const result = await median.salesforceCloud.attributes.set({
  attributes: {
    firstName: 'Jane',
    lastName: 'Doe',
    plan: 'premium'
  }
});

// result object
{
  success: true | false,
  error: "..."             // present on failure
}

Parameters

ParameterTypeDescription
attributesobjectRequired. Key-value pairs (all values must be strings).

Get Attributes

Retrieve all profile attributes currently set on the device.

To get attributes:

const result = await median.salesforceCloud.attributes.get();

// result object
{
  success: true,
  attributes: {
    firstName: "Jane",
    lastName: "Doe",
    plan: "premium"
  }
}

Set Tags

Add tags to the device for audience segmentation.

To set tags:

// Add a single tag (iOS and Android)
const result = await median.salesforceCloud.tags.set({
  tag: 'premium_user'
});

// Add multiple tags (Android only)
const result = await median.salesforceCloud.tags.set({
  tags: ['premium_user', 'newsletter_subscriber', 'beta_tester']
});

// result object
{
  success: true | false,
  error: "..."             // present on failure
}

Parameters

ParameterTypeDescription
tagstringOptional. A single tag to add (iOS and Android).
tagsstring[]Optional. An array of tags to add (Android only).
📘

Platform Differences

On iOS, only the tag parameter is supported (single tag at a time). On Android, both tag and tags are supported. Passing an empty tags array on Android will clear all existing tags.

Get Tags

Retrieve all tags currently set on the device.

To get tags:

const result = await median.salesforceCloud.tags.get();

// result object
{
  success: true,
  tags: ["premium_user", "newsletter_subscriber"]
}

Delete a Tag (iOS Only)

Remove a single tag from the device registration. This method is only available on iOS.

To delete a tag:

const result = await median.salesforceCloud.tags.delete({
  tag: 'premium_user'
});

// result object
{
  success: true | false,
  error: "..."             // present on failure
}

Parameters

ParameterTypeDescription
tagstringRequired. The tag to remove.