Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@allboatsrise/expo-marketingcloudsdk

Package Overview
Dependencies
Maintainers
0
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allboatsrise/expo-marketingcloudsdk

Expo module for Salesforce Marketing Cloud SDK

  • 51.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@allboatsrise/expo-marketingcloudsdk

This is an Expo module that provides a wrapper around the Salesforce Marketing Cloud 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 NameParametersReturn TypeDescription
isPushEnabledNonePromise<boolean>Returns a promise that resolves to a boolean indicating whether push notifications are enabled for the user.
enablePushNonePromise<void>Returns a promise that resolves when push notifications have been successfully enabled.
disablePushNonePromise<void>Returns a promise that resolves when push notifications have been successfully disabled.
getSystemTokenNonePromise<string>Returns a promise that resolves to a string representing the device's push notification token.
setSystemTokentoken: stringPromise<void>Returns a promise that resolves when the device's push notification token has been successfully set.
getAttributesNonePromise<Record<string, string>>Returns a promise that resolves to an object representing the user's attributes.
setAttributekey: string, value: stringPromise<void>Returns a promise that resolves when an attribute has been successfully set for the user.
clearAttributekey: stringPromise<void>Returns a promise that resolves when an attribute has been successfully cleared for the user.
addTagtag: stringPromise<void>Returns a promise that resolves when a tag has been successfully added for the user.
removeTagtag: stringPromise<void>Returns a promise that resolves when a tag has been successfully removed for the user.
getTagsNonePromise<string[]>Returns a promise that resolves to an array of strings representing the user's tags.
setContactKeycontactKey: stringPromise<void>Returns a promise that resolves when the user's contact key has been successfully set.
getContactKeyNonePromise<string>Returns a promise that resolves to a string representing the user's contact key.
getSdkStateNonePromise<Record<string, unknown>>Returns a promise that resolves to an object representing the current state of the SDK.
trackname: string, attributes: Record<string, string>Promise<void>Returns a promise that resolves when a custom event has been successfully tracked.
deleteMessagemessageId: stringPromise<void>Returns a promise that resolves when a specific inbox message has been successfully deleted.
getDeletedMessageCountNonePromise<number>Returns a promise that resolves to a number representing the total number of deleted inbox messages.
getDeletedMessagesNonePromise<InboxMessage[]>Returns a promise that resolves to an array of InboxMessage objects representing the deleted inbox messages.
getMessageCountNonePromise<number>Returns a promise that resolves to a number representing the total number of inbox messages.
getMessagesNonePromise<InboxMessage[]>Returns a promise that resolves to an array of InboxMessage objects representing the inbox messages.
getReadMessageCountNonePromise<number>Returns a promise that resolves to a number representing the total number of read inbox messages.
getReadMessagesNonePromise<InboxMessage[]>Returns a promise that resolves to an array of InboxMessage objects representing the read inbox messages.
trackMessageOpenedmessageId: stringPromiseReturns a promise that resolves to true when inbox open event successfully triggered on message.

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()
    }
}, [])

Keywords

FAQs

Package last updated on 06 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc