Android
Get AppConsent SDKβ
To add the AppConsent SDK to your Android project, follow the steps below :
In your global gradle.properties
file, add the following and replace ${username}
by the provided username and ${encrypted_password}
by the provided encrypted password. Please contact us, if you don't have your ${username}
and ${encrypted_password}
.
appconsent_artifactory_client_username=${username}
appconsent_artifactory_client_password=${encrypted_password}
In your project build.gradle
file, under allprojects/repositories
add the following:
maven {
url "https://artifactory.datalf.chat/artifactory/app-consent-v2-release"
credentials {
username = "${appconsent_artifactory_client_username}"
password = "${appconsent_artifactory_client_password}"
}
}
In your application build.gradle
file, under android
add the following:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
In your application build.gradle
add the following:
- Classic template development kit (SDK)
- Clear template development kit (SDK)
dependencies {
implementation 'com.sfbx.appconsent:appconsent-ui:${currentUIVersion}'
}
Where currentUIVersion = 1.1.14
dependencies {
implementation 'com.sfbx.appconsent:appconsent-ui-v3:${currentUIV3Version}'
}
Where currentUIV3Version = 2.0.3
caution
AppConsent uses androidX Jetpack, so it's not compatible with android.supportapplications.
How to use AppConsentβ
1. Get your AppKey from AppConsent : https://app.appconsent.ioβ
2. Create AppConsentUIβ
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.sfbx.appconsent.ui.AppConsentUI
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val appConsentUI = AppConsentUI(
context = this,
appKey = "YOUR_APP_KEY",
forceApplyGDPR = true
) {
it.presentNotice(false)
}
}
}
info
If forceApplyGDPR
is true
, it forces CMP to display even if your country isn't subject to GDPR.
Function onReady()
is called when AppConsent finished initializing. It can avoid bugs when you want to present notice just after creating AppConsentUI object.
3. Then use appConsentUI objectβ
- Check if user gave consent
appConsentUI.consentGiven()
Return true
if consent is given, false
otherwise.
- Check if user country is subject to GDPR
appConsentUI.isSubjectToGDPR()
Return true
if user country is subject to GDPR, false
otherwise.
- Check if user Limited Tracking is Enabled
appConsentUI.sLimitedTrackingEnabled()
Return true
if limited ad tracking is enabled, false
otherwise.
User ID
appConsentUI.getUserId()
Return the advertising id used by Appconsent.
info
If isLimitedTrackingEnabled() == false
, it will be Google ADID otherwise a random UUID
- Consent listener
Add Listenerβ
appConsentUI.addNoticeListener(object : AppConsentNoticeListener {
override fun onConsentGiven() {
}
override fun onError(error: AppConsentError) {
}
})
Remove Listenerβ
appConsentUI.removeNoticeListener(listener)
Every time consent is updated, a new event will be fired in AppConsentNoticeListener
.
- Geolocation consent listener
Add Geolocation Listenerβ
appConsentUI.addGeolocationListener(object : AppConsentLocationListener {
override fun onResult(allowed: Boolean) {
}
override fun onError(error: AppConsentError) {
}
})
Remove Geolocation Listenerβ
appConsentUI.removeGeolocationListener(listener)
Every time geolocation consent is updated, a new event will be fired in AppConsentLocationListener
- Display CMP notice
appConsentUI.presentNotice(false) // display CMP notice only if needed
appConsentUI.presentNotice(true) // force to display CMP notice
info
presentNotice(force : Boolean)
is a local method that only check cache. See checkForUpdate()
to fetch a notice update
the force : boolean
here when false
and the consent wasn't set before will show the notice , when true
will show the notice setting's either the consent has been already given or not
- Display Geolocation CMP
appConsentUI.presentGeolocationNotice(false) // display Geolocation CMP only if needed
appConsentUI.presentGeolocationNotice(true) // force to display Geolocation CMP
- Geolocation consent given
appConsentUI.geolocationConsentGiven()
Return true
if geolocation consent is given, false
otherwise.
- Consentable allowed
appConsentUI.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 for ex : purpose = 0 .
- Extra consentable allowed
appConsentUI.extraConsentableAllowed("O56KePok")
Return true
if extra consentable is allowed, false
otherwise. The parameter is the extraId
of your extra purpose available in the back office.
- Stack Allowed
appConsentUI.stackAllowed(1)
Return true
if stack with id = 1 is allowed, false
otherwise. The id
to pass is the iabId
of your stack.
- Vendor allowed
appConsentUI.vendorAllowed(1)
Return true
if vendor with id = 1
is allowed, false
otherwise. The id
to pass is the iabId
of your vendor.
- Extra vendor allowed
appConsentUI.extraVendorAllowed("EHJNieed")
Return true
if extra vendor is allowed, false
otherwise. The parameter is the extraId
of your extra vendor available in the back office.
- All consentables allowed
appConsentUI.allConsentablesAllowed()
Return true
if all are consentables allowed false
otherwise.
- All stacks allowed
appConsentUI.allStacksAllowed()
Return true
if all stacks are allowed false
otherwise.
- All vendors allowed
appConsentUI.allVendorsAllowed()
Return true
if all vendors are allowed false
otherwise.
- User Accept All
appConsentUI.userAcceptAll()
Return true
if all consentables , stacks and vendors are allowed false
otherwise
- Set consentable Status
appConsentUI.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.
- Set extra consentable Status
appConsentUI.setExtraConsentableConsents(
mapOf("EHJNieed" to ConsentStatus.ALLOWED, "O56KePok" to ConsentStatus.DISALLOWED),
object : AppConsentSetConsentableConsentsCallback {
override fun onSuccess() {
}
override fun onError(t: Throwable) {
}
}
)
Set extra consentables status, save it and send it to server. Ids are the extraId of your extra purpose available in the back office.
- Check for update
appConsentUI.checkForUpdate(object : AppConsentUpdateCallback {
override fun onResult(needUpdate: Boolean) {
if (needUpdate) {
appConsentUI.presentNotice(false)
}
}
override fun onError(t: Throwable?) {
}
})
Check if consent must be updated (new gvl version, new consentables...).
In this exemple, introduction page of the CMP will be displayed after a notice modification in back office.
- Clear consents
appConsentUI.clearConsent()
Clear consents on mobile, but not on server.
- GET / SET externalIds
val ids = appConsentUI.externalIds.toMutableMap()
ids["contractId"] = "AZR35G"
appConsentUI.externalIds = ids
GET / SET external ids in cache and send it to server when open notice.
- Save external ids
appConsentUI.saveExternalIds(
success = { },
failed = { }
)
Send external ids in cache to the server.
- Save floating purpose consent
val floatingPurposes = mapOf("floatingId" to true)
appConsentUI.saveFloatingPurposes(
floatingPurposes,
success = { },
failed = { }
)
Set floating purpose consent in cache as a map and send them to the server.
info
Only one floating purpose will be send at this time (1.1.0-beta04
). We match the given ids with the one set in the back office
- Retrieve floating purpose consent
appConsentUI.extraFloatingAllowed("floatingId")
Return true
if floating purpose is allowed, false
otherwise.
- Force save consents
appConsentUI.save(
onResult = {
},
onError = {
}
)
Force SDK to send consents to the server. It can be useful if you update externalIds
and you want to update them on the server.
4. 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.
5. Xchangeβ
In your application build.gradle
add the following
- Classic template development kit (SDK)
- Clear template development kit (SDK)
dependencies {
implementation 'com.sfbx.appconsent:appconsent-ui:${currentUIVersion}'
}
Where currentUIVersion = 1.1.14
dependencies {
implementation 'com.sfbx.appconsent:appconsent-ui-v3:${currentUIV3Version}'
}
Where currentUIV3Version = 2.0.3
- Set xchange user data
appConsentUI.setXchangeUserData(
XChangeUserData.Builder()
.email("test@sfbx.io")
.build()
)
Save user data in cache, and when user give his consent, data are sent to server.
- Add request location listener
appConsentUI.addRequestLocationListener(object : AppConsentRequestLocationListener {
override fun requestLocation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ActivityCompat.requestPermissions(
this@MainActivity,
arrayOf(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION
),
REQUEST_PERMISSION_CODE
)
} else {
ActivityCompat.requestPermissions(
this@MainActivity,
arrayOf(
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
),
REQUEST_PERMISSION_CODE
)
}
}
})
If your app need to track geolocation, you must implement AppConsentRequestLocation
as above and start partners geolocation SDK inside the callback (we check if location permissions and geolocation consents are given) and when creating appConsentUI for future launch .
- Huq
Use Huq SDK.
appConsentUI.startHuq()
appConsentUI.stopHuq()
- Smart-Traffik
Use Smart-Traffik SDK.
appConsentUI.startSmartTraffik() // start Smart-Traffik SDK when user gives his consent
appConsentUI.stopSmartTraffik() // stop Smart-Traffik SDK