Skip to content

Applying Service Consent

Now that you have collected your user's consent, it is fundamental that you apply these choices to your third-party frameworks.

Template ID

The way to match services defined in the CMP and frameworks running on your app, is the templateID. This unique ID represents the legal specifications of a defined service, such as:

  • Firebase
  • Google Ads
  • Unity Ads
  • Adjust

You will find this ID in the expanded view of each service, under "Service Settings" > "Data Processing Services" in the Admin Interface.

TemplateID

Essential Services

Essential services are those who are required to provide core functionality. These services are opted-in by default and users cannot opt-out. Which means, they can be initialized at any moment, without waiting for user consent.

Setting a Service as Essential

A service will be essential if you add it to the default "Essential" category, or any custom categories that has been set as essential.

Essential Service

Please consult your Data Protection Officer before defining essential services.

There are two main moments when you should apply consent:

Once consent has been collected, you should immediately apply it to your frameworks via the callback of the Usercentrics UI:

Available starting v2.2.0

banner.showFirstLayer(...) { userResponse in
    self.applyConsent(with: userResponse.consents)
}
banner.showFirstLayer(...) { userResponse ->
    applyConsent(userResponse?.consents)
}
final userResponse = await Usercentrics.showFirstLayer(...);
applyConsent(userResponse?.consents);
import { Usercentrics } from '@usercentrics/react-native-sdk';

const userResponse = await Usercentrics.showFirstLayer(...);
applyConsent(userResponse.consents);

Deprecated

As Banner API v2 is now live, we have discontinue support for Banner API v1. Please consider:

  • Banner API v2 fully replaces v1 and adds a lot more capabilities and functionality. We highly recommend upgrading.
  • If you do not have time or resources to upgrade, please stick to v2.1.0 or lower to avoid any unexpected content or behaviour changes,
  • Banner API v1 has been removed starting v2.3.0.
var usercentricsUI: UIViewController?
usercentricsUI = UsercentricsUserInterface.getPredefinedUI { userResponse in
    // Apply Consent
    self.applyConsent(with: userResponse.consents)

    // Dismiss CMP
    usercentricsUI.dismiss(animated: true, completion: nil)
}

// Present CMP
self.present(usercentricsUI, animated: true, completion: nil)
private val usercentricsActivityLauncher = registerForActivityResult(UsercentricsActivityContract()) { userResponse ->
    applyConsent(userResponse?.consents)
}
What to do in projects without AndroidX and old Android API levels?

You have to invoke manually startActivityForResult and process the result in the onActivityResult. You can still use UsercentricsActivityContract for that purpose:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == <XXXX>) {
        val userResponse = UsercentricsActivityContract().parseResult(resultCode, data)
        applyConsent(userResponse?.consents)
    }
}
private val usercentricsView by lazy { findViewById<UsercentricsPredefinedUI>(R.id.usercentrics_view) }
...
// For example in the `onCreate` of your Activity/Fragment
usercentricsView.load { userResponse ->
    applyConsent(userResponse?.consents)

    // Dismiss the CMP - finish your Activity/Fragment, remove the view, and so on
    finish()
}
final userResponse = await Usercentrics.showCMP();
applyConsent(userResponse?.consents);
import { Usercentrics } from '@usercentrics/react-native-sdk';

let userResponse = await Usercentrics.showCMP(<UsercentricsUIOptions>);
applyConsent(userResponse.consents);

or when storing consent via API, when building your own CMP:

let consents = UsercentricsCore.shared.acceptAll(consentType: .explicit_) // also applies for "deny all" and "save" methods
self.applyConsent(with: consents)
val consents = Usercentrics.instance.acceptAll(consentType = UsercentricsConsentType.EXPLICIT)
applyConsent(consents)
final consents = Usercentrics.acceptAll(consentType: UsercentricsConsentType.explicit);
applyConsent(consents);
const consents = Usercentrics.acceptAll(UsercentricsConsentType.explicit);
applyConsent(consents);

After SDK initialization

