Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Emit component updated metrics during table interactions #2901

Merged
merged 4 commits into from
Oct 23, 2024

Conversation

michaeldowseza
Copy link
Member

@michaeldowseza michaeldowseza commented Oct 18, 2024

Description

  • Emit component update metrics for table interactions.
  • Refactor useComponentAnalytics hook and migrate code into useTableInteraction: We do not have plans to extend this to additional components yet and it was cleaner to combine these hooks as they have the same purpose.

How has this been tested?

  • Added additional unit tests
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.23%. Comparing base (6ac2909) to head (fe18d37).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2901      +/-   ##
==========================================
- Coverage   96.23%   96.23%   -0.01%     
==========================================
  Files         767      767              
  Lines       21699    21703       +4     
  Branches     7363     7428      +65     
==========================================
+ Hits        20882    20885       +3     
- Misses        764      765       +1     
  Partials       53       53              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@michaeldowseza michaeldowseza marked this pull request as ready for review October 18, 2024 16:01
@michaeldowseza michaeldowseza requested a review from a team as a code owner October 18, 2024 16:01
@michaeldowseza michaeldowseza requested review from orangevolon and removed request for a team October 18, 2024 16:02
import { useEffectOnUpdate } from '../use-effect-on-update';
import { useRandomId } from '../use-unique-id';

function useTaskInteractionAttribute(elementRef: React.RefObject<HTMLElement>, value: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this code in another place:

function usePerformanceMarkAttribute(elementRef: React.RefObject<HTMLElement>, value: string) {
const attributeName = 'data-analytics-performance-mark';
const attributeValueRef = useRef<string | undefined>();
useEffect(() => {
// With this effect, we apply the attribute only on the client, to avoid hydration errors.
attributeValueRef.current = value;
elementRef.current?.setAttribute(attributeName, value);
}, [value, elementRef]);
return {
[attributeName]: attributeValueRef.current,
};
}

Can we merge these two into one, to reduce the risk of diverging implementations (e.g. when we make bug fixes)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Mine was based off of this one. Will consolidate into a useDOMAttribute hook.

@@ -182,12 +182,25 @@ export interface IPerformanceMetrics {
taskCompletionData: TaskCompletionDataMethod;
}

type JSONValue = string | number | boolean | null | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the value of an object's property is undefined, the property will not appear in the JSONified string at all - is that okay for our metrics? Should we enforce values being null instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had mostly tried to align with this type interface. I think not appearing in the string is fine.

metadata.current = { itemCount, getComponentIdentifier, getComponentConfiguration, interactionMetadata };

useEffect(() => {
ComponentMetrics.componentMounted({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With every taskInteractionId change, do we wanna track mount?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const taskInteractionId = useRandomId();

useRandomId() returns a ref value so this does not change on render and the effect will only run once on mount. In theory I could leave the dependency out but then I would need to have an eslint-disable comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as long as it's a ref it should be fine, but I guess that also relies on the assumption that useRandomId is always going to return a ref.

@michaeldowseza michaeldowseza force-pushed the analytics/table-updated branch 2 times, most recently from 4895306 to 30c0f00 Compare October 22, 2024 14:12
orangevolon
orangevolon previously approved these changes Oct 22, 2024
orangevolon
orangevolon previously approved these changes Oct 23, 2024
@michaeldowseza michaeldowseza added this pull request to the merge queue Oct 23, 2024
Merged via the queue into main with commit b1a1a4b Oct 23, 2024
38 checks passed
@michaeldowseza michaeldowseza deleted the analytics/table-updated branch October 23, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants