Segmentation

Introduction

Long user sessions typically contain a mix of movement and non-movement events (clicks, keystrokes, pauses, etc.), which makes it difficult to analyze specific portions of user interaction in isolation. To address this, PyWIB provides segmentation utilities that split a session into smaller, meaningful units called traces.

Working with traces instead of full sessions allows most movement-related metrics (velocity, acceleration, jerkiness, path, AUC, MAD, AAD) to be computed over a well-defined, continuous portion of interaction, rather than across gaps caused by clicks, pauses, or other non-movement events.

Note

Most trajectory and movement metrics documented in Movement Metrics and Trajectory Metrics are designed to operate on traces. Most of these metrics automatically compute the traces from the input dataframe, but you can manually compute the traces using your own segmentation logic if needed.

What is a Trace?

A trace is defined as a sequence of consecutive, non-stopped mouse or touch movements occurring between two non-movement events.

In other words, a trace begins after a non-movement event (such as a click, a key press, or a pause) and ends when the next non-movement event occurs. This segmentation approach is widely used in HCI research to gain more precise insights into user movement and trajectory patterns.

Movement Segmentation

Movement-based segmentation is implemented through two functions, both of which accept a DataFrame containing interaction event data as input:

  • extract_trace(): extracts a single list of traces from a DataFrame representing one session.

  • extract_traces_by_session(): extracts traces across multiple sessions, returning a dictionary where each key is a sessionId and each value is the corresponding list of traces for that session.

These functions rely on the presence of movement and non-movement event types (see EventTypes) to determine trace boundaries.

Keystroke Segmentation

Segmentation is not limited to movement data. pywib also provides a method to extract traces of keystroke-only interaction, which is useful when computing metrics such as typing duration or typing speed over isolated typing episodes.

The function extract_keystroke_traces_by_session() reduces a DataFrame to a dictionary containing, for each session, a list of segments in which the user’s interaction occurs exclusively through the keyboard.

Notes

When choosing whether to segment your data before computing metrics, consider the following:

  • Unsegmented DataFrames: metrics are computed over the entire session, which may mix distinct movement episodes together.

  • Segmented traces: metrics are computed per trace, offering finer-grained insight but requiring an extra preprocessing step.

This distinction is particularly relevant for metrics such as num_pauses(), where the behaviour of the computation changes depending on whether the input DataFrame is segmented or not (see Timing Metrics).

References

[1]

Tzafilkou Katerina and Protogeros Nicolaos. Mouse behavioral patterns and keystroke dynamics in End-User development: what can they tell us about users' behavioral attributes? Comput. Human Behav., 83:288–305, June 2018. URL: https://doi.org/10.1016/j.chb.2018.02.012.

[2]

Catia Cepeda, Joao Rodrigues, Maria Camila Dias, Diogo Oliveira, Dina Rindlisbacher, Marcus Cheetham, and Hugo Gamboa. Mouse tracking measures and movement patterns with application for online surveys. In Lecture Notes in Computer Science, Lecture notes in computer science, pages 28–42. Springer International Publishing, Cham, 2018. URL: https://dl.acm.org/doi/10.1007/978-3-319-99740-7_3.

[3]

Adriana Seelye, Stuart Hagler, Nora Mattek, Diane B Howieson, Katherine Wild, Hiroko H Dodge, and Jeffrey A Kaye. Computer mouse movement patterns: a potential marker of mild cognitive impairment. Alzheimers Dement. (Amst.), 1(4):472–480, December 2015. URL: https://alz-journals.onlinelibrary.wiley.com/doi/10.1016/j.dadm.2015.09.006.

[4]

Iftikhar Ahmed Khan, Willem-Paul Brinkman, Nick Fine, and Robert M Hierons. Measuring personality from keyboard and mouse use. In Proceedings of the 15th European conference on Cognitive ergonomics: the ergonomics of cool interaction. New York, NY, USA, January 2008. ACM.

[5]

Jungwook Rhim, Jiwon Kim, and Gahgene Gweon. Using geometric features of drag-and-drop trajectories to understand students' learning. In Proceedings of the 2023 CHI Conference on Human Factors in Computing Systems, volume 19, 1–14. New York, NY, USA, April 2023. ACM. URL: https://dl.acm.org/doi/10.1145/3544548.3581143.

