Search code examples
mixpanel

Mixpanel Android - consecutive timeEvent requests scenario


Background

I'm referring to this documentation about timeEvent:

MixpanelAPI mixpanel =
    MixpanelAPI.getInstance(context, MIXPANEL_TOKEN);

// start the timer for the event "Image Upload"
mixpanel.timeEvent("Image Upload");

// stop the timer if the imageUpload() method returns true
if(imageUpload()){
    mixpanel.track("Image Upload");
}

The method description explains:

Begin timing of an event. Calling timeEvent("Thing") will not send an event, but when you eventually call track("Thing"), your tracked event will be sent with a "$duration" property, representing the number of seconds between your calls.

Question

It looks like imageUpload() will return a boolean. if it's true then Mixpanel will track this event with duration property specified..

However, it does not state what will happen if imageUpload() returns false.. What if I have two consecutive calls to this uploadImage() method and the first one returns false and the following returns true? will that mess up the event tracking?

the calling sequence will be:

// first upload
mixpanel.timeEvent("Image Upload");
// first upload failed

// second upload
mixpanel.timeEvent("Image Upload");
// second upload succeeded
mixpanel.track("Image Upload");

will the second timeEvent override the first one?


Solution

  • After checking the source code on GitHub (here), it is clear that if the first upload doesn't call track("Image Upload"), then the second timeEvent("Image Upload") will override the first timing, and only the second event will be tracked.