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: Refactor event tracking method #11262

Merged
merged 18 commits into from
Oct 7, 2024
Merged

Conversation

NicolasMassart
Copy link
Contributor

@NicolasMassart NicolasMassart commented Sep 17, 2024

Description

  • introduces a tracking event Builder to help dev on creation of complex events
  • removes dependency to Segment SDK JsonMap by implementing our own
  • updates to useMetrics hook
  • deprecates legacy trackEvent function signature
  • updates app/components/UI/NetworkModal/index.tsx file using the builder instead of trackEvent as an example
  • updates unit tests that were checking for hook trackEvent params: the hook is now just a bypass and does no processing so metametrics trackEvent is called with same params.
  • updates code doc

Note

These changes are made in order to preserve existing mechanisms in parallel.
This leads to strange naming like ITrackingEvent as the ideal IMetaMetricsEvent already exists.
This can be dealt with later as it's well documented and following guidelines.

Related issues

fixes #11319

Manual testing steps

NA

Screenshots/Recordings

NA

Before

NA

After

NA

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@NicolasMassart NicolasMassart changed the title Refactor event tracking method chore: Refactor event tracking method Sep 17, 2024
@NicolasMassart NicolasMassart force-pushed the 10784_simplify_metrics_calls branch 3 times, most recently from e4e57fc to 6c90712 Compare September 17, 2024 18:44
@NicolasMassart NicolasMassart force-pushed the 10784_simplify_metrics_calls branch from 6c90712 to 7f37836 Compare September 17, 2024 18:53
@NicolasMassart NicolasMassart mentioned this pull request Sep 19, 2024
24 tasks
@wachunei
Copy link
Member

With @NicolasMassart we had a call and aligned on the API this Event Builder can have, here are some examples of the expected behavior:

// Event Builder interface
const eventBuilder = createEventBuilder(EVENT_NAME)
  .addProperties({ ...})
  .addSensitiveProperties({ ... })
  .addProperties({ ... }) // These can be added multiple times

if (condition) {
  eventBuilder.addProperties({ ... })
  eventBuilder.removeProperties(['prop1', 'prop2'])
  // or inline
  // eventBuilder.addProperties({ ... }).removeProperties(['prop1', 'prop2'])
}

const event = eventBuilder.build();

// Suggested way to track this event
// We pass the built event to the trackEvent function
trackEvent(event);

// or inline
trackEvent(createEventBuilder(EVENT).addProperties({ ... }).build());

// And backwards compatible (for now?? deprecate it in the future).
trackEvent({ name: EVENT, properties: { ... }, sensitiveProperties: { ... } });

// What if I want to modify an already built event?
// We can revert it to a Builder state if we create a new builder from the event
createEventBuilder(event).addProperties({ ... }).build();

// ———

// Another way (initial suggestion) was to have a track method in the event object
// THIS WILL NOT BE SUPPORTED
event.track();

If there's a use case we detect, in the future the builder can be extended to support new features, for example:

eventBuilder.makeSensitive(['prop1', 'prop2']);
eventBuilder.makeNonSensitive(['prop1', 'prop2']);

encapsulate
track function overload
@NicolasMassart NicolasMassart force-pushed the 10784_simplify_metrics_calls branch from 4233171 to 5bb3300 Compare September 30, 2024 14:49
@NicolasMassart NicolasMassart marked this pull request as ready for review October 1, 2024 10:27
@NicolasMassart NicolasMassart requested a review from a team as a code owner October 1, 2024 10:27
@NicolasMassart NicolasMassart added needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 1, 2024
@NicolasMassart NicolasMassart requested review from gambinish and wachunei and removed request for gambinish October 1, 2024 10:27
Copy link
Contributor

github-actions bot commented Oct 1, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 0c964b4
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/1af5cc2e-b561-47bf-92ba-48c29006c5df

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@NicolasMassart NicolasMassart added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 2, 2024
@MetaMask MetaMask deleted a comment from github-actions bot Oct 2, 2024
@NicolasMassart NicolasMassart added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 2, 2024
Copy link
Contributor

github-actions bot commented Oct 2, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 0aa75cf
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/866e6b89-6a57-47eb-9d66-d23e0677eb8d

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@NicolasMassart NicolasMassart requested a review from a team as a code owner October 3, 2024 09:19
Copy link

sonarqubecloud bot commented Oct 3, 2024

@NicolasMassart NicolasMassart added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 3, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 9b72ec5
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/e5319801-cf93-467d-8520-52f46c47c3be

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for those explanations.

Fyi I am not a codeowner on this, so looks like you'll still need to get that as well.

@NicolasMassart NicolasMassart requested review from gambinish and a team October 3, 2024 20:12
@MetaMask MetaMask deleted a comment from github-actions bot Oct 3, 2024
@MetaMask MetaMask deleted a comment from github-actions bot Oct 3, 2024
Copy link
Member

@wachunei wachunei left a comment

Choose a reason for hiding this comment

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

Looks good to me

@NicolasMassart NicolasMassart added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit bda40a6 Oct 7, 2024
43 checks passed
@NicolasMassart NicolasMassart deleted the 10784_simplify_metrics_calls branch October 7, 2024 14:00
@github-actions github-actions bot locked and limited conversation to collaborators Oct 7, 2024
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

chore: Refactor event tracking method
5 participants