mixpanel / mixpanel-swift

Official iOS (Swift) Tracking Library for Mixpanel Analytics
https://mixpanel.com
Apache License 2.0
435 stars 234 forks source link

How to track multiple "time" events with the same name #614

Open fzy-github opened 1 year ago

fzy-github commented 1 year ago

Hey Mixpanel team,

I have a question - is it possible to track multiple "time" events withe the same name?

Let's imagine that I am working on a "cloud storage" app and I want to track how long it takes for a user to upload a single file to a server and at the same time app allows uploading multiple files in parallel.

my tracking code would look smth like:


func startUpload(filePaths: [String]) {
 filePaths.forEach { upload($0) }
}

func upload(filePath: String) async {
  Task {
    do {
      Mixpanel.mainInstance().time("FileUpload")
      try await httpClient.uploadFile(filePath)
      Mixpanel.mainInstance().track("FileUpload", properties: ["result": "ok", "path": filePath])
    } catch {
      Mixpanel.mainInstance().track("FileUpload", properties: ["result": "fail", "path": filePath])      
    }
  }
}

Is this valid code from Mixpanel tracking point of view? Will it correctly track eg. 3 uploads happening in parallel?

If not how this can be achieved using mixpanel?

I can possibly create a unique event name like eg: FileUpload-\(filePath) but this means that I am not following best practice as shown eg here: https://docs.mixpanel.com/docs/tracking/how-tos/events-and-properties#best-practices

nathanmclain commented 10 months ago

@fzy-spyro ever get an answer or find a work around on this?

fzy-github commented 10 months ago

@nathanmclain unfortunately no. I implemented my own way of tracking those events

cmriboldi commented 10 months ago

@nathanmclain and @fzy-spyro I fixed the issue in this MR. It would be nice if we get some eyes and traction on it so that we can get this merged in so that we don't have to make our own "fixes" for this very fixable issue with the SDK.