Fullstory Stable Selectors
π± Platform-Specific Implementation: This document covers core concepts. For implementation details, see:
- Web (JavaScript/TypeScript): SKILL-WEB.md β React, Vue, Angular, Svelte, Next.js, and more
- Mobile: SKILL-MOBILE.md β iOS, Android, Flutter, React Native
Overview
Modern applicationsβboth web and mobileβoften have dynamic, unpredictable element identifiers that change across builds, deployments, or even at runtime. This creates challenges for:
- Fullstory: Reliable search, defined elements, heatmaps
- Automated Testing: Stable E2E test selectors
- Computer User Agents (CUA): AI agents navigating your interface
- Accessibility Tools: Programmatic element identification
The Solution: Add stable, semantic identifiers that describe what the element is, not how it's rendered.
This skill follows the conventions established in the Fullstory Data Attributes Guide, which recommends five core attributes: data-component, data-id, data-section, data-position, and data-state.
The Universal Problem
Web: Dynamic CSS Classes
<!-- What your code looks like -->
<button className={styles.primaryButton}>Add to Cart</button>
<!-- What renders in the browser -->
<button class="Button_primaryButton__x7Ks2">Add to Cart</button>
β
This hash changes every build!
Mobile: Dynamic View IDs
iOS View Hierarchy:
UIButton (0x7f8b4c0123a0) β Memory address changes every launch
βββ "Add to Cart"
Android View Tree:
Button (id: view-12345) β Auto-generated, unstable
βββ "Add to Cart"
React Native Bridge:
ReactButton (nativeID: rn_7) β Bridge-generated, changes on re-render
Impact Across Platforms
| Tool | Web Problem | Mobile Problem | |------|-------------|----------------| | Fullstory | CSS selectors break | View tree queries unreliable | | E2E Testing | Cypress/Playwright tests brittle | Detox/Espresso tests break | | AI Agents (CUA) | Cannot find elements | Cannot navigate reliably | | Automation | Scripts fail on deploy | Scripts fail on app update |
Why This Matters for AI Agents (CUA)
Computer User AgentsβAI systems that interact with digital interfacesβrely on stable, semantic identifiers to understand and navigate your application.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HOW CUAs "SEE" YOUR INTERFACE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β β BRITTLE (AI struggles): β
β β
β Web: <button class="sc-3d8f2a btn_primary__xK7n2"> β
β iOS: UIButton at memory 0x7f8b4c0123a0 β
β Android: view-12345 β
β β
β β
SEMANTIC (AI understands): β
β β
β Web: data-component="button" data-id="add-to-cart" β
β iOS: accessibilityIdentifier = "button.add-to-cart" β
β Android: testTag = "button.add-to-cart" β
β β
β The AI can now reliably: β
β β’ Find "the add-to-cart button" β
β β’ Understand the component type (button) and specific instance β
β β’ Maintain stable automation across deployments β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Stable selectors provide CUAs with:
- β Consistent element identification across builds
- β Semantic understanding of element purpose
- β Hierarchical context (section β component β instance)
- β State awareness for interaction planning
The Universal Solution
Add stable identifiers that survive build changes and runtime variations:
| Platform | Stable Identifier Mechanism |
|----------|----------------------------|
| Web | data-component, data-id, data-section, data-position, data-state attributes |
| iOS | accessibilityIdentifier property |
| Android (Kotlin) | contentDescription or resource ID |
| Android (Compose) | testTag modifier, semantics |
| React Native | testID prop |
| Flutter | Key, Semantics widget |
The naming conventions are the same across all platforms β only the implementation mechanism differs. For mobile apps, these attributes can also be set programmatically with FS.setAttribute calls.
Core Concepts
The Attribute Set
Based on the Fullstory Data Attributes Guide, five core attributes form the stable selector vocabulary:
| Attribute | Purpose | Example Values |
|-----------|---------|----------------|
| data-component | Identifies the type of component β a card, button, accordion, carousel, link, row, etc. Should be paired with data-id to identify the specific instance. | card, button, accordion, carousel, link, row, notification-bar |
| data-id | Identifies the specific instance of a component. Should be unique within a given data-section or nested data-component. | wireless-headphones, add-to-cart, Get Demo, shipping-method |
| data-section | Identifies a major section of the page β header, footer, sidebar, hero. If a section is really just a specific instance of a reusable component, use data-component + data-id instead. | header, footer, navigation, additional-resources, hero |
| data-position | Identifies the position of a repeated element within a list. Only needed for repeating elements where position might be useful for analytics. | 1, 2, 3 |
| data-state | Identifies the current state a component is in. Can also be used for counters or values. | checked, unchecked, expanded, collapsed, loading, active |
Note: There is nothing magical about these exact attribute names. Some companies add
analyticsas part of the attribute (e.g.,data-analytics-id) to make it clearer these are for analytics usage. You can choose different names if that works for your team. It is the concept of the attributes that is important, not their final names.
Semantic Hierarchy
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SEMANTIC HIERARCHY (applies to all platforms) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Section: "checkout" β Page area β
β β β
β βββ Component: "form" / ID: "shipping" β Component + ID β
β β βββ ID: "address-input" β Interactive element β
β β βββ ID: "city-input" β
β β β
β βββ Component: "form" / ID: "payment" β
β β βββ ID: "card-input" β
β β β
β βββ Component: "button" / ID: "place-order" β
β State: "enabled|disabled|loading" β Current state β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Platform Implementation Quick Reference
| Concept | Web | iOS | Android | React Native | Flutter |
|---------|-----|-----|---------|--------------|---------|
| Component type | data-component="card" | accessibilityIdentifier = "card" | testTag("card") | testID="card" | Key("card") |
| Instance ID | data-id="wireless-headphones" | .wireless-headphones suffix | .wireless-headphones suffix | .wireless-headphones suffix | .wireless-headphones suffix |
| Combined | data-component="card" + data-id="wireless-headphones" | "card.wireless-headphones" | "card.wireless-headphones" | "card.wireless-headphones" | Key("card.wireless-headphones") |
| Section | data-section="header" | (use as prefix) | (use as prefix) | (use as prefix) | (use as prefix) |
| Position | data-position="1" | (append to ID) | (append to ID) | (append to ID) | (append to ID) |
Two Approaches to Decoration
There are two primary strategies for applying data attributes. Agents should ask users which approach fits their team before proceeding with implementation.
Approach A: Framework Approach (Recommended for Design Systems)
Build data attributes into your shared, reusable components. When every team uses a shared FullstoryButton, that component automatically emits data-component="button" and data-id={i18nKey} β no manual work needed by consuming developers.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRAMEWORK APPROACH β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Shared Component Library β
β ββββββββββββββββββββββββββββββββ β
β β <FullstoryButton β β
β β i18nKey="checkout.submit"> β β
β β Place Order β β
β β </FullstoryButton> β β
β ββββββββββββββββββββββββββββββββ β
β β β
β βΌ Automatically emits: β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β <button β β
β β data-component="button" β β
β β data-id="checkout.submit"> β β
β β Place Order β β
β β </button> β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β β
Benefits: β
β β’ Zero effort for consuming developers β
β β’ Consistent naming across the entire app β
β β’ Scales automatically as the app grows β
β β’ Resilient to refactors β component handles the decoration β
β β’ i18n keys are already stable, human-readable identifiers β
β β
β β οΈ Considerations: β
β β’ Requires investment in a shared component library β
β β’ May not cover custom one-off elements β
β β’ Less granular control for individual elements β
β β
β Best for: Teams with established design systems or component libraries β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Approach B: Individual Element Decoration
Developers manually add data attributes to individual elements in their templates. This approach works with any codebase immediately.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INDIVIDUAL ELEMENT DECORATION β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Developer adds attributes directly: β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β <button β β
β β data-component="button" β β
β β data-id="place-order" β β
β β className={styles.primary}> β β
β β Place Order β β
β β </button> β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β β
Benefits: β
β β’ Works with any codebase immediately β
β β’ No shared component library dependency β
β β’ Full control over what gets decorated β
β β’ PascalCase code names can be used (test automation friendly) β
β β
β β οΈ Considerations: β
β β’ Manual effort per element β
β β’ Risk of naming inconsistency across developers β
β β’ Requires team discipline and code review β
β β’ May be forgotten on new elements β
β β
β Best for: Teams without a shared component library, or teams wanting β
β immediate results β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Agent Directive: When a developer asks for help with data attributes or stable selectors, always ask which approach they prefer before generating code. Present the benefits and considerations of each approach. Many teams use a hybrid β Framework for shared components (buttons, cards, inputs) and Individual for custom one-off elements.
Naming Conventions (Universal)
These naming conventions apply to all platforms.
Formal Naming Grammar
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NAMING GRAMMAR β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β data-component: <type> β
β β
β The TYPE of component. Use lowercase or kebab-case. β
β Examples: β
β β’ card (content card) β
β β’ button (interactive button) β
β β’ accordion (expandable content) β
β β’ carousel (sliding content) β
β β’ link (navigation link) β
β β’ row (table or list row) β
β β’ notification-bar (compound component type) β
β β’ stackable-elements (compound component type) β
β β
β Alternative: PascalCase code component names (ProductCard, β
β CheckoutForm) are valid for teams that prefer developer-centric β
β naming, especially when aligning with test automation selectors. β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β data-id: <instance-identifier> β
β β
β The SPECIFIC instance. Should be unique within its parent β
β data-section or nested data-component. Use descriptive, β
β human-readable names. β
β Examples: β
β β’ wireless-headphones (product name) β
β β’ add-to-cart (button purpose) β
β β’ Get Demo (CTA label) β
β β’ shipping-method (form element purpose) β
β β’ checkout.submit (i18n key, used in Framework approach) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β data-section: <page-area> β
β β
β A MAJOR section of the page. Use kebab-case. β
β Examples: β
β β’ header β
β β’ footer β
β β’ navigation β
β β’ hero β
β β’ additional-resources β
β β’ behavioral-data β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β data-position: <number> β
β β
β Position in a repeated list. Use integers starting at 1. β
β Examples: 1, 2, 3 β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β data-state: <current-state> β
β β
β The current state of the component. Use kebab-case. β
β Examples: β
β β’ checked / unchecked β
β β’ expanded / collapsed β
β β’ loading / loaded / error β
β β’ active / inactive β
β β’ Can also be a counter value (e.g., "5" for a like count) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Component Type Names (data-component)
Recommended: Use lowercase or kebab-case describing the type of component:
β
RECOMMENDED: Generic component types
β’ card
β’ button
β’ accordion
β’ carousel
β’ link
β’ row
β’ notification-bar
β’ stackable-elements
β
ALSO VALID: PascalCase code component names (for test automation alignment)
β’ ProductCard
β’ CheckoutForm
β’ NavigationHeader
β BAD: Too generic or meaningless
β’ Container
β’ Wrapper
β’ Component
β’ View
β’ div
Instance Identifiers (data-id)
Use descriptive, human-readable names that identify the specific instance:
β
GOOD: Describes what this specific instance IS
β’ wireless-headphones (product name)
β’ add-to-cart (button purpose)
β’ Get Demo (CTA label)
β’ shipping-method (form element purpose)
β’ 6 hurdles of data (content title)
β
GOOD: Qualified names for disambiguation
β’ billing-address-line1
β’ shipping-address-line1
β BAD: Describes appearance or position
β’ blue-button
β’ big-button
β’ button-1
β’ first-item
β’ left-sidebar
Section Names (data-section)
Use kebab-case describing the page area:
β
GOOD: Clear page areas
β’ header
β’ footer
β’ navigation
β’ hero
β’ additional-resources
β’ behavioral-data
β’ site-header
β BAD: Too specific (use data-component + data-id instead)
β’ product-card-section (this is a component, not a section)
β’ button-area (too granular for a section)
What to Annotate
Always Annotate
- β Buttons and tappable elements β Primary interaction points
- β Form inputs β Text fields, selects, checkboxes, toggles
- β Links and navigation items β Navigation paths
- β
Cards and list items β Items in repeating content (use
data-position) - β Modals and dialog triggers β State-changing interactions
- β
Tab and accordion controls β Content switchers (use
data-state) - β
Major page sections β Header, footer, navigation (use
data-section)
Skip Annotation For
- β Pure layout containers β Unless interactive
- β Styling wrappers β Divs/Views for styling only
- β Text-only elements β Unless key analytics content
Best Practices
1. Annotate at Development Time
Add identifiers as you write components, not as an afterthought. This ensures complete coverage.
2. Document Your Conventions
Create a team style guide covering:
- Component type naming patterns (lowercase types vs PascalCase code names)
- Instance identifier patterns
- Section boundaries
- Required annotations
- Platform-specific implementation
3. Combine with Privacy Controls
Stable identifiers and privacy controls work together:
- Annotate sensitive elements for searchability
- Apply privacy masking/exclusion for data protection
- Both serve complementary purposes
4. Use data-section for Page Structure, data-component for Reusable Parts
β
GOOD: Sections for page areas, components for reusable elements
data-section="additional-resources"
βββ data-component="card" data-id="behavioral data"
βββ data-component="card" data-id="6 hurdles of data"
β BAD: Everything is a component
data-component="AdditionalResourcesSection" β Should be a section
βββ data-component="ResourceCard"
5. Use Business Identifiers, Not Positions
For lists and repeating content, use data-id with a business identifier and data-position for the slot:
β
GOOD: Business identifier + position
data-component="card" data-id="wireless-headphones" data-position="1"
β BAD: Position-based identification only
data-id="item-0", data-id="item-1", data-id="item-2"
6. Pair data-component with data-id
A data-component should generally be paired with a data-id that represents the specific instance:
β
GOOD: Component type + specific instance
<div data-component="card" data-id="wireless-headphones">
β BAD: Component without instance identification
<div data-component="card"> β Which card?
Integration with Accessibility
Stable selectors complement accessibility attributes:
| Attribute Type | Purpose | Audience | |----------------|---------|----------| | Stable identifiers | Programmatic targeting | Fullstory, Tests, AI Agents | | Accessibility labels | Human-readable description | Screen readers, AI understanding | | Semantic roles | Element type/behavior | Accessibility, AI categorization |
Best Practice: Use BOTH stable identifiers AND accessibility attributes. They serve complementary purposes.
Troubleshooting
Identifiers Not Working
Common issues across all platforms:
- Identifier not set on the element (verify in inspector/debugger)
- Typos in identifier names
- Build tools stripping identifiers in production
- Conditional rendering removing elements
Too Many Search Results
Problem: Searching for [data-component="button"] returns hundreds of results
Solution: Be more specific with hierarchical identifiers:
- Use
[data-section="checkout"] [data-id="place-order"] - Combine section + component + id for unique targeting
- Use
[data-component="card"][data-id="wireless-headphones"]for specificity
Identifiers Stripped in Production
Check platform-specific build configurations:
- Web: Verify
data-*attributes aren't removed by minifiers - Mobile: Ensure debug-only code isn't stripping identifiers
KEY TAKEAWAYS FOR AGENT
When helping developers implement stable selectors:
Step 0: Ask Which Approach
Before generating any code, ask the developer:
"Would you like to build data attributes into shared components (Framework approach β recommended for teams with design systems) or add them to individual elements directly (Individual Element approach β works with any codebase)?"
Present the benefits and considerations of each approach (see "Two Approaches to Decoration" section above). Many teams use a hybrid β Framework for shared components and Individual for custom elements.
Step 1: Detect Platform and Route
- Detect platform first β Web vs iOS vs Android vs React Native vs Flutter
- Route to implementation file β SKILL-WEB.md or SKILL-MOBILE.md
- Use consistent naming β Same attribute concepts apply to all platforms
Core Principles (All Platforms)
- Name by purpose, not appearance:
data-id="add-to-cart"notdata-id="blue-button" - Use the five attributes:
data-component(type),data-id(instance),data-section(area),data-position(slot),data-state(state) - Pair component with id: A
data-componentshould have adata-id - Use sections for page areas:
data-section="header"notdata-component="header" - Annotate interactive elements: Buttons, inputs, links, cards in lists
- Combine with accessibility: Stable IDs + ARIA/accessibility labels
- Business IDs, not positions:
data-id="wireless-headphones"notdata-id="item-0"
Questions to Ask Developers
- "What platform(s) are you building for?" (Web, iOS, Android, React Native, Flutter)
- "Would you prefer the Framework approach (shared components auto-decorate) or Individual Element decoration?"
- "Do you have a shared component library or design system?"
- "Are your element identifiers stable across builds?"
- "What elements do you need to reliably find in Fullstory?"
- "Are you using E2E testing tools?"
- "Is AI/automation tooling on your roadmap?"
Implementation Checklist (All Platforms)
Phase 1: Core Implementation
β‘ Choose approach (Framework vs Individual vs Hybrid)
β‘ Identify interactive elements that need tracking
β‘ Establish naming convention (component types + instance identifiers)
β‘ Add data-section to major page areas (header, footer, nav)
β‘ Add data-component + data-id to reusable components
β‘ Add data-position to repeated/listed elements
β‘ Add data-state to stateful elements
β‘ Verify identifiers survive production build
β‘ Test in Fullstory search
Phase 2: AI/CUA Readiness
β‘ Ensure data-state is set for stateful elements (expandable, toggleable)
β‘ Ensure accessibility attributes complement stable IDs
β‘ Document naming conventions for team consistency
Phase 3: Enterprise Scale
β‘ If Framework approach: build attributes into shared component library
β‘ Implement type-safe identifier helpers
β‘ Add namespace prefixes for modules/teams (micro-frontends)
β‘ Configure E2E tools to use data-id or data-component selectors
REFERENCE LINKS
Fullstory Documentation
- Data Attributes Guide: Fullstory Data Attributes Guide (internal reference)
- Element Properties: ../core/fullstory-element-properties/SKILL.md
- Privacy Controls: ../core/fullstory-privacy-controls/SKILL.md
- Test Automation: ./fullstory-test-automation/SKILL.md
Platform-Specific Implementation
- Web Implementation: SKILL-WEB.md
- Mobile Implementation: SKILL-MOBILE.md
Accessibility Standards
- WAI-ARIA Authoring Practices: https://www.w3.org/WAI/ARIA/apg/
- iOS Accessibility: https://developer.apple.com/accessibility/
- Android Accessibility: https://developer.android.com/guide/topics/ui/accessibility
This skill provides the universal foundation for stable selectors across all platforms. See SKILL-WEB.md for web implementation and SKILL-MOBILE.md for mobile implementation.