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

carebot-tracker

v0.8.0

Published

Track if an element is visible on the page

Downloads

2

Readme

Carebot Tracker

Build Status

A tool for tracking analytics that matter.

Using the Tracker

Visibility Tracker

The Visibility Tracker records how long an element has been on screen. After including carebot-tracker.js on a page, here's how you initailize the tracker:

var tracker = new CarebotTracker.VisibilityTracker('element-id', function(bucket) {
  console.log("The user has seen the graphic for " + bucket);
});

ScrollTracker

The ScrollTracker measures how much of a given element has been "read" (passed the bottom of the screen). As you scroll down, it'll record every 10% of an an element you read, as well as how long you've spent on the page so far.

If you scroll down, then up, then down again, it'll re-record those percentages with the new time you hit them.

Here's an example of how to add the tracker:

var tracker = new CarebotTracker.ScrollTracker('element-id', function(percent, seconds) {
  pymParent.sendMessage('scroll-depth', {
    percent: percent,  // Percents as a number: "10", "120"
    seconds: seconds
  });
});

How to send the data to Google Analytics

Every analytics platform and implementation is slightly different. Here's an example of how we send the data to GA:

<script type="text/javascript" src="carebot-tracker.min.js"></script>
<script type="text/javascript">
var tracker = new CarebotTracker.ScrollTracker('element-id', function(percent, seconds) {
  var eventData = {
    'hitType': 'event',
    'eventCategory': 'your-page-slug-here', // something to identify the story later
    'eventAction': 'scroll-depth',
    'eventLabel': result,
    'eventValue': seconds
  };
  ga('send', eventData); // Assumes GA has already been set up.
});
</script>

Timer

The timer is a utility class that works like a stopwatch.

Time buckets

The timer's special feature is that it returns times in the standard NPR time buckets as strings (in addition to a plain seconds count).

The time buckets are:

  • From zero up to 59 seconds: 10 second intervals (eg 10s, 20s, 30s...)
  • 60 up to 300 seconds: one-minute intervals (eg 1m, 2m...)
  • More than 300 seconds: five-minute intervals (eg 5m, 10m...)

Methods

Constructor
var timer = new CarebotTracker.Timer();

An optional callback will be called on every new bucket:

var timer = new CarebotTracker.Timer(function(result) {
  console.log(result.bucket, result.seconds);
});
start

Starts the timer.

var timer = new CarebotTracker.Timer();
timer.start();
pause

Pauses the timer. Note that this does not zero out the timer value.

var timer = new CarebotTracker.Timer();
timer.start();
timer.pause();
check

Gets the seconds elapsed and current time bucket

var timer = new CarebotTracker.Timer();
timer.start();
// wait 300 seconds
console.log(timer.check());
// prints { bucket: '5m', seconds: 300 }

Example

var timer = new CarebotTracker.Timer();
timer.start();
// wait 300 seconds
timer.pause();

console.log(timer.check());
// prints { bucket: '5m', seconds: 300 }

timer.start();
// wait 60 seconds
timer.check();
// prints { bucket: '5m', seconds: 360 }

Development

Here's what you need to make Carebot Tracker better.

Getting started

You'll need node and npm to get started.

After installing node, you can install the dependencies by running npm install.

Developing

Run grunt watch from the project root to track changes, automatically lint the JS, and build the minimized and source versions that end up in /dist.

Building

Run grunt from the project root to lint the files and package them in /dist.

Testing

Run mocha from the project root to run the test suite.

To manually test while developing, start a simple server from the project root:

python -m SimpleHTTPServer 8000

And then load load http://localhost:8000/test/index.html

This is less than ideal and should be replaced with an automated selenium test rig.