[6]

Masud Karim and Md Hasanuzzaman. A study on mouse movement features to identify user. Sci. Res. J., 08(04):77–82, April 2020.

[7]

Fabian Monrose and Aviel D Rubin. Keystroke dynamics as a biometric for authentication. Future Gener. Comput. Syst., 16(4):351–359, February 2000.

[8]

Dirk U Wulff, Pascal J Kieslich, Felix Henninger, Jonas M B Haslbeck, and Michael Schulte-Mecklenbeck. Movement tracking of psychological processes: a tutorial using mousetrap. Behav. Res. Methods, 57(11):307, October 2025.

[9]

Guillermo Dylan Carvajal-Aza, Alejandro Alvarez-Varela, Javier De Andres, Martin Gonzalez-Rodriguez, Daniel Fernandez-Lanvin, and Mercedes Paino. Pywib: a python library for a multi-modal approach to web interaction behavior analysis. In Proceedings of the 2026 IARIA Annual Congress on Frontiers in Science, Technology, Services, and Applications (IARIA Congress 2026), 103–108. Nice, France, 2026. IARIA Press. URL: https://www.thinkmind.org/library/IARIA_CONGRESS/IARIA_Congress_2026/iaria_congress_2026_1_170_50103.html.

[10]

Martin Schoemann, Malte Lüken, Tobias Grage, Pascal J Kieslich, and Stefan Scherbaum. Validating mouse-tracking: how design factors influence action dynamics in intertemporal decision making. Behav. Res. Methods, 51(5):2356–2377, October 2019.

[11]

Eduard Kuric, Peter Demcak, Matus Krajcovic, and Peter Nemcek. Is mouse dynamics information credible for user behavior research? an empirical investigation. Comput. Stand. Interfaces, 90(103849):103849, August 2024.

[12]

Pascal J. Kieslich, Felix Henninger, Dirk U. Wulff, Jonas M. B. Haslbeck, and Michael Schulte-Mecklenbeck. Mouse-tracking: a practical guide to implementation and analysis. In A Handbook of Process Tracing Methods, pages 20. Routledge, 2nd edition edition, 2019. URL: https://www.taylorfrancis.com/chapters/edit/10.4324/9781315160559-9/mouse-tracking-pascal-kieslich-felix-henninger-dirk-wulff-jonas-haslbeck-michael-schulte-mecklenbeck.

[13]

Christian O'Reilly and Réjean Plamondon. Can computer mice be used as low-cost devices for the acquisition of planar human movement velocity signals? Behav. Res. Methods, 43(1):229–238, March 2011. URL: https://link.springer.com/article/10.3758/s13428-010-0030-3#notes.

[14]

Beatriz Pariente-Martinez, Martin Gonzalez-Rodriguez, Daniel Fernandez-Lanvin, and Javier De Andres-Suarez. Measuring the role of age in user performance during interaction with computers. Univers. Access Inf. Soc., 15(2):237–247, June 2016. URL: https://link.springer.com/article/10.1007/s10209-014-0388-6.

[15]

Clayton Epp, Michael Lippold, and Regan L Mandryk. Identifying emotional states using keystroke dynamics. In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems. New York, NY, USA, May 2011. ACM.

[16]

Preeti Khanna and M Sasikumar. Recognising emotions from keyboard stroke pattern. Int. J. Comput. Appl., 11(9):1–5, December 2010.

[17]

Lisa M Vizer, Lina Zhou, and Andrew Sears. Automated stress detection using keystroke and linguistic features: an exploratory study. Int. J. Hum. Comput. Stud., 67(10):870–886, October 2009.

[18]

A F M Nazmul Haque Nahin, Jawad Mohammad Alam, Hasan Mahmud, and Kamrul Hasan. Identifying emotion by keystroke dynamics and text pattern analysis. Behav. Inf. Technol., 33(9):987–996, September 2014.

[19]

Maarten Dijkstra. The diagnosis of self-efficacy using mouse and keyboard input. PhD thesis, Utrecht University, 2013.