Try it free

Configure privacy and data collection

  • Latest Dynatrace
  • Explanation
  • 1-min read

Dynatrace provides privacy settings that allow you to control the amount of data collected from your users. These settings help ensure compliance with data protection regulations such as GDPR while still providing valuable insights into application performance. OneAgent supports privacy-first data collection, giving developers control over data collection levels, crash reporting, and user privacy options at runtime. Additionally, OneAgent allows you to redact sensitive data from reported events.

Data collection levels

OneAgent supports three levels of data collection, defined by the DataCollectionLevel.

LevelDescription

OFF

No data is collected.

PERFORMANCE

Collects performance-related data, such as app crashes and ANRs.

USER_BEHAVIOR

Collects both performance data and user behavior data.

At the Performance level, performance data is collected by default, including user interactions, web requests, errors, and screen flows. However, crashes and ANRs are only reported if crash reporting is explicitly enabled via the crash reporting opt-in flag; if disabled, no crash or ANR data is collected despite the level description. See Enable or disable crash reporting.

Set the data collection level

Configure the data collection level using the applyUserPrivacyOptions API.

import com.dynatrace.android.agent.Dynatrace
import com.dynatrace.android.agent.conf.UserPrivacyOptions
import com.dynatrace.android.agent.conf.DataCollectionLevel
val privacyOptions = Dynatrace.getUserPrivacyOptions()
val updatedOptions = privacyOptions.newBuilder()
.withDataCollectionLevel(DataCollectionLevel.PERFORMANCE)
.build()
Dynatrace.applyUserPrivacyOptions(updatedOptions)
import com.dynatrace.android.agent.Dynatrace;
import com.dynatrace.android.agent.conf.UserPrivacyOptions;
import com.dynatrace.android.agent.conf.DataCollectionLevel;
UserPrivacyOptions privacyOptions = Dynatrace.getUserPrivacyOptions();
UserPrivacyOptions updatedOptions = privacyOptions.newBuilder()
.withDataCollectionLevel(DataCollectionLevel.PERFORMANCE)
.build();
Dynatrace.applyUserPrivacyOptions(updatedOptions);

User opt-in mode

The user opt-in feature allows developers to comply with privacy regulations by explicitly obtaining user consent before collecting data or enabling crash reporting. This feature ensures that users have control over their data and can make informed decisions about their privacy.

How user opt-in works

When the user opt-in feature is enabled, OneAgent does not collect any data or enable crash reporting until the user explicitly provides consent. Developers can use the applyUserPrivacyOptions API to update the privacy settings based on the user's preferences.

Default behavior

When user opt-in mode is enabled, before a user explicitly provides consent, OneAgent uses the following default settings:

  • Data Collection Level: OFF (no data collected).
  • Crash Reporting: false (disabled).

By using user opt-in mode, developers can ensure compliance with privacy regulations and provide users with greater control over their data.

Enable user opt-in mode

User opt-in mode is optional. Without it, OneAgent collects data and reports crashes by default, without requiring user consent. When enabled, your application must provide a consent UI to the end user; until the user explicitly grants consent, no data is collected and crash reporting remains off. To enable opt-in mode, update your Gradle configuration:

Gradle plugin configuration:

dynatrace {
configurations {
defaultConfig {
userOptIn true
}
}
}
configure<com.dynatrace.tools.android.dsl.DynatraceExtension> {
configurations {
create("defaultConfig") {
userOptIn(true)
}
}
}

Manual startup configuration:

DynatraceConfigurationBuilder("<YourApplicationID>", "<ProvidedBeaconURL>")
.withUserOptIn(true)
.buildConfiguration()
new DynatraceConfigurationBuilder("<YourApplicationID>", "<ProvidedBeaconURL>")
.withUserOptIn(true)
.buildConfiguration();

Implement a consent dialog

Dynatrace doesn't provide a consent dialog UI. You must implement your own consent banner or dialog within your application (as described in Configure data privacy settings for mobile applications. The dialog should:

  1. Explain what data will be collected.
  2. Allow users to choose their preferred data collection level.
  3. Allow users to enable or disable crash reporting.
  4. Provide a way for users to change their preferences later.

Privacy API

The applyUserPrivacyOptions API allows you to dynamically update privacy settings at runtime. This is useful for implementing user consent dialogs or privacy settings screens.

Enable or disable crash reporting

When opt-in mode is disabled, crash reporting is enabled by default. When opt-in mode is enabled, crash reporting is off until the user explicitly grants consent. When enabled, OneAgent collects crash data to help developers diagnose and fix issues in their applications.

Use the applyUserPrivacyOptions API to enable or disable crash reporting:

import com.dynatrace.android.agent.Dynatrace
import com.dynatrace.android.agent.conf.UserPrivacyOptions
val privacyOptions = Dynatrace.getUserPrivacyOptions()
val updatedOptions = privacyOptions.newBuilder()
.withCrashReportingOptedIn(true) // Enable crash reporting
.build()
Dynatrace.applyUserPrivacyOptions(updatedOptions)
import com.dynatrace.android.agent.Dynatrace;
import com.dynatrace.android.agent.conf.UserPrivacyOptions;
UserPrivacyOptions privacyOptions = Dynatrace.getUserPrivacyOptions();
UserPrivacyOptions updatedOptions = privacyOptions.newBuilder()
.withCrashReportingOptedIn(true) // Enable crash reporting
.build();
Dynatrace.applyUserPrivacyOptions(updatedOptions);

Apply privacy options

import com.dynatrace.android.agent.Dynatrace
import com.dynatrace.android.agent.conf.UserPrivacyOptions
import com.dynatrace.android.agent.conf.DataCollectionLevel
val privacyOptions = Dynatrace.getUserPrivacyOptions()
val updatedOptions = privacyOptions.newBuilder()
.withDataCollectionLevel(DataCollectionLevel.USER_BEHAVIOR)
.withCrashReportingOptedIn(false)
.build()
Dynatrace.applyUserPrivacyOptions(updatedOptions)
import com.dynatrace.android.agent.Dynatrace;
import com.dynatrace.android.agent.conf.UserPrivacyOptions;
import com.dynatrace.android.agent.conf.DataCollectionLevel;
UserPrivacyOptions privacyOptions = Dynatrace.getUserPrivacyOptions();
UserPrivacyOptions updatedOptions = privacyOptions.newBuilder()
.withDataCollectionLevel(DataCollectionLevel.USER_BEHAVIOR)
.withCrashReportingOptedIn(false)
.build();
Dynatrace.applyUserPrivacyOptions(updatedOptions);

Data safety section on Google Play

When Dynatrace is used in an Android app distributed via Google Play, the following privacy information has to be added within Google Play.

Related tags
Digital Experience