Question

Event Tracking with Duration

  • 19 June 2019
  • 4 replies
  • 64 views

Userlevel 2
Badge

Hello for every one!

Could you please help me to solve the one little question about event tracking with in Android and iOS? The question is if I can use "$duration" property in the JSON directly. For instance, I want to track an event with additional parameter - seconds elapsed. But according the API I have to call .timeEvent("event name") at the first and after event is completed - call .track("event name"). But in my case there are several analytics systems already implemented.

Can I use "$duration" in the direct way:

JSONObject props = new JSONObject();

try {

props.put("Category", "some text");

props.put("Label", "some label");

props.put("$duration", (double) (timeInMilliSeconds / 1000.0));

} catch (JSONException e) {

e.printStackTrace();

}

AnalyticsManager.getMixpanel().track(name, props);


For now it works, but will it lead to bugs in the future?

Thank you for the answer!




4 replies

Userlevel 3
Badge

Hi @Valery,

For $duration event, do you mean the $ae_session? By default, Mixpanel tracks "App Session" ($ae_session) for mobile events. Their Track Mobile and Web Sessions article talks in more detail about it.

If you would like to further customize the app session event, you can adjust the session length too. Their Adjust Session Length Parameters for App Session Events article gives a more detailed explanation on how to set it up for IOS and Android.


Hopefully this helps!


Userlevel 2
Badge

Thank you @shawn.barrett for your answer!
But the core of the problem is in the other event. There is a special methods which provides time tracking functionality. It accepts event name as a parameter and after calling .track("event name") method it sends that event with duration to mixpanel backend. But in my case I would like to user only .track("event name") method without starting method .time event() but passing "$duration" key with seconds elapsed.

http://mixpanel.github.io/mixpanel-android/index.html


Userlevel 3
Badge

@Valery Thanks for that context! I see what you are referring to now. You can absolutely track a $duration property without using the internal timeEvent: method. However, you will need to build your own custom logic to populate your $duration property - as you have done already and seem to be working fine.

Out of curiosity, is there some reason you would prefer using a different method for calculating duration rather than the with timeEvent?


Userlevel 2
Badge

@shawn.barrett Great! Thank you!
We have some kind of special analytics events which track time for the database population or server responses. In this case this events can be finished or not.


Reply