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

Add eventID's to time and track methods for more reliable durations. #625

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cmriboldi
Copy link

@cmriboldi cmriboldi commented Jan 22, 2024

As mentioned in this issue there is no way to time events independent of their name. This is a HUGE issue for any serious user of Mixpanel events because there is no way to follow the Best Practice Naming Guidelines and be certain your durations are correct.

For example, if I were to have a generic System event that I want to time as long as I have one of those events I'm fine, but if I ever need to time multiple system events there is no way for me to organize them or distinguish using Mixpanel which .track(event:) call matches with the original time(event:) call. This means that durations will be completely missing or inaccurate.

The that I'm adding in this MR is to link the tracking of timed events to an EventID instead of to the event name. That means callers of the SDK can provide their own unique id's for id's of events and be guaranteed that when the duration completes for that generic event the duration is completely accurate.

I added a new function signature for these timed and tracked events that allow users to provide a String eventID to link the two events. I would have liked to create a more type safe ID so that it's not just any string but because of the way the SDK works with events I didn't want to change too much besides separating the idea of an eventName with the idea of an eventID. I also separated out the idea of a TimedEvents dictionary from the InternalProperties dictionary that existed previously, this adds some small type safety around the dictionary and adds purpose clarity in the code.

The original method signatures still exist and work just as they did before they simply call the eventID versions of these methods so that there aren't two places that the logic needs to be maintained.

@cmriboldi cmriboldi changed the title Cmriboldi/add event i ds Add eventID's to time and track methods for more reliable durations. Jan 22, 2024
Comment on lines +40 to +41
typealias TimedEventID = String
typealias TimedEvents = [TimedEventID: TimeInterval]
Copy link
Author

Choose a reason for hiding this comment

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

I added these two typealiases for additional type-safely and clarity. Ideally TimedEventID is it's own type that wraps a string but I didn't want to change the call site too drastically from what it already is.

@@ -1017,17 +1020,34 @@ extension MixpanelInstance {
- parameter properties: properties dictionary
*/
public func track(event: String?, properties: Properties? = nil) {
track(event: event, withID: nil, properties: properties)
Copy link
Author

Choose a reason for hiding this comment

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

The call site for all of these methods remains the same for backwards compatibility, and under the hood they just call the other method that uses the event id.

return timedEvents
}
let timedEventID = eventID ?? eventName
Copy link
Author

Choose a reason for hiding this comment

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

If no eventID is provided we fall back to using whatever the eventName is which means we default back to the original behavior.

@@ -139,32 +141,32 @@ class Track {
update(&superProperties)
}

func time(event: String?, timedEvents: InternalProperties, startTime: Double) -> InternalProperties {
func time(eventID: TimedEventID, timedEvents: TimedEvents, startTime: TimeInterval) -> TimedEvents {
Copy link
Author

@cmriboldi cmriboldi Jan 22, 2024

Choose a reason for hiding this comment

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

I renamed the property name for clarity, and changed the types for consistency/correctness and removed the optionality of the eventID because it didn't need to be optional.

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.

None yet

2 participants