Send consent for DMA compliance
For a general introduction to DMA consent data, see here.
The SDK offers two alternative methods for gathering consent data:
-
Through a Consent Management Platform (CMP): If the app uses a CMP that complies with the Transparency and Consent Framework (TCF) v2.2 protocol, the SDK can automatically retrieve the consent details.
OR
-
Through a dedicated SDK API: Developers can pass Google's required consent data directly to the SDK using a specific API designed for this purpose.
Note
AppsFlyer recommends using only one of the above methods per specific event sent. If both methods are sent for the same event, AppsFlyer will prioritize the manual consent data sent via the dedicated SDK API.
Use CMP to collect consent data
A CMP compatible with TCF v2.2 collects DMA consent data and stores it in SharedPreferences
. To enable the SDK to access this data and include it with every event, follow these steps:
- Initialize the SDK from the
Application
class. - Immediately after initializing the SDK, call
enableTCFDataCollection(true)
to instruct the SDK to collect the TCF data from the device. - In the
Activity
class, use the CMP to decide if you need the consent dialog in the current session. - If needed, show the consent dialog, using the CMP, to capture the user consent decision. Otherwise, go to step 6.
- Get confirmation from the CMP that the user has made their consent decision, and the data is available in
SharedPreferences
. - Call
start()
.
Application class
public class AppsflyerBasicApp extends Application {
@Override
public void onCreate() {
super.onCreate();
String afDevKey = AppsFlyerConstants.afDevKey;
AppsFlyerLib appsflyer = AppsFlyerLib.getInstance();
// In this example the AppsFlyerConversionListener is not initialized.
// It is optional
appsflyer.init(afDevKey, null, this);
appsflyer.enableTCFDataCollection(true);
}
}
Activity class
public class MainActivity extends AppCompatActivity {
private boolean consentRequired = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (consentRequired)
initConsentCollection();
else
AppsFlyerLib.getInstance().start(this);
}
private void initConsentCollection() {
// Implement here the you CMP flow
// When the flow is completed and consent was collected
// call onConsentCollectionFinished()
}
private void onConsentCollectionFinished() {
AppsFlyerLib.getInstance().start(this);
}
Manually collect consent data
If your app does not use a CMP compatible with TCF v2.2, utilize the SDK API detailed below to provide the consent data directly to the SDK.
- Initialize the SDK from the Application class.
- In the
Activity
class, determine whether the GDPR applies or not to the user.
When GDPR applies to the user
If GDPR applies to the user, perform the following:
- Given that GDPR is applicable to the user, determine whether the consent data is already stored for this session.
- If there is no consent data stored, show the consent dialog to capture the user consent decision.
- If there is consent data stored continue to the next step.
- To transfer the consent data to the SDK create an object called
AppsFlyerConsent
using theforGDPRUser()
method with the following parameters:hasConsentForDataUsage
- Indicates whether the user has consented to use their data for advertising purposes.hasConsentForAdsPersonalization
- Indicates whether the user has consented to use their data for personalized advertising purposes.
- Call
setConsentData()
with theAppsFlyerConsent
object. - Call
start()
.
// If the user is subject to GDPR - collect the consent data
// or retrieve it from the storage
...
// Set the consent data to the SDK:
boolean hasConsentForDataUsage = << true / false >> ; // Based on actual user consent
boolean hasConsentForAdsPersonalization = << true / false >>; // Based on actual user consent
AppsFlyerConsent gdprUserConsent = AppsFlyerConsent.forGDPRUser(hasConsentForDataUsage, hasConsentForAdsPersonalization);
AppsFlyerLib.getInstance().setConsentData(gdprUserConsent);
// Start the AppsFlyer SDK
AppsFlyerLib.getInstance().start(this);
// If the user is subject to GDPR - collect the consent data
// or retrieve it from the storage
...
// Set the consent data to the SDK based on actual user consent:
val gdprUserConsent = AppsFlyerConsent.forGDPRUser(hasConsentForDataUsage = << true / false >>, // Based on actual user consent
hasConsentForAdsPersonalization = << true / false >>) //
AppsFlyerLib.getInstance().setConsentData(gdprUserConsent)
// Start the AppsFlyer SDK
AppsFlyerLib.getInstance().start(this);
When GDPR does not apply to the user
If GDPR doesn’t apply to the user perform the following:
- Create an
AppsFlyerConsent
object using theforNonGDPRUser()
method. This method doesn’t accept any parameters. - Call
setConsentData()
with theAppsFlyerConsent
object - Call
start()
.
// If the user is not subject to GDPR:
AppsFlyerConsent nonGdprUser = AppsFlyerConsent.forNonGDPRUser();
AppsFlyerLib.getInstance().setConsentData(nonGdprUser);
// Start the AppsFlyer SDK
AppsFlyerLib.getInstance().start(this);
// If the user is not subject to GDPR:
val nonGdprUser = AppsFlyerConsent.forNonGDPRUser()
AppsFlyerLib.getInstance().setConsentData(nonGdprUser)
// Start the AppsFlyer SDK
AppsFlyerLib.getInstance().start(this);
Verify consent data is sent
To test whether your SDK sends DMA consent data with each event, perform the following steps:
- Enable the SDK debug mode.
- Search for
consent_data
in the log of the outgoing request.
Logs snippet example for CMP flow
LAUNCH-10: preparing data: { ... {"consent_data":{"tcf":{"policy_version":4,"cmp_sdk_id":300,"cmp_sdk_version":2,"gdpr_applies":1,"tcstring":"XXXXXXXX"}}} ... }
Logs snippet example for manual flow
LAUNCH-10: preparing data: { ... {"consent_data":{"manual":{"gdpr_applies":true,"ad_user_data_enabled":true,"ad_personalization_enabled":true}}} ... }
Updated 4 months ago