objectiv-analytics
objectiv-analytics copied to clipboard
React SDK: easier tracking of `checked` based inputs
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
checkedtracking to our standard '0' and '1' - Re-enabled triggering events via
onChangeevent for checkboxes and radio (it was a testing fluke) - Automatically track radio
nameas 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
nameattribute as Location - [x] Add warning message to TrackedInput inviting to use the new TrackedInputCheckbox and TrackedInputRadio
- [ ] Verify feasibility: support
multipleattribute for TrackedSelect or warn if set - [x] Update documentation
- [x] TrackedInputContext
- [x] TrackedInputRadio
- [x] TrackedInputCheckbox
- [ ] TrackedSelect
- [ ] Manual testing and QA