Enable privacy protection in Android Compose apps

When capturing user behavior data, you must take measures to exclude personally identifiable information (PII) such as credit card numbers or home addresses.

Before you begin

We recommend assigning accessibility labels to the UI elements that require privacy protection. Use the contentDescription semantic property for that purpose.

import com.acoustic.connect.android.connectmod.composeui.customcomposable.LoggedText

LoggedText(
    text = "This is some text",
    contentDescription = "private"  // Required for masking
)

You can reuse the same label for several composables.

📘

Important

  • The accessibility labels will be available to your users through screen readers, so make sure they are helpful.
  • Using the same accessibility labels across the iOS and Android versions of an app creates consistency and is considered an industry standard. For more information, see Mobile Accessibility at W3C.

Instructions

  1. Copy the ConnectLayoutConfig.json from our sample app and paste it to the assets directory in your project.
  2. In the masking object, set HasMasking to true.
  3. Add the MaskAccessibilityLabelList parameter and populate it with the accessibility labels of the elements that require privacy protection.
{
  "AutoLayout": {
    "GlobalScreenSettings": {
      "ScreenChange": true,
      "DisplayName": "",
      "CaptureLayoutDelay": 500,
      "ScreenShot": true,
      "NumberOfWebViews": 0,
      "CaptureUserEvents": true,
      "CaptureScreenVisits": true,
      "CaptureLayoutOn": 2,
      "CaptureScreenshotOn": 2,
      "Masking": {
        "HasMasking": true,
        "HasCustomMask": false,
        "Sensitive": {
          "capitalCaseAlphabet": "X",
          "number": "9",
          "smallCaseAlphabet": "x",
          "symbol": "#"
        },
        "MaskIdList": [
        ],
        "MaskValueList": [],
        "MaskAccessibilityLabelList": [
          "sensitive_label",
          "mask_label"
        ]
      }
    },
    "MainActivity": {
      "ScreenChange": false,
      "DisplayName": "MainActivity",
      "CaptureLayoutOn": 0,
      "CaptureScreenshotOn": 0
    },
    "plantDetail/{plantId}": {
      "ScreenChange": true,
      "DisplayName": "plant Detail",
      "Masking": {
        "HasMasking": true,
        "HasCustomMask": true,
        "Sensitive": {
          "capitalCaseAlphabet": "X",
          "number": "9",
          "smallCaseAlphabet": "x",
          "symbol": "#"
        },
        "MaskAccessibilityLabelList": [
          "mask_label"
        ]
      }
    },
    "home": {
      "ScreenChange": true
    },
    "GardenActivity": {
      "ScreenChange": false
    }
  },
  "AppendMapIds": {
    "com.any.package:id/givenIdOnXmlLayout1": {
      "mid": "giveAdditionalId1"
    },
    "com.any.package:id/givenIdOnXmlLayout2": {
      "mid": "giveAdditionalId2"
    }
  }
}
  1. (recommended) Run the file through a JSON validator.

How it works

The masking object in ConnectLayoutConfig.json contains all properties related to PII protection.

PropertyValuesDescription
HasMaskingBoolean. Default value - false.Set the value to true to allow masking.
HasCustomMaskBooleanDefines how protected text is displayed in session replay.
MaskAccessibilityLabelListArray of stringThe accessibility labels of the elements that require privacy protection

You can create a general privacy rule that applies to all screens of your app. In that case, use the AutoLayout.GlobalScreenSettings object. To create a rule for a particular screen, add the AutoLayout.ScreenName object where ScreenName is the name of the screen. Feel free to combine general and screen-specific rules within the same configuration file.

Test the settings (Connect Ultimate)

If your company has an Ultimate subscription for Connect, you can check how your new rule is working.

  1. Run the app and enter something into the fields you have masked.
  2. In your Connect account, navigate to Insights > Sessions > Session search.
  3. Find the session and check how the input is displayed.
Masked input example

Protected text input in session replay