React Native SDK Reference

Class CredoAppService

Represents the bridge between React native and native SDK

new CredoAppService()

Method setForceResolvePermissions()

This method is designed to manage permission behavior on iOS.

If it is determined to be true, the SDK will automatically request permissions; otherwise, the SDK will not request permissions.

service.setForceResolvePermissions(false)

Parameters:

NameDescriptionType
valueIf true then SDK requests permissions automatically otherwise SDK omits requesting permissions.

The default value is true.
bool

📘

IosMusicModule

Even when the value is set to false, the Music permission (NSAppleMusicUsageDescription in IosMusicModule module) will be automatically requested by the SDK when data is requested.

Method setIgnorePermissions()

This method is designed to manage permission behavior on Android.

  • The method sets if SDK should prevent the run of collectAsync() if permissions aren't granted.
  • The true value allows collecting dataset even if not all permissions are granted.
  • The false value restricts collecting dataset from running until all permissions are granted (including normal permissions).
  • The default value is true
service.setIgnorePermissions(false)

Parameters:

NameDescriptionType
valueThe true value allows data collection even if not all permissions are granted. The false value restricts data collection until all permissions (including normal permissions) are granted.

The default value is true.
bool

Method addModuleAsync()

The method adds a module to the CredoAppService configuration.

await service.addModuleAsync(new SampleModule())

Parameters:

NameDescriptionType
moduleRepresents platform moduleAndroidApplicationModule
AndroidCalendarModule
AndroidContactModule
AndroidAccountModule
AndroidImagesModule
AndroidIovationModule
AndroidAudioModule
AndroidVideoModule
AndroidSmsModule
IosMusicModule
IosCalendarEventsModule
IosCalendarRemindersModule
IosContactModule
IosIovationModule
IosMediaModule

Returns:

TypeDescription
PromiseReturns Promise object

Method collectAsync()

Collects data from the phone and returns locally.

await service.collectAsync()

Returns:

TypeDescription
Promise<String>Returns JSON dataset in compressed string format if collect action is succeeded or error with code and message

Error Codes

Status CodeReasonDescription
30Duplicated areas errorThe extracting areas are duplicated.
90Unknown errorAn unexpected error occurred.
91The module is not supportedUse 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()

Starts behavioral interaction metadata tracking

BehavioralModule.startTracking()

Static method BehavioralModule.stopTracking()

Terminates behavioral metadata tracking

BehavioralModule.stopTracking()

Class BehavioralNavigation

BehavioralNavigation is responsible for capturing navigation events

Static method 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 recommended

For successful integration, we strongly recommend assigning a value to testID property , 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)