Similar psychology:
When someone starts a study session, you could automatically turn off notifications, leaving fewer things to pull their mind away partway through.

Halfway through a lesson, try pausing people to reflect on why they started, pulling their attention back before their mind wanders off.

Consider giving a task a sense of importance, e.g., a limited number of lives, so people pay closer attention rather than drifting off.

One option is to cap an onboarding exercise at a brief window, like 30 seconds, rather than letting it run indefinitely, so attention holds throughout.

During a timed focus session, it may help to show a hero who walks further the longer the user focuses, then rests by a bonfire when they pause.

Keeping flows short and free of unrelated links could reduce drop-off halfway through, as users' minds have fewer chances to wander before they finish.
Silencing notifications and clearing busy screens might help users hold their attention for longer, with fewer things pulling their mind off the task.
Reminding users why they started, partway through a long lesson or task, could keep their motivation up just as their attention begins to drift.
Wandering minds can make answers careless, so giving a task some importance or a time limit may lead to more considered input from users.