Mixpanel Community Icon

Resolving Mixpanel Event Tracking Issues in SwiftUI Screen Navigation

·
·

Hey, I am currently integrating Mixpanel into my iOS SwiftUI project, and I have encountered an issue while tracking screen view events with properties, including the screen view duration. In my implementation, I am using the following methods:

  1. 1.

    In the onAppear of the view:

  2. 2.

    Mixpanel.mainInstance().time(event: "screen_viewed")

  3. 3.

    In the onDisappear of the view:

  4. 4.

    Mixpanel.mainInstance().track(event: "screen_viewed", properties: properties)

However, I am facing an issue where, when navigating to the next screen, the onAppear of the next screen is called first, before the onDisappear of the current screen. This causes a mismatch in the event tracking order, which results in inaccurate data being recorded. is there any solution to tackle the issue?