@allboatsrise/expo-marketingcloudsdk

中文文档
55.0.2发布于 2026/11/07MITTypeScriptCommonJS零依赖近 30 天下载 1.7万

Expo module for Salesforce Marketing Cloud SDK

原始使用文档
文档目录6 节
  1. Installation
  2. Plugin setup
  3. Plugin parameters
  4. Functions
  5. Add event listener
  6. Notification Response Handling

@allboatsrise/expo-marketingcloudsdk

This is an Expo module that provides a wrapper around the Salesforce Marketing Cloud (SFMC) SDK for iOS and Android.

It allows Expo-based apps to integrate with the Marketing Cloud SDK.

Installation

To install the package use your preferred package manager:

npm install @allboatsrise/expo-marketingcloudsdk expo-notifications zod

or

yarn add @allboatsrise/expo-marketingcloudsdk expo-notifications zod

Plugin setup

View parameters

Add package to plugins in app.js/app.config.js with minimal configuration.

"expo": {
  "plugins": [
    [
      "@allboatsrise/expo-marketingcloudsdk", {
        "appId": "<< MARKETING_CLOUD_APP_ID >>",
        "accessToken": "<< MARKETING_CLOUD_ACCESS_TOKEN >>",
        "serverUrl": "<< MARKETING_CLOUD_SERVER_URL >>",
      }
    ],
    "expo-notifications"
    ]
}

Sample initialization of notifications in the app

import * as Notifications from 'expo-notifications'
import * as MarketingCloud from '@allboatsrise/expo-marketingcloudsdk'

// ensure push notifications appear regardless whether app is active or not
Notifications.setNotificationHandler({
  handleNotification: async (_notification) => {
    return {
      shouldShowAlert: true,
      shouldPlaySound: true,
      shouldSetBadge: true,
    }
  },
})

export const App: React.FC = () => {
  useEffect(() => {
    let cleanup = () => {}

    ;(async () => {
      // request push notifications permission on load
      // ideally: show this elsewhere where it's more relevant instead of as soon as when the ap loads
      let result = await Notifications.getPermissionsAsync()
      if (!result.granted && result.canAskAgain) {
        result = await Notifications.requestPermissionsAsync({
          ios: {
            allowAlert: true,
            allowBadge: true,
            allowSound: true,
          },
        })
      }

      if (!result.granted) return

      const token = await Notifications.getDevicePushTokenAsync()

      // let Marketing Cloud SDK the value of current push token
      MarketingCloud.setSystemToken(token.data)

      // In rare situations a push token may be changed by the push notification service while the app is running.
      const subscription = Notifications.addPushTokenListener((newToken) => {
        MarketingCloud.setSystemToken(newToken.data)
      })
      cleanup = () => subscription.remove()
    })()

    return () => cleanup()
  }, [])

  // remaining app logic...
}

Plugin parameters

ParameterTypeRequiredDescription
appIdstringYesMarketing Cloud app id
accessTokenstringYesMarketing Cloud access token
serverUrlstringYesMarketing Cloud server url
senderId (Android only)stringNoMarketing Cloud FCM sender id. Defaults to project_info.project_number defined in android.googleServicesFile (google-services.json) if defined.
midstringNoSets the configuration value to use for the Salesforce MarketingCloud Tenant Specific mid.
inboxEnabledbooleanNoSets the configuration flag that enables or disables inbox services
locationEnabledbooleanNoSets the configuration flag that enables or disables location services
analyticsEnabledbooleanNoSets the configuration flag that enables or disables Salesforce MarketingCloud Analytics services
applicationControlsBadgingbooleanNoSets the configuration value which enables or disables application control over badging
delayRegistrationUntilContactKeyIsSetbooleanNoSets the configuration value which enables or disables application control over delaying SDK registration until a contact key is set
markNotificationReadOnInboxNotificationOpenbooleanNoSets the configuration value which enables or disables marking inbox notifications as read on open
debugbooleanNoEnable logging debug messages

Usage

Various functions, their parameters, return values, and their specific purposes in ExpoMarketingCloudSdk

Functions

