browser-sdk icon indicating copy to clipboard operation
browser-sdk copied to clipboard

💡onFrustration or onRageClick callback

Open sators opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

It would be great if the library had a callback option for a function that could be run when a frustration/rage click is detected so that we could display a helpful popup/chat prompt to the user to try to help/gather more feedback as to what they are trying to do.

Describe the solution you'd like

A configuration option like 'onFrustration' or 'onRageClick'

Describe alternatives you've considered

None

sators avatar Nov 12 '23 20:11 sators

Thank you for your feedback, we'll considering it. In the meantime, you could imlement this via the beforeSend hook, something like this:

      DD_RUM.init({
        ...
        trackUserInteractions: true,
        beforeSend(event) {
          if (
            event.type === 'action' &&
            event.action.type === 'click' &&
            event.action.frustration?.type.includes('rage_click')
          ) {
            // got a rage click
            showFeedbackForm()
          }
        },
      })

Keep in mind that rageclick detection is subjective and the user might not perceive an action as "rage" even if we report it as such. You could fine-tune the condition by using context.events, example:

      DD_RUM.init({
        ...
        trackUserInteractions: true,
        beforeSend(event, context) {
          if (
            event.type === 'action' &&
            event.action.type === 'click' &&
            event.action.frustration?.type.includes('rage_click') &&
            // don't open the feedback form if a click is on the "Next Page" button
            !context.events.some(event => event.target.matches(".next-page"))
          ) {
            // got a rage click
            showFeedbackForm()
          }
        },
      })

BenoitZugmeyer avatar Nov 13 '23 13:11 BenoitZugmeyer