Sometimes there is a need to track certain scroll positions on the page. I had a request recently with the situation needed as follows:

Let's say you have a single page site where you have X top navigation links that jump to different sections on the page (for example, my homepage at The requirement for this scenario says:

1) If a user clicks on the link in the top nav, track that specific link as a page view. Then, scroll to the section on the page.
2) If a user scrolls without clicking, track each section as a page view as they scroll past it.
3) Only track each section page view once regardless of if it was clicked or scrolled.

This can be a little tricky to determine, so I was able to build a plugin that can manage these requirements every time the page is loaded.

The plugin code can be found here:

In order for the above situation to work, a few parts are required.

First, we need the scroll tracking to fire on certain parts of the page. This plugin is built to handle this by giving a list of ids for your sections to track. You also will provide the code to run when that id is viewed on the page.

Second, for the clicking, it requires that you have some jQuery to track each link click. How to set this up will depend on your situation. There is an example provided in the code.

Third, configure any additional options as mentioned in the code comments.

NOTES for using:

  • Please read the inline comments in the code on how to configure this plugin.
  • This code should run in a global scope any time the page loads.


Uses for this plugin

Obviously, analytics can benefit from this plugin. However, other uses might include being able to show a popup if a certain section has been viewed. You could also set a cookie if a certain section is viewed so you could modify future pages if the cookie exists (e.g. specific ads).

My imagination for uses on this plugin are limited -- however if you have any additional thoughts, feel free to comment below!