GuidesDiscussions
Log In
Guides

Additional Methods React

SDK Invocation and Functions

For use the plugin you need import to your class:

import SiprocalPluginModule from "siprocalsdk-reactnative-plugin"; 

Common methods for Android and iOS

Custom Org Selection (Optional):

If the client wishes to make the same app available for different organizations, they can achieve this by calling the following API to the Siprocal SDK.

SiprocalPluginModule.setCountryCodeSelected(countryCode) 

Opt-In/Opt-Out Settings:

The host application can provide an option to the users to Opt-In and Opt-Out of the Ads services. The same can be accomplished via the following methods to access or update the Status.
The method accepts boolean value. When TRUE is passed, the user is Opted-In to the Ad services and when FALSE is passed, the user is Opted-Out of the Ad Service.

To update Opt-In status:

SiprocalPluginModule.updateOptInStatus(optinValue)

To get Opt-in status:

SiprocalPluginModule.getOptInStatus().then((data) => { 
	const optinValue = data 
}); 

ClientAttributes:

In some cases, the Host application may need to pass attributes to the Siprocal SDK. This is supported with the ClientAttributes class provided as a part of the SDK.

Note: Avoid Data Override: Please note that all values need to be passed together to the SDK before the setClientAttributes method is called. Calling the method multiple times will overwrite the previous data, and only the new value will be available and sent to Siprocal servers.

The following code snippet shows how this can be done.

const json = { CUSTOM_CLIENT_ATTRIBUTE: ‘custom value’ }; 
SiprocalPluginModule.setClientAttributes(JSON.stringify(json)); 

The following are the keys which we have pre-defied.

  • Phone number - "PHONE_NUMBER"
  • Carrier - "CARRIER"
  • Bill type - "BILL_TYPE" // POSTPAY or PREPAY.

In addition to the keys above you are free to add your own keys, Siprocal would be storing the information in DB for future reference.

Methods available for Android

Enable/Disable capture of Sensitive Data:

Capturing sensitive data requires a prominent disclosure, and the user must consent to the app's data capture and usage. If the user consents, the app should send a boolean flag using the following method:

SiprocalPluginModule.setSensitiveDataSwitch(sensitiveValue) 

Turn ON/OFF the SDK:

If you want to handle the turning on and off of the SDK, add the method activeSDKManually() to the SiprocalSDKSettings:

Note: The SDK by default is OFF, you need use setSDKStatus for Turn On the SDK.
That way you can then use the following method to turn it on/off:

SiprocalPluginModule.setSDKStatus(sdkEnable) 

Notification Channel

If you need to know information about the SDK notification channel you can use the following methods.

SiprocalPluginModule.getNotificationChannelId().then((data) => { 
	const notificationChannelId = data 
}); 
 
SiprocalPluginModule.getNotificationChannelName()().then((data) => { 
	const notificationChannelName = data 
}); 

FCM Push Integration (Optional)

FCM integration in Android for Host Apps with existing FCM implementation :

Follow these steps if your application has Firebase Cloud Messaging (FCM). If not you can skip this section.

To get the App token and handle the push notification when App is in foreground, added the next code in the file App.tsx

import { NativeModules } from 'react-native'; 
const { SiprocalPluginModule } = NativeModules; 
 
export default function App() { 
  React.useEffect(() => { 
    if (Platform.OS === 'android') { 
      PermissionsAndroid.request( 
        PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS 
      );// for Android 13+ 
 
      messaging().onMessage(async (remoteMessage) => { 
        const siprocalFcmSenderId = await SiprocalPluginModule.getFCMSenderId(); 
        if ( 
          Platform.OS === "android" && 
          siprocalFcmSenderId === remoteMessage.from 
        ) { 
          const jsonString = JSON.stringify(remoteMessage.data); 
          SiprocalPluginModule.invokeFCM(jsonString); 
        } 
      }); 
 
      messaging().onTokenRefresh((token) => { 
        // HostApp can handle the FCM token here... 
        SiprocalPluginModule.refreshToken(); 
      }); 
    } 
  }, []); 
} 

App in Background

When App is in Background, include the following sample code to your index.js file.

import { NativeModules } from 'react-native'; 
const { SiprocalPluginModule } = NativeModules; 
 
messaging().setBackgroundMessageHandler(async (remoteMessage) => { 
  const siprocalFcmSenderId = await SiprocalPluginModule.getFCMSenderId(); 
  if (Platform.OS === "android" && siprocalFcmSenderId === remoteMessage.from) { 
    const jsonString = JSON.stringify(remoteMessage.data); 
    SiprocalPluginModule.invokeFCM(jsonString); 
  } 
}); 
 

Notification Center (Only available for Android)

If Host Application supports for showing of Notifications inside the App, then this functionality can be utilised. This is completely an optional feature set.

Open your index.js file.

import SiprocalPluginModule from "siprocalsdk-reactnative-plugin"; 
 
SiprocalPluginModule.onNotificationDataListener() 
  .then((notificationData) => { 
//notificationData is a string that can be conver in a JsonObject 
const jsonData = JSON.parse(notificationData); 
/**SAMPLE DATA 
{ 
  "adId": 123456789, 
  "actionUrl": "https://example.com/action", 
  "actionType": 1, 
  "category": "news", 
  "actionId": "action123", 
  "createdAt": 1627687200000, 
  "startedAt": 1627690800000, 
  "finalizedAt": 1627694400000, 
  "notificationTitle": "New Notification", 
  "notificationDescription": "This is a sample notification description.", 
  "icon": "https://example.com/icon.png", 
  "bigImage": "https://example.com/bigimage.png" 
} */ 
  }) 
  .catch((error) => { 
    console.error('Error receiving data:', error); 
  }); 
 
SiprocalPluginModule.onNotificationEventListener() 
  .then((notificationEvent) => { 
const jsonData = JSON.parse(notificationEvent); 
/**SAMPLE DATA 
{ 
  "adId": 123456789, 
  “notificationEventType”:”CLICK” 
} 
*/ 
  }) 
  .catch((error) => { 
    console.error('Error receiving data:', error); 
  }); 

Send Notification Event

If the host app wishes to synchronize the actions between notification center and device's
notification center, the method below should be used to send informations about campaigns' events to
Siprocal SDK

import SiprocalPluginModule from "siprocalsdk-reactnative-plugin"; 
 
SiprocalPluginModule.sendNotificationEventFromHostApp( 
              Number(adId), 
              NotificationEventType.CLICK); 

Methods available for iOS

Request Push Notification Permission:

SiprocalPluginModule.requestPushPermissioniOS() 

App Tracking Permission:

Siprocal SDK needs to request App Tracking permission from the user to collect IDFA details and track user activity on DR Platform. Below is the sample code to invoke the same from any View Controller class.

SiprocalPluginModule.requestAppTrackingTransparencyPermissioniOS()