npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

screentime

v1.0.0

Published

Screentime ==========

Downloads

11

Readme

Screentime

Screentime is a small tool that helps you start thinking of your website traffic in terms of time instead of hits (Pageviews, visits, etc). You can define areas of the page, called Fields, and then Screentime will keep track of how much time each Field is on screen for. You can also use it to track smaller elements, like ad units.

Screentime only handles the client side work. You'll need to provide your own backend to post the data to. I've included an example that shows how to this with Keen IO using only a few lines of code. There's also a built-in option for posting to Google Analytics but there are some caveats (see below).

View the Project Page

How it works

You specify some DOM elements that you want to track and then every second Screentime checks the viewport to see which ones are in view. It tracks the viewable seconds for each element/field and then issues a report every 10 seconds (you can adjust the interval). The report is passed to a callback function that you can use to post the data to your server.

If the user switches tabs, the timer stops (using Addy Osmani's Page Visibility polyfill). The timer doesn't require that the user be active, just that the screen elements are visible.

Usage

jQuery is required. Pass in selectors for each unique element you want to track, including a name for each. The callback option receives an object containing the data.

$.screentime({
  fields: [
    { selector: '#top',
      name: 'Top'
    },
    { selector: '#middle',
      name: 'Middle'
    },
    { selector: '#bottom',
      name: 'Bottom'
    }
  ],
  callback: function(data) {
    console.log(data);
    // Example { Top: 5, Middle: 3 }
  }
});

Options

fields array (required)

An array of object listing the DOM elements you want to track. Each object should specify a selector property and a name property.

reportInterval number

The interval, in seconds, used to issue a report. The default is 10 seconds.

percentOnScreen string

This determines what percentage of the field must be on screen for it to be considered in view. The default is 50%. One exception to this rule: if a field occupies the majority of the viewport it will be considered in view regardless of its viewable percentage.

googleAnalytics boolean

Setting this to true (default is false) will send a Google Analytics event for each field (if the field has data to report) when the report is issued.

callback function

The callback function that receives the screentime data.

Methods

reset

Calling $.screentime.reset() will reset the counter. This is useful for Single Page Applications where the page context is reloaded client side.

Posting the data

The built-in Google Analytics option is an easy way to quickly start collecting screentime data, but it's not exactly scalable. For each field that has data to report, a separate GA Event has to be sent. If you're only tracking 2 or 3 fields, this is probably fine. But anything more than that and you might start hitting the GA collection limit.

For scalabla data collection you'll want to provide your own backend or use a service like Keen IO. In the examples folder there's a demo showing how easy it is to use Keen for this. It's as simple as this:

...
callback: function(data) {
  Keen.addEvent("screentime", data);        
}
...