React Native SDK Reference
Class CredoAppService
CredoAppServiceRepresents the bridge between React native and native SDK
new CredoAppService()Method setForceResolvePermissions()
setForceResolvePermissions()This method is designed to manage permission behavior on iOS. It has no effect on Android.
If it is determined to be true, the SDK will automatically request permissions; otherwise, the SDK will not request permissions.
service.setForceResolvePermissions(false)Parameters:
| Name | Description | Type |
|---|---|---|
value | If The default value is | bool |
Permissions that are not grantedWhen the value is
false, the SDK shows no permission prompts and still runscollectAsync(). Data areas of modules whose permission is not granted contain anAccess deniederror instead of data.
Method setIgnorePermissions()
setIgnorePermissions()This method is designed to manage permission behavior on Android. It has no effect on iOS.
- The method sets if SDK should prevent the run of
collectAsync()if permissions aren't granted. - The
truevalue allows collecting dataset even if not all permissions are granted. Data areas of modules whose permission is not granted contain aPermission Denialerror instead of data. - The
falsevalue restricts collecting dataset from running until all permissions are granted (including normal permissions). If a permission is missing,collectAsync()fails with error code43. - The default value is
true
service.setIgnorePermissions(false)Parameters:
| Name | Description | Type |
|---|---|---|
value | The The default value is | bool |
Method addModuleAsync()
addModuleAsync()The method adds a module to the CredoAppService configuration.
await service.addModuleAsync(new SampleModule())Parameters:
| Name | Description | Type |
|---|---|---|
module | Represents platform module | AndroidCalendarModuleAndroidContactModuleAndroidAccountModuleAndroidImagesModuleAndroidIovationModuleAndroidAudioModuleAndroidVideoModuleAndroidSmsModuleAndroidTelephonyModuleAndroidGuardModuleIosMusicModuleIosCalendarEventsModuleIosCalendarRemindersModuleIosContactModuleIosIovationModuleIosMediaModuleIosApplicationModuleIosTelephonyModuleBehavioralModule |
Returns:
| Type | Description |
|---|---|
Promise | Returns Promise object |
Method addPluginAsync()
addPluginAsync()The method adds a plugin to the CredoAppService configuration.
await service.addPluginAsync(new SamplePlugin())Parameters:
| Name | Description | Type |
|---|---|---|
plugin | Represents plugin | LoggingPlugin |
Returns:
| Type | Description |
|---|---|
Promise | Returns Promise object |
Method collectAsync()
collectAsync()Collects data from the phone and returns locally.
await service.collectAsync()Returns:
| Type | Description |
|---|---|
Promise<String> | Returns JSON dataset in compressed string format if collect action is succeeded or error with code and message |
Error Codes
| Status Code | Reason | Description |
|---|---|---|
| 30 | Duplicated areas error | The extracting areas are duplicated. |
| 43 | Permissions are not granted | Android only. setIgnorePermissions(false) is set and a permission required by a module is missing. |
| 90 | Unknown error | An unexpected error occurred. |
| 91 | The module is not supported | Use a higher plugin version. |
Class BehavioralModule
BehavioralModule is responsible for capturing a client's behavioral interaction with UI and OS for both Android and iOS platforms
new BehavioralModule()Static method BehavioralModule.startTracking()
BehavioralModule.startTracking()Starts behavioral interaction metadata tracking
BehavioralModule.startTracking()Static method BehavioralModule.stopTracking()
BehavioralModule.stopTracking()Terminates behavioral metadata tracking
BehavioralModule.stopTracking()Static method BehavioralModule.addPlugin(plugin)
BehavioralModule.addPlugin(plugin)Attaches behavioral plugin to BehavioralModule instance.
Available plugins - AndroidPhoneBehavioralPlugin, AndroidGuardBehavioralPlugin
BehavioralModule.addPlugin(new AndroidPhoneBehavioralPlugin())
BehavioralModule.addPlugin(new AndroidGuardBehavioralPlugin())
Make sure to add theAndroidPhoneBehavioralPluginafter successfully requesting theREAD_PHONE_STATEpermission, or add plugin immediately afterstartTrackingif the permission has already been granted.
Static method BehavioralModule.setLogger(loggingPlugin)
BehavioralModule.setLogger(loggingPlugin)Attaches LoggingPlugin instance to BehavioralModule
BehavioralModule.setLogger(new LoggingPlugin());Class BehavioralNavigation
BehavioralNavigation is responsible for capturing navigation events
Static method BehavioralNavigation.updateScreen()
BehavioralNavigation.updateScreen()Capture screen name
BehavioralNavigation.updateScreen('OnBoarding')How to use BehavioralNavigation
import { BehavioralNavigation } from '@credolab/react-behavioral';
function App(): JSX.Element {
var navContainer = useNavigationContainerRef()
return (
<GestureHandlerRootView>
<SafeAreaProvider>
<NavigationContainer
ref={navContainer}
onReady={async () => {
BehavioralNavigation.updateScreen(navContainer.getCurrentRoute()?.name ?? "undefined")
}}
onStateChange={async () => {
BehavioralNavigation.updateScreen(navContainer.getCurrentRoute()?.name ?? "undefined")
}}>
<RootNavigator />
</NavigationContainer>
</SafeAreaProvider>
</GestureHandlerRootView>
);
}
export default App;How to use BehavioralModule
It is necessary to call the BehavioralModule.startTracking() method before proceeding to complete the application form. The example is below
const ApplicationFormScreen = ({ navigation, route }: {navigation: NavigationProp<any>, route: RouteProp<RootStackParamList, 'ApplicationFormScreen'>}) => {
useEffect(()=> {
BehavioralModule.startTracking()
}, [])
return (<Text>Application Form screen</Text>)
}
Then pass BehavioralModule instance to CredoAppService to collect behavioral data along with other data
const ApplicationFormCompleteScreen = ({ navigation, route }: {navigation: NavigationProp<any>, route: RouteProp<RootStackParamList, 'ApplicationFormCompleteScreen'>}) => {
onSubmit(async ()=> {
const service = new CredoAppService()
// add other modules: await service.addModuleAsync(new IosMusicModule())
await service.addModuleAsync(new BehavioralModule())
const dataset = await service.collectAsync()
// upload dataset to the credolab server
}, [])
return (<Button onPress={onSubmit}
...code omitted
Highly recommendedFor successful integration, we strongly recommend assigning a value to
testIDproperty , to emphasize a specific logical control or element that holds significance within the User Flow of your app.For example:
<View> <TouchableOpacity testID="submit_button"> <Text>Submit</Text> </TouchableOpacity> </View>
See more examples in our Behavioral Module Identifiers Guide (React Native)
Updated 6 days ago