Function NameDescription
isPushEnabledReturns a promise that resolves to a boolean indicating whether push notifications are enabled for the user.
enablePushReturns a promise that resolves when push notifications have been successfully enabled.
disablePushReturns a promise that resolves when push notifications have been successfully disabled.
getSystemTokenReturns a promise that resolves to a string representing the device's push notification token.
setSystemTokenReturns a promise that resolves when the device's push notification token has been successfully set.
getAttributesReturns a promise that resolves to an object representing the user's attributes.
setAttributeReturns a promise that resolves when an attribute has been successfully set for the user.
clearAttributeReturns a promise that resolves when an attribute has been successfully cleared for the user.
addTagReturns a promise that resolves when a tag has been successfully added for the user.
removeTagReturns a promise that resolves when a tag has been successfully removed for the user.
getTagsReturns a promise that resolves to an array of strings representing the user's tags.
setContactKeyReturns a promise that resolves when the user's contact key has been successfully set.
getContactKeyReturns a promise that resolves to a string representing the user's contact key.
getSdkStateReturns a promise that resolves to an object representing the current state of the SDK.
trackReturns a promise that resolves when a custom event has been successfully tracked.
deleteMessageReturns a promise that resolves when a specific inbox message has been successfully deleted.
getDeletedMessageCountReturns a promise that resolves to a number representing the total number of deleted inbox messages.
getDeletedMessagesReturns a promise that resolves to an array of InboxMessage objects representing the deleted inbox messages.
getMessageCountReturns a promise that resolves to a number representing the total number of inbox messages.
getMessagesReturns a promise that resolves to an array of InboxMessage objects representing the inbox messages.
getReadMessageCountReturns a promise that resolves to a number representing the total number of read inbox messages.
getReadMessagesReturns a promise that resolves to an array of InboxMessage objects representing the read inbox messages.
trackMessageOpenedReturns a promise that resolves to true when inbox open event successfully triggered on message.
isAnalyticsEnabledReturns a promise that resolves to a boolean indicating whether analytics are enabled for the user.
enableAnalyticsReturns a promise that resolves when analytics have been successfully enabled.
disableAnalyticsReturns a promise that resolves when analytics have been successfully disabled.
isSfmcNotificationResponseCheck if a notification response NotificationResponse originated from SFMC.
extractPayloadFromSfmcNotificationResponseExtract payload info from SFMC notification reponse.
useLastSfmcNotificationResponseA React hook that always returns the SFMC notification response that was received most recently.

Add event listener

Available event listeners:

FunctionParametersDescription
addLogListenerlistener: (event: LogEventPayload) => voidAdds a listener function to the onLog event, which is triggered when a new log event is generated.
addInboxResponseListenerlistener: (event: InboxResponsePayload) => voidAdds a listener function to the onInboxResponse event, which is triggered when a new inbox response is received.
addRegistrationResponseSucceededListenerlistener: (event: RegistrationResponseSucceededPayload) => voidAdds a listener function to the onRegistrationResponseSucceeded event, which is triggered when SDK successfully registers with backend.
// listeners being used in a useEffect hook.

useEffect(() => {
    const logSubscription = addLogListener((logEvent: LogEventPayload) => {
        // Do something with logEvent
      })

    const inboxSubscription = addInboxResponseListener((inboxEvent: InboxResponsePayload) => {
        // Do something with inboxEvent
      })

    const registrationSubscription = MarketingCloud.addRegistrationResponseSucceededListener((registrationEvent: RegistrationResponseSucceededPayload) => {
      // Do something with registrationEvent
    })

    return () => {
      logSubscription.remove()
      inboxSubscription.remove()
      registrationSubscription.remove()
    }
}, [])

Notification Response Handling

Use useLastSfmcNotificationResponse hook to listen for last notification that the user interacted with that originated from SFMC.

import { useLastSfmcNotificationResponse } from '@allboatsrise/expo-marketingcloudsdk'

const { response, payload } = useLastSfmcNotificationResponse()

useEffect(() => {
  if (!payload) return

  if (responsePayload.openDirectUrl) {
    // e.g. open url in the browser
  }
}, [payload])

Alternatively use isSfmcNotificationResponse to check if the response from useLastNotificationResponse originated from SFMC and then extract the payload using extractPayloadFromSfmcNotificationResponse

import { useLastNotificationResponse } from 'expo-notifications'
import { isSfmcNotificationResponse, extractPayloadFromSfmcNotificationResponse } from '@allboatsrise/expo-marketingcloudsdk'

const response = useLastNotificationResponse()

useEffect(() => {
  if (!response) return
  if (!isSfmcNotificationResponse(response)) return
  const payload = extractPayloadFromSfmcNotificationResponse(response)
  
  if (responsePayload.openDirectUrl) {
    // e.g. open url in the browser
  }
}, [payload])

版本与发布记录

@allboatsrise/expo-marketingcloudsdk 共发布 103 个版本,首次发布于 2021/12/09;过去 12 个月发布了 4 个版本。

版本发布日期距今
55.0.2latest2026/11/07今天
55.0.12026/05/135 个月前
55.0.02026/04/276 个月前
55.0.0-beta.0beta2026/04/276 个月前
54.0.12025/10/071.1 年前
54.0.02025/10/011.1 年前

其他发布通道:android → 47.0.0-android.27,beta → 55.0.0-beta.0。

关于 @allboatsrise/expo-marketingcloudsdk 的常见问题

@allboatsrise/expo-marketingcloudsdk 是什么?

Expo module for Salesforce Marketing Cloud SDK

如何安装 @allboatsrise/expo-marketingcloudsdk?

在项目目录运行 npm install @allboatsrise/expo-marketingcloudsdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^4.0.0)、expo-notifications(>=55.0.20)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@allboatsrise/expo-marketingcloudsdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@allboatsrise/expo-marketingcloudsdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@allboatsrise/expo-marketingcloudsdk 可以商用吗?

@allboatsrise/expo-marketingcloudsdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@allboatsrise/expo-marketingcloudsdk 的下载量有多少?

根据 npm 官方下载统计,@allboatsrise/expo-marketingcloudsdk 在 2026/10/06 – 2026/11/04 这 30 天内被下载 17,210 次,日均约 574 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@allboatsrise/expo-marketingcloudsdk 还在维护吗?

最新版本 55.0.2 发布于 2026/11/07(今天);至今共发布 103 个版本,其中过去 12 个月发布了 4 个;首次发布于 2021/12/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。