Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong screen entity info assigned for screen end event and in case events are tracked right before screen view (close #673) #674

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

matus-tomlein
Copy link
Contributor

Issue #673

Due to a bug in how the screen state is updated in the tracker, the screen end event is assigned the wrong information – instead of referring to the previous screen name and ID, it contains information of the subsequent screen.

This bug is not only limited to screen end events but may also appear in case an event is tracked right before a screen view event – the event will be assigned the next screen view instead of the one used when it was tracked.

@matus-tomlein matus-tomlein changed the title Fix wrong screen entity info assigned for screen end event and in case events are tracked in parallel (close #673) Fix wrong screen entity info assigned for screen end event and in case events are tracked right before screen view (close #673) Feb 12, 2024
@matus-tomlein matus-tomlein force-pushed the issue/673-fix_screen_end branch from 247367c to c9b814a Compare February 12, 2024 20:06
@matus-tomlein matus-tomlein force-pushed the issue/673-fix_screen_end branch 3 times, most recently from b514871 to 41f2a05 Compare February 13, 2024 08:20
@matus-tomlein matus-tomlein force-pushed the issue/673-fix_screen_end branch from 41f2a05 to 6370f29 Compare February 13, 2024 17:15
Copy link
Contributor

@mscwilson mscwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -333,8 +328,9 @@ class Tracker(
override fun apply(data: Map<String, Any>) {
if (screenViewAutotracking) {
val event = data["event"] as? ScreenView?
event?.let { event ->
getScreenState()?.let { state ->
if (event != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It had a slightly different behaviour which I think was unintended – the ?: track(event) part could be executed even in case the previous let block was evaluated but returned null. I think this if-else better reflects what should happen and is a bit more clear.


Assert.assertEquals(2, numberOfScreenViews)
val numberOfScreenViews = eventSink.trackedEvents.filter { it.schema == TrackerConstants.SCHEMA_SCREEN_VIEW }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: strange name for a list, I was expecting an int

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed now.

Assert.assertEquals(10.0, screenSummary?.get("foreground_sec"))
Assert.assertEquals(0.0, screenSummary?.get("background_sec"))

// should have the screen name of the first screen view
val screenEndScreen = screenEnd?.entities?.find { it.map["schema"] == TrackerConstants.SCHEMA_SCREEN }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read the word "screen" so much it doesn't look like a real word anymore

@matus-tomlein matus-tomlein changed the base branch from master to release/6.0.1 February 14, 2024 11:45
@matus-tomlein matus-tomlein merged commit 486d3d7 into release/6.0.1 Feb 14, 2024
2 of 3 checks passed
@matus-tomlein matus-tomlein deleted the issue/673-fix_screen_end branch February 14, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants