Skip to main content

How to use it


How to use appConsent object​

Here is a list of the most commonly used methods

appConsent.consentGiven()

Return true if consent is given, false otherwise.

warning

Please note that we are only talking about whether the user has confirmed a choice and not whether he has accepted or refused consent.

Listener​

When the user has completed the consent process and given their consent, this "callback" informs them of this.

info

It is recommended to define it before trying to display the CMP and to remove it once consent has been given or the cmp has not been displayed.

appConsent.setOnPresentNoticeListener(object : OnPresentNoticeListener { 
override fun presentConsentGiven() {
// ...
}

override fun presentConsentError(error: Throwable?) {
// ...
}
})
Remove Listener​
appConsent.setOnPresentNoticeListener(null)

Try to Display CMP notice​

There are 2 display modes:

  1. The first runs only if user consent is required.
  2. The second, which should be used to allow your users to consult/modify their consent (often used from your settings screen to display your user's privacy policy)
note

By default this method tries to display the CMP. It tries because, depending on the region of your users (if no settings are made via ACConfiguration to force the display) then it will follow its controls and display the CMP only if necessary.

It will also be displayed if the user consent has not yet been given or if it needs to be renewed.

// @return true if the notice display, false otherwise
appConsent.tryToDisplayNotice(false) // display CMP notice only if needed
appConsent.tryToDisplayNotice(true) // force to display CMP notice

It returns true if the CMP is displayed, false otherwise

GCM Status​

info

This method shows the current status of GCMv2 (Google Consent Mode V2).

Before calling up this method, it's best to make sure that the user has already given his consent and that it's up to date, and that the CMP doesn't need to be redisplayed.

Otherwise :

  • either the saved value of the old consent will be returned
  • or the default values of your FirebaseAnalytics AndroidManifest configuration will be returned
Set the default consent state from google documentation
appConsent.getGCMConsentStatus()

Return GCMStatus

Data model representing the state of GCMv2 (Google Consent Mode v2)

This will allow you to define consent from your Firebase Analytics instance.

isAnalyticsStorageGranted, indicates whether the user has given consent for FirebaseAnalytics.ConsentType#ANALYTICS_STORAGE

isAdStorageGranted, indicates whether the user has given consent for FirebaseAnalytics.ConsentType#AD_STORAGE

isAdUserDataGranted, indicates whether the user has given consent for FirebaseAnalytics.ConsentType#AD_USER_DATA

isAdPersonalizationGranted, indicates whether the user has given consent for FirebaseAnalytics.ConsentType#AD_PERSONALIZATION

FirebaseAnalytics.ConsentType

Check for update​

This method allows you to check from our servers whether your Notice has been updated since it was last displayed on your user's device.

info

The method will return true if you have modified the Source and/or Notice from your dashboard and, if and only if, you have configured your Notice to update for all your users.

Check for update - configuration
warning

This method can only be used once every 30 minutes. This allows you to force a first network call to make sure your users are up to date. The next calls to this method will use the cache of the previous response or attempt a network call if the previous one was in error.

appConsent.checkForUpdate({ isNeedToPresentTheCmp: Boolean ->
// Your Notice has been updated, you must represent the CMP to your users
if (true == isNeedToPresentTheCmp) {
/*
Deletes old user consent locally.
This step is not mandatory, but it avoids the need to make another network call
to check whether the Notice has been updated,
as no consent will be present on the user's device.
*/
appConsent.clearConsent()
appConsent.tryToDisplayNotice(false)
} else {
/*
The Notice is the same as when it was last checked
(you have made no changes since the board or
it has not been updated internally by us, e.g. by updating a vendor)
*/
}
}) { _: Throwable? ->
/*
An error has occurred
*/
}

Using AppConsent's more specific methods​

Here's a list of methods that could be useful if you want to go further in tracking user consent.

Consentable allowed​

appConsent.consentableAllowed(1,0)

Return true if consentable with id = 1 and consentableType = 0 is allowed, false otherwise. The id to pass is the iabId of your purpose and the consentableType is the type, e.g: purpose = 0 .

Stack Allowed​

appConsent.stackAllowed(1)

Return true if stack with id = 1 is allowed, false otherwise.

Vendor allowed​

appConsent.vendorAllowed(1)

Return true if vendor with id = 1 is allowed, false otherwise.

All Consentables Allowed​

appConsent.isAllConsentablesAllowed()

Returns true if all consentables have been allowed false if at least one consentable is not allowed and null if no choice has yet been made (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

All Consentables Disallowed​

appConsent.isAllConsentablesDisallowed()

Returns true if all consentables have been disallowed false if at least one consentable is not disallowed and null if no choice has yet been made (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

All Stacks Allowed​

appConsent.isAllStacksAllowed()

Returns true if all stacks have been accepted false if at least one stack is not accepted and null if no choice has yet been made or not present into your notice (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

All Stacks Disallowed​

appConsent.isAllStacksDisallowed()

Returns true if all stacks have been disallowed false if at least one stack is not disallowed and null if no choice has yet been made or not present into your notice (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

All Vendors Allowed​

appConsent.isAllVendorsAllowed()

Returns true if all vendors have been allowed false if at least one vendor is not allowed and null if no choice has yet been made (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

All Vendors Disallowed​

appConsent.isAllVendorsDisallowed()

Returns true if all vendors have been disallowed false if at least one vendor is not disallowed and null if no choice has yet been made (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

User Accept All​

appConsent.isUserAcceptAll()

Returns true if all consent items, stacks and vendors are allowed. false if at least one of them is not allowed and null if no data is present yet (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

User Deny All​

appConsent.isUserDenyAll()

Returns true if all consent items, stacks and vendors are disallowed. false if at least one of them is not disallowed and null if no data is present yet (notice not yet downloaded, choice not yet made, application cache deleted, etc.).

Set consentable status​

appConsent.setConsentableConsents(
mapOf(1 to ConsentStatus.ALLOWED, 2 to ConsentStatus.DISALLOWED),
object : AppConsentSetConsentableConsentsCallback {
override fun onSuccess() {
// ...
}

override fun onError(t: Throwable) {
// ...
}
}
)

Set consentables status, save it and send it to server.

Clear consents​

Locally removes user consent, but not on the server (this will allow a new display of the CMP on the next call to tryToDisplayNotice(false) for example)

appConsent.clearConsent()

Set external ids​

val ids = mapOf<String, String>("customPersonalId" to "abze23", "otherData" to "{\"name\": \"test\"}")
appConsent.setExternalIds(ids)

Allows to define additional Ids that will be taken into account when validating user consent.

Get external ids​

Retrieves your previously registered external ids

val ids: Map<String, String> = appConsent.getExternalIds()

(Bonus) Retrieve your consents​

Your consents are saved in SharedPreferences of your application. To know more about keys used to save your consents, please refer to the IAB documentation.

We also provide an additional key for Google Additionnal Consent IABTCF_AddtlConsent returning a String.