How to use it
How to use appConsent objectβ
Here is a list of the most commonly used methods
Check if user gave consentβ
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β
Define the listener related to user consentβ
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:
- The first runs only if user consent is required.
- 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
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
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.
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.