On first init, there won't be any consent stored, and you will need to show the CMP, in order to collect consent. However, on any future initializations you will need to apply the already stored consent as soon as possible. For this, the UsercentricsReadyStatus has the stored consent, which you can pass to your applyConsent function.

UsercentricsCore.isReady { status in
    if status.shouldCollectConsent {
        // Collect Consent
    } else {
        self.applyConsent(with: status.consents)
    }
} onFailure: { error in 
    // Handle non-localized error
}
Usercentrics.isReady({ status ->
    if (status.shouldCollectConsent) {
        // Collect Consent
    } else {
        applyConsent(status.consents)
    }
},{ error ->
    // Handle non-localized error
})
try {
  final status = await Usercentrics.status;

  if (status.shouldCollectConsent) {
    //Collect Consent
  } else {
    applyConsent(status.consents);
  }
} catch (error) {
  // Handle non-localized error
}
import { Usercentrics } from '@usercentrics/react-native-sdk';

try {
  const status = await Usercentrics.status();

  if (status.shouldCollectConsent) {
    //Collect Consent
  } else {
    applyConsent(status.consents);
  }
} catch (error) {
  // Handle non-localized error
}

Get Consent

You may also call UsercentricsCore.shared.getConsents() to get the consent directly, but make sure to do so after the isReady callback has been triggered.

Depending on the frameworks included in your app, you will have different ways to apply consent. As a principle, do not initialize any SDK that a user has not consented.

func applyConsent(with consents: [UsercentricsServiceConsent]) {
    for service in consents {

        switch service.templateId {
        case "uNl9XGnZC": // Firebase Template ID

            // Initialize framework if consent was provided. e.g. Firebase Init
            if service.status { FirebaseApp.configure() }

            // and/or provide consent directly to the framework, if an API is available. e.g. Firebase Analytics
            Analytics.setAnalyticsCollectionEnabled(service.status)

        case "x-XXXxXx": // Other Service Template ID
            //Initialize or pass consent to framework with service.status
        default:
            // Log a warning if a service was not caught or do nothing
        }
    }
}
fun applyConsent(consents: List<UsercentricsServiceConsent>?) {
    consents?.forEach { service ->
        when (service.templateId) {
            // Firebase Template ID
            "uNl9XGnZC" -> {
                // Initialize framework if consent was provided. e.g. Firebase Init
                if (service.status) {
                    initializeFirebase()
                }
                // and/or provide consent directly to the framework, if an API is available. e.g. Firebase Analytics
                FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(service.status)
            }
            // Other Service Template ID
            "x-XXXxXx" -> {
                // Initialize or pass consent to framework with service.status
            }
            else -> {
                // Log a warning if a service was not caught or do nothing
            }
        }
    }
}
void applyConsent(List<UsercentricsServiceConsent>? consents) {
  consents?.forEach((service) {
    switch (service.templateId) {
      // Firebase Template ID
      case "uNl9XGnZC":
        // Initialize framework if consent was provided. e.g. Firebase Init
        if (service.status) {
          initializeFirebase();
        }
        // and/or provide consent directly to the framework, if an API is available. e.g. Firebase Analytics
        FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(service.status);
        break;
      // Other Service Template ID
      case "x-XXXxXx":
        // Initialize or pass consent to framework with service.status
        break;
      default:
        // Log a warning if a service was not caught or do nothing
    }
  });
}
import { UsercentricsServiceConsent } from '@usercentrics/react-native-sdk';

const applyConsents = (consents: [UsercentricsServiceConsent]) => {
    consents.forEach(service => {
        switch (service.templateId) {

            // Firebase Template ID
            case "uNl9XGnZC":
                // Initialize framework if consent was provided. e.g. Firebase Init
                if (service.status) {
                    // initializeFirebase();
                }
                break;

            // Other Service Template ID
            case "x-XXXxXx":
                // Initialize or pass consent to framework with service.status
                break;

            default:
                // Log a warning if a service was not caught or do nothing
        }
    });
}