mixpanel / mixpanel-swift

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

Does Mixpanel work great out-of-the-box for apps with short sessions? #486

Closed kgaidis closed 2 years ago

kgaidis commented 2 years ago

I have a small app where users don't have to spend time inside of the application.

I recently had a day (November 12) where Mixpanel had logged 0 events from the iOS app (note: I manually 'gate' out events sent by my personal accounts, and I also log other events from a server). I was surprised as all other days had events.

Few days later, November 12 started showing some events, but not all. I assume the events were cached, user returned to the app, and the events were sent.

I also log events to Google Analytics. Same initialization point. Same event logging point.

I started comparing the two, and Mixpanel logs way less events. Here is a an event "logged_in_open" and there's a massive difference: unnamed

I couldn't come up with any reasons other than either Google Analytics is broken, or Mixpanel is maybe not friendly to handling apps with short sessions. I do see that Mixpanel logs every 60 seconds or on app background. My app will likely most-often log events on app background. However, iOS only gives a short window on app background to finish work, is Mixpanel work finishing in time? It seem to be using lower-priority utility queues. Does Mixpanel ever log if there's an event build-up, or if event logs are old?

I figured to flag this as maybe this has been brought up before. Of course, I could change Mixpanel settings to flush more-often, but it would be nice if it worked out-of-the-box.

zihejia commented 2 years ago

hi @kgaidis , which SDK version are you using?

kgaidis commented 2 years ago

2.10.3 via SPM

zihejia commented 2 years ago

Mixpanel SDK should be able to handle your case without any problem. Any event that doesn't get sent will be sent next time when the flush happens. If you don't track too many events, you can also call flush manually after each event, events will be sent to Mixpanel immediately.

Alternatively, we'd recommend you use our 3.0.0.beta.5 via SPM(just point to 3.0.0.beta branch). It has a huge improvement for tracking performance. https://github.com/mixpanel/mixpanel-swift/releases/tag/v3.0.0.beta.4

Hope that helps.

kgaidis commented 2 years ago

Thank you for the advice!

I will go ahead and try "3.0.0.beta.5" and report back on how that goes. If that doesn't give parity, I will add custom flush logic.

My app doesn't have a lot of users, and the session times are small. On a surface level, it probably isn't something Mixpanel has to worry about. However, I do think these scenarios of small sessions can happen. Especially for up-and-coming apps. If Mixpanel iOS library is missing events, that means users will not be getting as much value out of the analytics (getting data is 80%+ of the value). It may be worth examining this more-deeply.

zihejia commented 2 years ago

hi @kgaidis , how did it go with "3.0.0.beta.5"? I will close this one for now, feel free to reopen if the problem still exists on "3.0.0.beta".

kgaidis commented 2 years ago

I will get back to it a little later after I collect more data. However, one small data point did seem to show improvements.

I think Google Analytics doesn't like it if there are dots in an event name, so I had to change the event name I was targeting.

kgaidis commented 2 years ago

@zihejia

It does seem to be a lot better.

Mixpanel logged 100 events, vs. 110 for Google Analytics. In very simplified terms, it went from missing 50% of the events (in the old library) to missing about 10% of the events (in the new library), which is a big upgrade.

Screen Shot 2021-12-31 at 9 45 49 AM