I tried to track a event with duration by timeEvent method. And I called timeEvent method and also called track method to finish the timer that the timeEvent method made. But, the event was recored when the track method called, not the time when timeEvent method had been called. What can I do to track the event when timeEvent called?
Hi john, Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> 👋
Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai
Mixpanel’s timeEvent/time_event (or time in iOS Swift/Obj‑C) is only for measuring duration. It doesn’t create an event at the moment you call it; it just starts a timer. The actual event is only sent when you call track, and that event’s timestamp is when track runs, with a Duration property added. This is the expected behavior in all the SDKs. [JS SDK events; Android SDK events]If you need: 1. Event timestamp to be when the action started
You’d need to explicitly send that as an event property yourself, e.g.:
js
const startedAt = Date.now();
// later…
mixpanel.track("Some Event", {
started_at: startedAt,
// other props...
});
```LBKS Then analyze using that custom property instead of the event’s ingestion timestamp.LBKS2. **A separate event at start and another at finish**
Call `track` twice:
- Once immediately (start event)
- Once after completion (finish event, possibly using `timeEvent`/`time` only to compute `Duration`).LBKSThe docs don’t describe any way to have Mixpanel record the event **at** `timeEvent` time automatically; it always records when `track` is called and adds a `Duration` field based on the earlier timing call. [[iOS Swift timing](https://docs.mixpanel.com/docs/tracking-methods/sdks/swift#sending-events); [React Native timing](https://docs.mixpanel.com/docs/tracking-methods/sdks/react-native#sending-events)]
kapa.ai is still learning and improving, please let me know how I did by reacting below.
ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
Ansh A. Thank you for your answer. So, the event that I want to track with a duration can't be ordered properly, right? For example, if events B,C, and D are triggered during the duration of event A : Expected: A (with a duration) -> B -> C -> D. Actual Order : B -> C -> D -> A(with a duration).
Yes, that i want to do. But, I found that the event is not recorded when the timeEvent method is called. And the event is recorded when the track method is called later. Is it right?
Yes, that's right. So, you need to at the same time call timeEvent and track event
By doing so, the duration of an event is recorded as 0. Right?? Let’s say I have two events:
Event A: a page view event that I want to track with a duration
Event B: a button click event on that page
In my implementation, I trigger the events in this order:
timeEvent('A');
track('B');
track('A');And the order of events is recorded as B -> A(with duration). But, I want to track the events by order of A(with duration) -> B . Is there any other ways to acheive this? If not, that's okay. I'll modify a code to adjust the sequence of order. Thank you for your help, Ansh! It was very helpful for me.
