Giter VIP home page Giter VIP logo

carebot-tracker's Introduction

Carebot Tracker

Build Status

Carebot is an effort in thinking about alternative ways to look at analytics for journalism: both the measures and indicators used to understand story impact, and the way which analytics data is used in the newsroom.

This repository has the trackers you'll put on your website to measure interactions with your articles. You might also want to run the Carebot Slackbot to report data through notifications.

Quickstart

If you are using Google Analytics, here's how to include the carebot tracker and start tracking how much of an article someone has read. Put this code after the Google Analytics code block. You'll need to change element-id to match the CSS ID of the article on your page, and

<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': percent,
    'eventValue': seconds
  };
  ga('send', eventData); // Assumes GA has already been set up.
});
</script>

The trackers

Here are more details on the two trackers available and how to use them:

Time on Screen Tracker

The Visibility Tracker records how long an element is visible on screen. It reports the time in standard buckets:

  • 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...)

Here's how to setup this tracker:

<script type="text/javascript" src="carebot-tracker.min.js"></script>
<script type="text/javascript">
var tracker = new CarebotTracker.VisibilityTracker('element-id', function(bucket) {
  console.log("The user has seen the graphic for " + bucket); // eg "10s", "2m"
});
</script>

Scroll Depth Tracker

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 in seconds.

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

Replace element-id with the ID of the element you want measure scroll depth for. Usually, this is the ID of the main article on the page.

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

<script type="text/javascript" src="carebot-tracker.min.js"></script>
<script type="text/javascript">
var tracker = new CarebotTracker.ScrollTracker('element-id', function(percent, seconds) {
  console.log("The user has gone", percent, "percent down the page after", seconds, "seconds");
});
</script>

How to send the data to Pym

This is a rare edge case (we set it up to meet NPR's specific implementation). If you're using pym_and) your graphic uses a different analytics property than the parent page, you can pass in the bucket values to the pym child using code like this:

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

Timer

The timer is a utility class that works like a stopwatch. You probably won't need to use it directly unless you're building a new tracker.

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.

Alternatives

If you're using jquery on the page, these plugins by Rob Flaherty could simplify your life and can act as replacements for pym:


Contribute to the project

Here are a few ways you can help make Carebot more useful:

  1. Fix bugs in the Carebot tracker and slackbot.
  2. Report new new issues you find.
  3. Contribute new metrics to the Carebot tracker via pull request.
  4. Contribute new notification methods to Carebot via pull request (SMS, Hipchat, etc).
  5. Add to or edit this documentation.
  6. Tell people about Carebot and how more meaningful analytics can help them.

carebot-tracker's People

Contributors

ahilles107 avatar hampelm avatar livlab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

carebot-tracker's Issues

Tracker idea: Feel grid

An idea for a tracker based on active user input (rather than passive)

On an X or X-Y axis, what do you think about this issue after reading the article?

The NYT used to do these for sentiment analysis

Scroll depth phase 2

Turn the scroll depth tracker from something that works through viz to something that can be dropped on any page.

Do we report to the NPR Viz property (easier) or to the NPR general property?

If we use the Viz property, this can be a standalone script that initializes the NPR viz GA property, then tracks and reports

If we use the main property, we need to know if GA is available by the point where we deploy our script. Otherwise, we'll need to wait or load it a second time ourself (not optimal).

In any case, it would probably just report the Seamus ID as the category.

Handle scrollback

We should track when people scroll down, scroll back up, and start scrolling again.

To do this, we'll reset the max bucket if the scroll percent lower than the current max bucket.

We also should track time on page for this to be more useful.

Track time with scroll depth

We can use the timer class for this, and report the amount to GA as the value for the scroll depth bucket label.

Which time buckets are we tracking?

@livlab In last week's review, we decided to get finer-grained time buckets for early on (if I remember right) -- was that reporting one second ("1s" buckets) up to 10 or 20 seconds? Or longer?

How should we handle a user who comes back to a viz?

Scenario:

  • User looks at the viz for a while (the timer records how long they see it)
  • They scroll on (timer stops)
  • They scroll back up to the viz

Does the timer restart from zero seconds, or from the last timepoint?

Track click events & interactions

Do users click on interactives? (even if they aren't clickable)

Probably looking at mousedown and tap events. Need to make sure they still propagate.

Scroll depth reporting proposal

Step 1: NPR Viz only

  1. Report the scroll depth to the pym child
  2. The pym child reports it to the NPR Viz GA with the Seamus ID as the Category (instead of the graphic slug as the category)

Step 2: General solution

Something that can be dropped on any page.

Do we report to the NPR Viz property (easier) or to the NPR general property?

If we use the Viz property, this can be a standalone script that initializes the NPR viz GA property, then tracks and reports

If we use the main property, we need to know if GA is available by the point where we deploy our script. Otherwise, we'll need to wait or load it a second time ourself (not optimal).

In any case, it would probably just report the Seamus ID as the category.

Use pagevisibility to track if something is actually in the open tab

Problem: If a user has the graphic open and visible but it's in a different tab or window, we'll still record that as screen time.

Solution: track if the page is visible using the widely-supported pagevisibility API. Only report data when the page is active. Fall back to tracking everything if it isn't available.

http://caniuse.com/#feat=pagevisibility

http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.