@salesmanago/mobile-push-sdk-react-native
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Salesmanago Mobile Push SDK for React Native

Requirements and Compatibility

Supported React Native Architectures

  • New Architecture (Fabric): Yes
  • Old Architecture: Yes

Minimum Requirements

  • Android: minSDK version 24 or higher
  • iOS: The SDK supports a minimum iOS 15.0.
  • React Native: Version 0.68.0 or higher

Installation

To install the @salesmanago/mobile-push-sdk-react-native library, follow these steps:

  # using npm
  npm install @salesmanago/mobile-push-sdk-react-native

  # OR using Yarn
  yarn add @salesmanago/mobile-push-sdk-react-native

Initialization

In order to initialize Salesmanago SDK call init() method passing application Context object and API key.

import { Salesmanago } from '@salesmanago/mobile-push-sdk-react-native';

const sdk = new Salesmanago()

sdk.init(<API key>)

API key can be obtained from your Salesmanago dashboard.

Configuration

There is a number of user properties which can be set up with an SDK:

  • Contact data (name, email address, phone number)
  • Marketing consents (email, mobile, monitoring)
  • Additional custom consents
  • List of tags

They can be all set with a single method:

Salesmanago.updateContactProperties({
  contactData: {
    name: "John Doe",
    email: "john.doe@example.com",
    phone: "+48123456789",
    standardDetails: { "custom_field": "custom_value" }
  },
  marketingConsents: {
    email: OptInOption.GRANTED,
    mobile: OptInOption.DENIED,
    monitoring: OptInOption.NO_ANSWER
  },
  additionalConsents: [
    { name: "custom consent", status: OptInOption.DENIED }
  ],
    tagsToAdd: ["tag_to_add"],
    tagsToRemove: ["tag_to_remove"]
});

All parameters are optional so this method can be used to set just some of them. However there are also dedicated methods which can be used to set selected type of user properties.

Contact data:

Salesmanago.updateContactData({
  name: "John Doe",
  email: "john.doe@example.com",
  phone: "+48123456789",
  standardDetails: { "custom_field": "custom_value" }
});

Marketing consents:

Salesmanago.updateContactMarketingConsents({
  email: OptInOption.DENIED,
  mobile: OptInOption.NO_ANSWER,
  monitoring: OptInOption.GRANTED
});

Additional custom consents:

Salesmanago.updateContactAdditionalConsents([
  { name: "some custom consent", status: OptInOption.GRANTED }
]);

Tags:

Salesmanago.addTags(["only_tag_to_add"]);
Salesmanago.removeTags(["only_tag_to_remove"]);

IOS Configuration

InApp notifications

InApp notifications are sent with apns-push-type header set to background. To handle them it is required to implement didReceiveRemoteNotification method in UIApplicationDelegate:

Swift

func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
    Salesmanago.sendDeviceTokenData(deviceToken)
}

ObjC

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    [Salesmanago didReceiveRemoteNotificationWithUserInfo:userInfo];
    completionHandler(UIBackgroundFetchResultNoData);
}

In order to update IOS SDK native version please follow the steps below:

 1. Download the latest version of the ios SDK from the repository.
 2. Open the terminal and navigate to the folder where the SDK is located.
 3. Run the command `make install` to install the SDK in the local repository.
 4. Copy `build/SaleManagoSDK.xcframework` fo `ios` folder.

Android Configuration

Push notifications

Push notifications are sent via Firebase Cloud Messaging. All the Firebase management work is done inside the SDK. The only thing to do is to connect the app with your Firebase project via JSON file generated in your Firebase project dashboard. This file is the same as the one you uploaded to the SALESmanago dashboard. Paste your google-services.json file into the app-level root directory. Next, add the Google services Gradle plugin in your project-level build.gradle file:

plugins {
  // ...
  // dependency for the Google services Gradle plugin
  id("com.google.gms.google-services") version "<version>" apply false
}

and in the app-level build.gradle file:

plugins {
  id("com.android.application")
  // Google services Gradle plugin
  id("com.google.gms.google-services")
  ...
}

Starting from Android 13, your app has to ask a user to permit showing notifications. Without it, the SDK will not be allowed to show the notifications. After the user grants the permission, request the SDK to update its status via updatePushNotificationSystemPermissions() method.

If you want to use deep links in your push notifications, you have to declare it in your app. The AndroidManifest.xml file declares your main activity (usually MainActivity) in <activity> tag. To make this activity able to handle your deep links, you should declare your scheme in a separate intent-filter. For instance, if you create a notification with the deep link salesmanago://main in the SM dashboard, your <activity> tag should contain:

<activity
    ...
    ...

    <intent-filter>
        ...
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="salesmanago" />
    </intent-filter>
</activity>

Package Sidebar

Install

npm i @salesmanago/mobile-push-sdk-react-native

Weekly Downloads

8

Version

1.0.3

License

MIT

Unpacked Size

2.37 MB

Total Files

82

Last publish

Collaborators

  • dev-salesmanago