mixpanel / mixpanel-swift

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

Bug in 3.1.3 #514

Closed c128128 closed 2 years ago

c128128 commented 2 years ago

Looks like with version 3.1.3 a new bug was introduced.

Some events are deleted and never sent to server.

A little diving into your SDK get me here https://github.com/mixpanel/mixpanel-swift/blob/cb6c5d648e42987e1285897a3f856ff7e24270a9/Sources/MixpanelInstance.swift#L1416

From bellow logs, 2 events are inserted and then deleted but never flushed.

[Mixpanel - MixpanelInstance.swift - func loggingEnabled] (info) - Logging Enabled
[Mixpanel - Flush.swift - func flushQueueInBatches(_:type:)] (debug) - Sending batch of data
[Mixpanel - MPDB.swift - func updateRowsFlag(_:newFlag:)] (info) - Succesfully update rows from table mixpanel_5c87ed810d2e683c3346f980b9f80364_people
[Mixpanel - Flush.swift - func flushQueueInBatches(_:type:)] (debug) - [["id": 8, "properties": {
[Mixpanel - Network.swift - func buildURLRequest(_:resource:)] (debug) - Fetching URL
[Mixpanel - Network.swift - func buildURLRequest(_:resource:)] (debug) - https://api.mixpanel.com/track/?ip=1
[Mixpanel - MPDB.swift - func insertRow(_:data:flag:)] (info) - Successfully inserted row into table mixpanel_5c87ed810d2e683c3346f980b9f80364_events
[Mixpanel - MixpanelInstance.swift - func reachabilityCallback(reachability:flags:unsafePointer:)] (info) - reachability changed, wifi=true
[Mixpanel - MPDB.swift - func insertRow(_:data:flag:)] (info) - Successfully inserted row into table mixpanel_5c87ed810d2e683c3346f980b9f80364_events
[Mixpanel - Network.swift - func buildURLRequest(_:resource:)] (debug) - Fetching URL
[Mixpanel - Network.swift - func buildURLRequest(_:resource:)] (debug) - https://api.mixpanel.com/decide?version=1&lib=iphone&token=5c87ed810d2e683c3346f980b9f80364&distinct_id=32FCD7E5-FA72-4B5D-8019-195667FDB83A&properties=%7B%22$swift_lib_version%22:%223.1.3%22,%22$ios_app_version%22:%22616%22,%22$ios_device_model%22:%22iPhone10,5%22,%22$ios_app_release%22:%221.5.2%22,%22$ios_version%22:%2215.3%22,%22$ios_lib_version%22:%223.1.3%22%7D
[Mixpanel - MPDB.swift - func deleteRows(_:ids:)] (info) - Succesfully deleted rows from table mixpanel_5c87ed810d2e683c3346f980b9f80364_events
[Mixpanel - MPDB.swift - func readRows(_:numRows:flag:)] (info) - Successfully read 2 from table mixpanel_5c87ed810d2e683c3346f980b9f80364_events
[Mixpanel - MPDB.swift - func deleteRows(_:ids:)] (info) - Succesfully deleted rows from table mixpanel_5c87ed810d2e683c3346f980b9f80364_events
********************************************************* flush() ********************************************************* 
[Mixpanel - MPDB.swift - func insertRow(_:data:flag:)] (info) - Successfully inserted row into table mixpanel_5c87ed810d2e683c3346f980b9f80364_people
[Mixpanel - MPDB.swift - func insertRow(_:data:flag:)] (info) - Successfully inserted row into table mixpanel_5c87ed810d2e683c3346f980b9f80364_people
[Mixpanel - MPDB.swift - func readRows(_:numRows:flag:)] (info) - Successfully read 2 from table mixpanel_5c87ed810d2e683c3346f980b9f80364_people
[Mixpanel - Flush.swift - func flushQueueInBatches(_:type:)] (debug) - Sending batch of data
[Mixpanel - Flush.swift - func flushQueueInBatches(_:type:)] (debug) - [["$mp_metadata": {
[Mixpanel - Network.swift - func buildURLRequest(_:resource:)] (debug) - Fetching URL
[Mixpanel - Network.swift - func buildURLRequest(_:resource:)] (debug) - https://api.mixpanel.com/engage/?ip=1
[Mixpanel - MPDB.swift - func insertRow(_:data:flag:)] (info) - Successfully inserted row into table mixpanel_5c87ed810d2e683c3346f980b9f80364_events
[Mixpanel - MPDB.swift - func deleteRows(_:ids:)] (info) - Succesfully deleted rows from table mixpanel_5c87ed810d2e683c3346f980b9f80364_people

Tested also with 3.1.2 and it works as expected.

zihejia commented 2 years ago

hi @c128128 , this is per design. Could you check your project setting if the Automatically collect common mobile events toggle is off? If so, it will stop tracking common mobile events so you will see those events not being able to send to Mixpanel anymore. Versions prior to 3.1.3 contain a bug that does not respect this setting from the server.

image

zihejia commented 2 years ago

I'm closing this issue now, please feel free to reopen if you have any questions.

c128128 commented 2 years ago

@zihejia The Automatically collect common mobile events is off, and I think you have a race.

Ex:

  1. I start the app.
  2. SDK is doing request to get the Automatically collect common mobile events from server.
  3. I record some events.
  4. The result from request 2 is coming back.
  5. SDK is deleting my recorded events.
  6. I am missing events from 3
zihejia commented 2 years ago

hi @c128128 , because the Automatically collect common mobile events is off, your automatic events will be removed but it won't remove your regular events. The reason you see this is because First App Open is tracked before we have a chance to check whether your Automatically collect common mobile events is off or not(can't move it earlier, to avoid more problems).

You can also choose not to rely on the server toggle Automatically collect common mobile events by setting trackAutomaticEvents param like so Mixpanel.initialize(token: "your project token", trackAutomaticEvents: false). In that way you won't see this deletion happening.

c128128 commented 2 years ago

You can also choose not to rely on the server toggle Automatically collect common mobile events by setting trackAutomaticEvents param like so Mixpanel.initialize(token: "your project token", trackAutomaticEvents: false). In that way you won't see this deletion happening.

I've done this. And my events get deleted. The deleted events from my report are mine and not trackAutomaticEvents, that's why I am reporting this.

zihejia commented 2 years ago

hi @c128128 , it should only remove Mixpanel automatic events prefix with $ae_, as long as your event name does not start with $ae_, there is no way they get deleted. Let me know if there is something I missed. https://github.com/mixpanel/mixpanel-swift/blob/cb6c5d648e42987e1285897a3f856ff7e24270a9/Sources/MixpanelPersistence.swift#L91

c128128 commented 2 years ago

Hmm.. I will check tomorrow and let you know. But for sure that something introduced in 3.1.3 is deleting my events.

c128128 commented 2 years ago

@zihejia Checked! And looks like the problem is somewhere else, unfortunately I have no time to debug it. I have created a demo project here https://github.com/c128128/MixpanelBug, check main.swift

BrightChad commented 2 years ago

FWIW, I just updated to 3.1.3 and I suspect I'm missing a lot of events based on some of my KPI's dropping in half. I downloaded my app and created a new account and watched the events come in and did not see a lot of events I would expect.

I came to the Issues list to see if there is an open issue and found this. I'll keep digging into this but there might be a real bug here.

zihejia commented 2 years ago

hi @c128128 , thanks for providing the sample app, that would help a lot. I will get back to you shortly.

zihejia commented 2 years ago

hi @c128128 @BrightChad . We did find the issue and fix it in v3.1.4. It was caused by the delete SQL command being incorrectly executed. Sorry about the inconvenience! I've verified the sample app with the fix and it works as expected. I'm closing this issue now, feel free to reopen if you have any other issues.

BrightChad commented 2 years ago

Thanks for the quick turn. I didn't have time to isolate the bug on my app but will update to this release right now and test it out.

UPDATE: ran through onboarding sequence again (which was missing events) and it worked. It was only one test pass but I used the same steps as before.