Add a data attribute to list item element in menu

try this code in your functions file.

function add_class_to_nav_items($nav_items, $args) {
  if ( $args['theme_location'] == 'MY_NAV_THEME_LOCATION' ) { // IMPORTANT: replace MY_NAV_THEME_LOCATION with the location of your menu
    foreach ($nav_items as &$nav_item) {
      $nav_item->classes[] = 'custon-class-name';
    }
  }

  return $nav_items;

}

add_filter( 'wp_nav_menu_objects', 'add_class_to_nav_items', 11 );