3
20 Comments

Best way to detect scroll level in interactive essay?

Howdy IH! I am working on an interactive essay (https://thisappwillgiveyouabs.com/). I really want to help people learn, so I want to track how much of the essay my users read. This will allow me to re-arrange my sections, or re-write sections where they are dropping off.

I found a few articles about how to get what % of a page a user read. There are options in GA (https://www.blastanalytics.com/blog/scroll-depth-tracking-analysis-google-analytics) and on page events etc. However the ones I have found only record the scroll depth on the subsequent page view. My essay is only one page so that doesn't work as well for me.

I don't have a backend right now, looking into learning Node and using serverless functions etc. I want to track this, but I am still a rookie javascript developer, what would you suggest? Thanks!

posted to Icon for group Developers
Developers
on February 27, 2020
  1. 2

    I think you are looking for user behavior insights as opposed to tracking inbound traffic.
    Seems like a super fast setup to me. Just add some scroll position code on your page:
    https://developer.mozilla.org/en-US/docs/Web/API/Document/scroll_event
    Have a tracking script (not GA) such as:
    https://mixpanel.com/
    https://heap.io/
    https://amplitude.com/
    Just send the custom event you wish to track (i.e. fired off at y position).
    If you want to get super specific (i.e. scroll positioning is getting different results on mobile, for example) you can use JS code to determine if a div is in viewport:
    document.querySelector('div').getBoundingClientRect().top; // 750

    1. 1

      Yes. We use Heap at my company, I will check out Amplitude. Thanks

  2. 2

    You should be able to do this with JavaScript. I remember I built something like that a few years ago in a previous job and I used JS only.
    I would get what's visible on the screen and it's content to compare to the full document. Then it's easy to calculate the percentage.

    1. 1

      Love this idea. Thanks

  3. 2

    Have you looked at Hotjar?

    1. 1

      Have not. Looking at it now.

      1. 1

        Do let me know how it goes. Am curious.

  4. 2

    Hi josh,

    I am working on an app that does exactly this, more specifically it generates mouse movement and scroll heatmaps to see where users are looking. userTrack is a premium self-hosted analytics platform, so you need to have a server with PHP+MySQL to host it.

    Currently I am working on v3 of usertrack.net which will have a lot more analytics features and a new UI.

    Let me know if you have any specific questions about your use case!

    PS: I am really excited about almost releasing v3, I think it will be something big. 🎉

    1. 1

      Do you have a serverless version? (don't really know what that means, but I am looking at learning that for my backend :)

      1. 2

        To be honest, I don't know either what the serverless hype is supposed to mean. Everything has to run on a server, somewhere. This is not an API, but an entire platform with backend + frontend, so you need to access the frontend somehow, through a web-server. I think serverless usually refers to APIs only.

        If instead of serverless you mean hosted version, no there is no hosted alternative, but setting it up is really easy if you already have a server with PHP+MySQL (eg. any shared hosting platforms with <$5/mo plans work too).

  5. 2

    yeah came here to say pretty much what @peterj1994 said

    one other metric you could work with is time spent on the page. I wouldn't recommend firing off an event every second but maybe you could set thresholds like 5, 15, 30, 60, 120+ seconds, etc.

    1. 1

      Ooh I like that. Never thought about time on page as a way to measure completion. I would love exact numbers, like what section they read to etc, but time on page could work as an estimate.

  6. 2

    You shouldn't need any backend to track scroll position, although you may need one to save it.

    You can simply track the scroll event, and then fire off whatever you want at that point. It's easy enough to get the current offset and then compare that to total height if you want. Or, you could attach metadata (like special ids used only for this purpose) to your content and fire off events as they become visible/invisible.

    At this point you can save that data however you want. Querying some sort of backend and sticking it into a DB is probably easiest. You may be able to get this into GA with some sort of custom event, but I'm not an expert here so that's just a guess.

    1. 1

      great ideas. Thanks!

  7. 1

    When I was working for an employer we used an on-premise version of Piwik to gather user behavior, and it included metrics for impressions and interactions. So when something scrolled into view it recorded an impression, and when they tapped/clicked on something it recorded an interaction. All we had to do was add a data-track-content attribute to the HTML elements we wanted impression metrics for, and configure the client Javascript library to send them to the server. See https://matomo.org/docs/content-tracking/#tracking-content info.

    If you marked each section (or marked subsections within each section) with data-track-content you would know how much the user saw.

    There was also a feature where you as the Piwik account owner could bring up your own web page and see how many impressions/interactions there were for each section directly in your web page, so no need to do any analysis/visualization to figure out what's being viewed and what isn't.

    Piwik was renamed to Matomo a couple years ago, and now I think they have a SaaS version so you wouldn't have to host it (although it looks like they still have an on-premise version if you need that).

    1. 2

      19 bucks a month looks like. https://matomo.org/pricing/ Thanks that is a good option!

  8. 2

    This comment was deleted 5 years ago.

    1. 1

      This is great! Was looking at plugins or coding it myself.

      1. 2

        This comment was deleted 5 years ago.

        1. 1

          I am going to try setting it up today.

  9. 2

    This comment was deleted 5 years ago.

    1. 1

      I like the idea. However, my essay is 4,000 words already, and I want to know where they lose interest etc.

Trending on Indie Hackers
I spent $0 on marketing and got 1,200 website visitors - Here's my exact playbook User Avatar 52 comments Veo 3.1 vs Sora 2: AI Video Generation in 2025 🎬🤖 User Avatar 26 comments I built eSIMKitStore — helping travelers stay online with instant QR-based eSIMs 🌍 User Avatar 20 comments Codenhack Beta — Full Access + Referral User Avatar 20 comments 🚀 Get Your Brand Featured on FaceSeek User Avatar 18 comments Day 6 - Slow days as a solo founder User Avatar 16 comments