How do I record how long a user listens to an audio file?

Hello to all,
Glide is developing so incredibly fast. Especially that we can now use Custom JavaScript code, I find very exciting. I maintain a Meditation app that is used in psychological research. We are interested in meditation frequencies of our subjects. Before the introduction of the custom code options, I didn’t see a way to objectively measure how long a subject listened to a meditation file. Normally, without Glide, I would have JavaScript running until the meditation audio is listened to and recording the elapsed time in the background. I am not sure if this could be implemented using the Custom Code Column. Do you guys have any good ideas if and how something like this would be possible in Glide?

Thanks a lot!

1 Like

In my opinion, it is not possible in Glide with native tools, and it is not even possible through the use of a javascript column… but if there is anyone here who can say otherwise I would be delighted!

1 Like

You could always gather timestamps from a button going into and out of a screen. A workaround :slight_smile:

Or within a screen as you use visibility conditions to guide the user through the process.

I do that already, but sometimes, people start the meditation without completing it with a press on the “end” button…

Some ideas:

  • if you know how long the audio lasts…

  • math column as a timer - set column to get the time the user enters the screen, and do math from now to work out how many mins it is from now for the user (e.g. enters 09:00, now is 09:05, so column result = 5)

  • give them a button to ‘escape’ the page before the end…

  • set column in the action to a usc- temporary value (I would name this like toggle/ usc-quit early?)

  • this button is visible if usc-quit early is NOT true… AND the time counter is less than the total time for the audio (can be entered in manually to your visibility condition, but you could also make this more generic if you have lots of audio files of varying durations)

  • the user can then click early to get out… but they are given a ‘show notification’ to ask if they are sure, then a second button to quit

  • and you can set columns and record timestamps to get into this screen, in this screen, and to leave the screen

If you want to be fancy, you could even have a rich text component with CSS as a modal popup - to draw the attention and have more control of the experience.

You could then keep track of people who cut their sessions short… and maybe use behavioral nudges in the UX to persuade them to spend more time (to be in the moment, otherwise the whole process might not work out so well).

Good luck!

2 Likes

Those are all great ideas, but if Android users use their native back button then you have no way to prevent that, I think.

2 Likes

yeah, that’s a bit of a trap.
I used to think that hiding the back button was a clever trick, but it only ends up getting you into trouble.
So these days I try to avoid it.

2 Likes

Another idea might be to write JavaScript code in a rich text component that then sends, for example, the user ID and current meditation time to an API every 60 seconds, which then stores this incoming data in a Google Sheets file. However, I wonder if it is even possible to write JavaScript into a rich text component and what happens to the execution of the code when the device screen turns off. Do you have any experience with that?

No, I’m afraid that CSS/HTML is the limit when it comes to Rich Text. You can’t run javascript.

1 Like

Thanks a lot for all your ideas, many of them helped me. I just set a few more timestamps : ) At the same time, it still happens that users don’t turn on their phone again after the meditation is finished and therefore don’t mark it as completed.
Another idea could be:
In a JavaScript code column I write a function that either goes to 0 as soon as the user is no longer in the meditation tab. For this, the function would have to check the availability of some DOM HTML elements (is that even possible in Glide?). However, if the user is in the meditation tab AND listening to a meditation AND the current minute of the device clock time (now) is even, the function jumps to 1 and simultaneously POSTs usage statistics to an API (with Javascript functions like http.open(…)), which in turn writes to my Google Sheet. So my usage statistics would be refreshed every 2 minutes.

Do you think this approach is promising?