Skip to content

Accessibility Identifiers for Targeting

Contextual 3.0.0+ Launcher and Tip Targeting

From Contextual 3.0.0 onwards, the mobile SDKS support an additional targeting method using the well-known functions of Accessibility Identifiers.

By default Contextual mobile guides tips or launchers with (button launchers, hover launcher, click launcher) rely on elements of the interface of the application for placement, our mobile SDKs built-in algorithms make best efforts to find your targeted elements at run-time, but sometimes, these are dynamically rendered and therefore not reachable. To improve this you can make your target elements more reliable for our mobile SDKs algorithms by using Accessibility Identifiers.

If your application has these identifiers implemented, our SDKs will very easily find the targets (with near 100% success).

What are Accessibility Identifiers?

Accessibility identifiers are attributes or labels associated with user interface elements in software applications, particularly in the context of mobile and desktop applications. These identifiers are primarily used to improve the accessibility of the application for individuals with disabilities, including those who rely on assistive technologies such as screen readers, voice commands, or braille displays. Accessibility identifiers help make it easier for these users to interact with and understand the content and functionality of the application.

How should the Accessibility Identifiers be implemented?

Note

  1. It is advisable to determine during first integration of the Contextual SDK which screen elements should have Accessibility Identifiers added, these are the elements you are very likely to target and may be dynamic. Advise your developers to add these changes below ASAP.
  2. Accessibility Identifiers are case sensitive on both IOS and Android. This should not affect performance or reliability but advise your developers to be consistent.
  3. Most importantly each Accessibility Identifier MUST be unique.

iOS references:

UI Accessibility guidelines

Accessibility identifiers

Note

Accessibility identifiers are case sensitive on both IOS and Android

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
struct ContentView: View {
   var body: some View {
       VStack {
           Button("Tap me") {
               // Button action
           }
           .padding()
           .accessibilityIdentifier("myButtonIdentifier") // Set the accessibility identifier
       }
   }
}
UIKit
let button = UIButton(type: .system)
button.setTitle("Tap me", for: .normal)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
button.accessibilityIdentifier = "myButtonIdentifier"

Android references:

Principles of improving app accessibility

Examples:

1
2
3
4
5
6
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap me"
android:contentDescription="myButtonIdentifier" />
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@Composable
fun MyScreen() {
   Column {
       Button(
           onClick = {
               // Button click action
           },
           modifier = Modifier.contentDescription("myButtonIdentifier")
       ) {
           // Button content
       }
   }
}

Last update: 2024-01-05