Advanced Usage
Listening to Consent Events
Section titled “Listening to Consent Events”You can listen to consent events in your activity by adding and removing listeners in the onStart and onStop methods:
import { SecurePrivacyMobileConsent, SPDataMessage, SPConsentEvent} from '@secureprivacy/react-native-mobile-consent';
// Subscribe to consent eventsconst subscription = SecurePrivacyMobileConsent.onConsentEvent('YOUR_APPLICATION_ID', MOBILE_CONSENT_EVENT_CODE, (event: SPDataMessage<SPConsentEvent>) => { //Custom logic});
// Unsubscribe consent eventssubscription.unsubscribe();Here, MOBILE_CONSENT_EVENT_CODE is a unique code you can use to attach/remove event listener.
Debugging and Logs
Section titled “Debugging and Logs”Enable detailed logs for development:
import { SecurePrivacyMobileConsent, SPLogType } from '@secureprivacy/react-native-mobile-consent';
SecurePrivacyMobileConsent.setLogConfig([ { type: SPLogType.ERROR, enabled: true }, { type: SPLogType.INFO, enabled: false }, { type: SPLogType.WARNING, enabled: false },]);These settings will enable:
- Error Logs – to capture critical issues.
- Info Logs – for general SDK activity and flow.
- Warning Logs – to monitor potential misconfigurations or unexpected behavior.
⚠️ Tip: Disable logging in production to avoid exposing sensitive data.
Handling Unique Client ID
Section titled “Handling Unique Client ID”Each time the app is installed (fresh install) or during a new session, Secure Privacy Mobile Consent SDK generates a unique clientId for the user. This clientId can be retrieved by calling the following method.
const result = await SecurePrivacyMobileConsent.getClientId('YOUR_APPLICATION_ID');if(result.code == 200 && result.data!=null){ const clientId = result.data;} else { // handle error}This clientId can be used to associate the user’s consent with internal identifiers within your app or backend systems. You can also use this clientId for custom user identification and to ensure accurate tracking of consent preferences.
Get Country Code
Section titled “Get Country Code”You can get the country code detected by the SDK using:
const result = await SecurePrivacyMobileConsent.getLocale('YOUR_APPLICATION_ID');if(result.code == 200 && result.data!=null){ const locale == result.data;} else { // handle error}It returns a country code like US-CA or IN based on the user’s region.
Clearing Session
Section titled “Clearing Session”To clear the session, call clearSession(). This method is useful when you want to ensure that all local session-specific sdk data is cleared. It is typically used when a user logs out or resets their preferences.
await SecurePrivacyMobileConsent.clearSession();