objectiv-analytics icon indicating copy to clipboard operation
objectiv-analytics copied to clipboard

React SDK: easier tracking of `checked` based inputs

Open sdirosa opened this issue 3 years ago • 0 comments

This PR is inspired by and (hopefully) solves https://github.com/objectiv/objectiv-analytics/issues/1131


In this PR I add options to further customize how we track inputs. The main aim is to better support tracking checked based inputs, such as radio and checkbox.

TrackedInputContext

  • new prop: attributeToMonitor, with sensible defaults depending on the input type
  • new prop: attributeToTrack, with sensible defaults depending on the input type
  • Some input validation (mainly to point out conflicting or impossible configurations)
  • Support for defaultChecked
  • Normalization for checked tracking to our standard '0' and '1'
  • Re-enabled triggering events via onChange event for checkboxes and radio (it was a testing fluke)
  • Automatically track radio name as ContentContext in LocationStack of InputChangeEvents
  • Extended type definition to support HTMLSelectElement + test case

New Components

Leveraging the new capabilities of TrackedInputContext I've added:

  • TrackedInputCheckbox
  • TrackedSelect

Todo

  • [x] Support onChange events for checkboxes and radios. This seems to be an issue either with JSDOM or testing-library, as the behavior when testing manually differs from what happens in unit tests.
  • [x] Track radio group name attribute as Location
  • [x] Add warning message to TrackedInput inviting to use the new TrackedInputCheckbox and TrackedInputRadio
  • [ ] Verify feasibility: support multiple attribute for TrackedSelect or warn if set
  • [x] Update documentation
    • [x] TrackedInputContext
    • [x] TrackedInputRadio
    • [x] TrackedInputCheckbox
    • [ ] TrackedSelect
  • [ ] Manual testing and QA

sdirosa avatar Aug 10 '22 08:08 sdirosa