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

Add screen engagement tracking of time spent and list items scrolled on a screen (close #851) #853

Merged
merged 5 commits into from
Jan 11, 2024

Conversation

matus-tomlein
Copy link
Contributor

@matus-tomlein matus-tomlein commented Dec 11, 2023

Issue #851

This PR adds screen engagement tracking to the tracker.

Screen engagement tracking is enabled by default. It can be disabled using the TrackerConfiguration.screenEngagementAutotracking configuration option.

It consists of the following events and entities:

  • Screen summary entity.
  • Screen end event.
  • List item view event (optional).
  • Scroll changed (optional).

Screen summary entity

The screen engagement information is attached in a screen_summary entity. The entity has information about the time spent on the screen in foreground and background.

It also contains information about the scroll depth on the screen – this is in the form of the last item in a list that the user reached in the screen out of all list items. It is updated using a list_item_view event, see below.

The screen summary entity is attached to the following events:

  • foreground event
  • background event
  • screen end event

Screen end event

The screen_end event is a new event that is tracked automatically before transitioning from one screen view to another screen view event. It does not have any properties, it's only tracked to contain the screen summary information.

In order to implement it, I added a beforeEvents function to the state machines. Using this function, the state machines can return a list of events to be tracked before another event. The new ScreenSummaryStateMachine returns the screen end event whenever a screen view event is tracked.

List item view events

List item view events are tracked as the user scrolls through a list view on the screen. Whenever an item in the list is shown, the event should be tracked. It contains two information:

  1. The index of the list item shown.
  2. The total number of items in the list.

If screen engagement tracking is enabled, the list item view events are aggregated into the screen_summary entity. This means that they are not tracked individually, but the maximum index of viewed items and the total number of items are tracked in the entity on the next screen end or background/foreground event.

For SwiftUI apps, I have added a snowplowListItem view modifier to auto track list item view events in a similar way as we do for screen view events. The following example shows a SwiftUI view annotated both using the snowplowScreen() modifier to track screen views and the snowplowListItem modifier to track list item views:

struct SomeListView: View {
    var body: some View {
        List {
            ForEach(Array(myItems.enumerated()), id: \.1.url) { offset, item in
               Text(item.name)
                .snowplowListItem(index: offset, itemsCount: myItems.count)
            }
        }
        .navigationTitle("Items")
        .snowplowScreen(name: "ItemsList")
    }
}

It is implemented in the Iglu Central demo app.

Scroll changed events

Scroll changed events are similar to the list item view events. They are tracked when the position of a scroll view changes – when the user scrolls. In contrast with the list item view events, the scroll changed events track the position in pixels.

Users will need to implement them manually since we can't provide automatic tracking. In UIKit, this is a matter of adding a delegate for the UIScrollView and tracking a ScrollChanged event with the current position. The event will be aggregated into the screen_summary entity and populate the properties max_y_offset and content_height.

I have added a new view into the SwiftSPM demo app that can be scrolled. It tracks the ScrollChanged events when the scroll position changes.

Iglu Central PR with schemas

Schemas for the new events and entity are not yet published on Iglu Central, they are in review in this PR.

Demo

I have recorded a demo of how the screen engagement tracking works here.

@matus-tomlein matus-tomlein marked this pull request as ready for review December 11, 2023 09:28
@gthomson31 gthomson31 requested a review from a team December 11, 2023 12:37
@matus-tomlein matus-tomlein marked this pull request as draft December 14, 2023 10:57
@matus-tomlein matus-tomlein force-pushed the issue/screen_engagemetn branch from b13a617 to 51e6c2a Compare December 14, 2023 15:48
@matus-tomlein matus-tomlein marked this pull request as ready for review January 2, 2024 11:27
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

Sources/Snowplow/Configurations/TrackerConfiguration.swift Outdated Show resolved Hide resolved
@matus-tomlein matus-tomlein merged commit 6210a1b into release/6.0.0 Jan 11, 2024
20 checks passed
@matus-tomlein matus-tomlein deleted the issue/screen_engagemetn branch January 11, 2024 18:14
matus-tomlein added a commit that referenced this pull request Jan 19, 2024
matus-tomlein added a commit that referenced this pull request Jan 19, 2024
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