Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

chore: metrics infrastructure for first-time events#483

Merged
vinistevam merged 10 commits into455-flush-events-saved-before-users-opt-in-outfrom
416-infrastructure-first-time-event
Feb 9, 2023
Merged

chore: metrics infrastructure for first-time events#483
vinistevam merged 10 commits into455-flush-events-saved-before-users-opt-in-outfrom
416-infrastructure-first-time-event

Conversation

@vinistevam
Copy link
Copy Markdown
Contributor

@vinistevam vinistevam commented Feb 1, 2023

Overview

The aim of this PR is to implement the infrastructure for first-time events and send events to the segment whenever the main process is started and also when UI is loaded.

Changes

  • metrics-service.ts: created the infrastructure for first-time events.
    • create a separate electron store to save first-time events.
    • whenever the track method is called it checks if events were already sent before and include a boolean property on the event object.
  • exposed page and screen methods from segment SDK on the analytics wrapper.
  • moved ipcMain. handlers to metrics-service.ts.
  • Track events:
    • DESKTOP_APP_STARTING sending right before DesktopApp.init() in the main.ts
    • DESKTOP_UI_LOADED sending from routes.component.js
    • UI_CRITICAL_ERROR included an additional event because either routes loaded or componentDidCatch in case of an error.

Issues

resolves: #416 and #481

@vinistevam vinistevam marked this pull request as ready for review February 2, 2023 08:18
@vinistevam vinistevam requested a review from a team February 2, 2023 08:18
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be simpler just to maintain an array in the store of the unique event names that have been sent?

That way we don't have to default the map of every single event during initialisation, we don't have to worry about adding new events down the line and ensuring we default those also, plus we can simplify the logic here and always append the event name and just save the Set to remove any duplicates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed, removed the initialisation in the constructor and as you mentioned much simpler to just maintain what we already sent and not bother with new events.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We discussed the importance of keeping this state as isolated as possible to potentially persist between installs, so should this be in it's own electron store and therefore a separate file?

I'm not sure what segmentApiCalls does in truth, but I'm assuming it could still function in a separate store.

Copy link
Copy Markdown
Contributor Author

@vinistevam vinistevam Feb 2, 2023

Choose a reason for hiding this comment

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

I've just put this state isolated in its own electron store, now should be fine.
Now the segmentApiCalls I'm removing it as there is no usage at the moment with this approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned in the other PR, i'd vote to put these directly on the electronBridge and to remove this helper method.

@vinistevam vinistevam force-pushed the 416-infrastructure-first-time-event branch from 5550b15 to 9e4b3fd Compare February 2, 2023 21:43
@vinistevam vinistevam force-pushed the 455-flush-events-saved-before-users-opt-in-out branch from abb6d50 to 919ced6 Compare February 2, 2023 21:54
@vinistevam vinistevam force-pushed the 416-infrastructure-first-time-event branch 3 times, most recently from a01a817 to 5b0a191 Compare February 3, 2023 16:22
@vinistevam vinistevam force-pushed the 455-flush-events-saved-before-users-opt-in-out branch from bb2db6c to 544efea Compare February 6, 2023 18:11
@vinistevam vinistevam force-pushed the 416-infrastructure-first-time-event branch from 499291e to b544d3d Compare February 6, 2023 18:20
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need the Boolean( here? Won't includes return a boolean already and the negation keep it as a boolean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be clearer to rename this processedEvents or seenEvents?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As this is visible in the filesystem, should we keep it generic and maybe just call it mmd-desktop-metrics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just for visibility as we discussed in a channel apart, I'm not using mmd-desktop-metrics just because it will clash with the first electron store we have in metrics.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't those be saved only if MetricsDecision.PENDING?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this.saveProcessedEvents is saving the names of the events that were already triggered that way we know if it's the first time we track the event and include a property to further be filtered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense. Naming is confusing though. Should we rename it to saveProcessedEventName? Also we should rename the method signature. Should reveive an eventName: string instead of a event: string. That will make the signature consistent with both the saveProcessedEvents and the ipcMain.handle('analytics-track'....

@vinistevam vinistevam force-pushed the 416-infrastructure-first-time-event branch 2 times, most recently from d21726f to 5f3e6ff Compare February 7, 2023 15:32
@vinistevam vinistevam force-pushed the 455-flush-events-saved-before-users-opt-in-out branch 2 times, most recently from 32df9e1 to 634f27c Compare February 8, 2023 05:20
@vinistevam vinistevam force-pushed the 416-infrastructure-first-time-event branch from 5f3e6ff to 66e52f0 Compare February 8, 2023 06:18
@vinistevam vinistevam force-pushed the 455-flush-events-saved-before-users-opt-in-out branch from 634f27c to 0bbaf10 Compare February 8, 2023 19:30
@vinistevam vinistevam force-pushed the 416-infrastructure-first-time-event branch from 66e52f0 to dc0c381 Compare February 8, 2023 19:32
Copy link
Copy Markdown
Contributor

@bergarces bergarces left a comment

Choose a reason for hiding this comment

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

LGTM

@vinistevam vinistevam merged commit d299844 into 455-flush-events-saved-before-users-opt-in-out Feb 9, 2023
vinistevam added a commit that referenced this pull request Feb 9, 2023
* feat: metrics infrastructure for first-time events (#483)
@vinistevam vinistevam deleted the 416-infrastructure-first-time-event branch February 9, 2023 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants