microsoft / clarity

A behavioral analytics library that uses dom mutations and user interactions to generate aggregated insights.
https://clarity.microsoft.com
MIT License
2.09k stars 208 forks source link

Enable the customization of the name of DOM elements when clicked #501

Open jonathanghm opened 10 months ago

jonathanghm commented 10 months ago

Objective Enable the customization of the name of DOM elements when clicked.

Motivation 1. Independence from the content of the DOM element: By using a custom attribute, the logic for event tracking is separated from the content of the element. This provides flexibility to change the content without affecting the tracking logic.

2. Avoids internationalization issues: In multilingual applications, the text of the element may change depending on the language, which could complicate tracking. A custom attribute can provide a more stable identifier.

2. Privacy enhancement: There may be scenarios where an element contains sensitive information, like email, name or passwords. This enhances the masking option already provided by clarity and additionally gives the analytics more context about the action.

How does it work? By using the custom attribute "data-clarity-event" on the clickable DOM element, this will be considered as the default event name. If the custom attribute "data-clarity-event" does not exist on the element, the current logic will be followed to obtain the name (textContent, value, or alt).

jonathanghm commented 10 months ago

@microsoft-github-policy-service agree