Skip to content

Advanced Usage

You can listen to consent events in your activity by adding and removing listeners in the onStart and onStop methods:

// Attach listener
spConsentEngine.addListener("YOUR_APPLICATION_ID", kMobileConsentEventCode);
// Remove listener
spConsentEngine.removeListener(kMobileConsentEventCode);

Here, kMobileConsentEventCode is a unique code you can use to attach/remove event listener.

You can listen to events using the consent stream:

spConsentEngine.consentEventStream.listen((event) {
//Custom logic
});

Enable detailed logs for development:

SPLogger.errorLogsEnabled = true;
SPLogger.infoLogsEnabled = true;
SPLogger.warningLogsEnabled = true;

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.

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.

final result = await spConsentEngine.getClientId("YOUR_APPLICATION_ID");
if(result.code == 200 && result.data!=null){
final 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.

You can get the country code detected by the SDK using:

final countryCode = await spConsentEngine.getLocale("YOUR_APPLICATION_ID");

It returns a country code like US-CA or IN based on the user’s region.

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 spConsentEngine.clearSession();