Something I think you might find VERY useful, that is a bit of a hidden gem, is Matomo.
First of all, I’m not associated with them in any way.
Matomo is a self-hosted alternative to Analytics, it has lots of features.
BUT it also has a HTTP API.
I have used it in a Thunkable project to collect data (such as user OS, screen size, City etc.), but also you can track clicks with it, for example if a button is tapped, you can use custom Actions to define which button was clicked (and I assume collect what they’ve typed using the ‘search’ parameter). You can also define goals and funnels like on Analytics, so when users have gone a certain route in your app, you get an overview of all users.
(It does give you time spent per user, though it may not be accurate.)
In the example below I added OneSignal and used part of the ID it generates to create a UserID to send with the API, so returning users can have accurate multiple sessions.
Matomo is free for the core, which includes the HTTP API. It’s easy to install on your existing hosting. I think Softaculous has it as a one-click if your hosting company provides that.
More details: https://developer.matomo.org/api-reference/tracking-api
Basic (if slightly messy) example:
Disclaimer: Yes, this means you can technically collect typed passwords and things that you probably shouldn’t. I would advise using this with reasonable caution, and make sure it’s mentioned in your various policies and terms, or that at least ensure the data collected is anonymous. I’m not responsible for anything (legal or otherwise) anyone does with this information…