• This repository has been archived on 19/Sep/2018
  • Stars
    star
    493
  • Rank 89,306 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Turn web user activity into a analyzable stream of JSON event data

CommonWeb


Deprecation Notice

CommonWeb is deprecated, instead use the Keen Tracking.js library https://github.com/keen/keen-tracking.js


CommonWeb is an open source JavaScript library that transforms common web user activity into a stream of event data you can listen to and analyze. CommonWeb listens for:

  • Pageviews
  • Clicks
  • Form Submissions
  • More...

And emits a JSON representation of each, loaded with useful properties.

The data emitted by CommonWeb can be used to compute traditional web metrics like:

  • Visits and Visitors
  • Time on Site
  • Bounce Rate
  • Content Ranking
  • …and more

CommonWeb supports integrations with services like Keen IO that provide tools for analyzing and reporting on streams of event data.

Philosophy

CommonWeb is more of a collection tool than an analysis tool. The philosophy behind CommonWeb is that data collection is hard, but 80% of what needs to be collected is common to everybody, and auto-collecting the 80% can enable a lot of basic reporting.

The analysis of the data, on the other hand, varies widely based on what you're trying to learn about your users and how your product or web site works. For example, exactly how you define a cohort might be very different than the company next door.

CommonWeb:

  • Automatically collects the 80% of interesting web events and properties
  • Lets you customize or add new events and properties (the 20% specific to you)
  • Send data to configurable back-ends or fire JavaScript callbacks

CommonWeb's job is to capture web analytics data in a consistent but configurable fashion. Consistency has its advantages. For example, reporting tools built with commmon-web in mind can be useful to anyone!

Already a Keen IO user?

Hooray! <3 <3 CommonWeb can help level up your web analytics game. It might allow you to pare down old tracking code, or just learn something new about your users.

CommonWeb is not a replacement for keen-js. Rather, it sits on top of it, while providing a data model and higher level abstractions than addEvent.

Installation

Download common-web.min.js from this repository into your project and include it on your pages.

<script type="text/javascript" src="/javascripts/common-web.min.js"></script>

Make sure to change /javascripts/common-web.min.js if that's not where the file is in your project.

Dependencies
  • jQuery – Required. Someday this may change, but for now jQuery is required.
  • Keen IO JS SDK v3 - Required if you're using Keen as a backend for the JSON data captured.

Include dependencies before including common-web.min.js itself. For example, here's how you'd include both jQuery and Keen IO:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/keen-js@3"></script>
<script type="text/javascript" src="common-web.min.js"></script>

If you're using the Keen IO backend, you'll need to tell CommonWeb about the Keen.Client instance you'd like it to use to record events and tell it to use the CommonWeb.Keen callback:

CommonWeb.Keen.Client = new Keen({
  projectId: "your_project_id",
  writeKey: "your_write_key"
});
CommonWeb.addGlobalProperties(CommonWeb.Keen.globalProperties);
CommonWeb.Callback = CommonWeb.Keen.Callback;

Usage

After all of the required JavaScript has been loaded, you can begin making calls to the CommonWeb object.

The CommonWeb API contains several trackXXX methods that initialize tracking for pageviews or events on specific HTML elements. Here's an example of each:

// add a user-specific GUID to all events for tracking user flow
CommonWeb.trackSession();

// track the pageview
CommonWeb.trackPageview();

// track clicks for each link on the page
CommonWeb.trackClicks();

// track submissions for every form on the page
CommonWeb.trackFormSubmissions();

// track changes to every input on the page
CommonWeb.trackInputChanges();

// track clicks for non-link tags on the page, requires argument
CommonWeb.trackClicksPassive($("span"));

Blocking vs. Non-Blocking

Most links (<a> tags) unload pages when they are clicked because the user is being taken to a new page. Same with traditional, non-ajax form submissions. If the page unloads before a call to record the event is finished the event may not be recorded. This is a common issue in web analytics that often goes unnoticed to the detriment of accurate data.

CommonWeb's solution is to have you specify explicitly when to work around this scenario; i.e. to tell CommonWeb what links / forms are going to unload the page. In that case CommonWeb will prevent the default browser action, record the event with the backend, and then re-initiate the action.

The methods that alter default behavior. Here they are:

  • trackClicks
  • trackFormSubmissions

These methods are more passive, and don't interrupt any normal event flow:

  • trackClicksPassive
  • trackInputChanges
  • trackFormSubmissionsPassive (coming soon)

Specify HTML Elements (Recommended)

If you only want certain elements tracked, pass them in as the first argument to the track methods:

// track clicks on the nav
CommonWeb.trackClicks($(".nav a"));

// track clicks with a specific attribute
CommonWeb.trackClicks($("a[data-track=true]"));

// track changes to number inputs
CommonWeb.trackInputChanges($("input[type='number']"));

The same arguments work for tracking non-link-clicks and forms:

CommonWeb.trackClicksPassive($("span.less"));
CommonWeb.trackFormSubmissions($("form"));
Words of Caution

CommonWeb is designed to make tracking automatic, but the design is also aware that tracking certain elements may not be desired, or worse, may cause unexpected behavior.

That's why, at least for now, explicitly passing the elements you care about is preferred over grabbing everything.

And be careful not to wire up the same element twice!

Specify Additional Properties

The default data model used to represent events is described in another section below. Sometimes you may need to include more properties. For example, maybe you need to include extra user properties that allow for further segmenting analysis down the road.

This can be done at a global level or for specific elements passed into track calls.

Here's how to add global properties that will be merged into each captured event on the page:

CommonWeb.addGlobalProperties({
  experiment: {
    id: 13983,
    variant: "A"
  }
});

Here's how to specific properties that will only be added to a specific element's click:

CommonWeb.trackClicks($("span.less"), { another: "property" });

You can also pass a function to compute properties lazily at the time of the event:

CommonWeb.trackClicksPassive($("span.even-more-stuff"), function (event, element) {
    return {
        event: { clientX : event.clientX },
        element: { tagNameAgain : element.tagName  }
    };
});

Custom Backend

Eventually multiple backends will be supported, but for now a Backend is just a function and you can specify your own just like this:

CommonWeb.Callback = function(collection, properties, callback) {
  // do something with the event here!
};

Data Model - Event Types

CommonWeb identifies several event types based on the interaction

  • pageviews, clicks, form-submissions. The event type is added to the JSON payload that represents each event so it can be used in analysis.

Data Model - Event Properties

Global

These properties are sent with every event by default:

  • page_url - The window.location.href of the current page
  • referrer_url - The document.referrer of the current page
Events and Elements

JavaScript event and HTML element objects are turned into JSON structures and places at the event and element top level keys respectively.

Session Tracking

You can have CommonWeb generate a user-specific GUID that will be sent along with all of your CommonWeb events. This GUID will be stored in the user's cookies (and persist for one year), so you can relate future events to the same user. Turn on session tracking like this:

CommonWeb.trackSession();

trackSession will also accept two arguments: the first is the name of the cookie to use. The second is the GUID to use, if there isn't already one stored. Pass them in like this:

CommonWeb.trackSession('custom_guid_cookie', 'semi-random-user-identifier');
Keen Backend

More documentation needed here

Here's an example clicks event that shows what properties are collected:

[
  {
    "parsed_user_agent": {
      "device": {
        "family": "Other"
      },
      "os": {
        "major": "10",
        "patch_minor": null,
        "minor": "9",
        "family": "Mac OS X",
        "patch": "3"
      },
      "browser": {
        "major": "36",
        "minor": "0",
        "family": "Chrome",
        "patch": "1985"
      }
    },
    "referrer_info": {
      "medium" : "SEARCH",
      "source" : "http://google.com/",
      "term" : "analytics"
    },
    "parsed_page_url": {
      "path": "/docs/data-collection",
      "domain": "keen.io",
      "protocol": "https",
      "anchor": null,
      "query_string": {
        "page": "1",
        "term": "analytics"
      }
    },
    "element": {
      "style": "color: blue",
      "text": "Data Enrichment",
      "id": "link-0",
      "href": "/docs",
      "tagName": "A",
      "path": "html > body > p > a#link-0.classy.classy2.classy3",
      "classes": [
        "classy",
        "classy2",
        "classy3"
      ],
      "class": "classy classy2 classy3"
    },
    "keen": {
      "timestamp": "2014-08-12T09:19:28.605Z",
      "created_at": "2014-08-12T09:19:28.605Z",
      "id": "53e9dc20c9e163024bc2c799"
    },
    "referrer_url": "",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36",
    "ip_geo_info": {
      "province": "California",
      "city": "San Francisco",
      "postal_code": "94103",
      "continent": "North America",
      "country": "United States"
    },
    "ip_address": "199.247.206.130",
    "event": {
      "metaKey": false,
      "type": "click"
    },
    "page_url": "https://keen.io/docs/data-collection",
    "guid": "e54029e7-6a54-b39f-c592-022686afb9c9"
  }
]

Further Documentation and Examples

Example Page w/ Keen IO Backend

Open index.html after cloning this project and head to the console. It will prompt you first to fill out Keen IO project information so that there's somewhere to capture your events. The annoying pop-ups will go away once you've put that in. It's there so that you don't have to hand edit the file and then accidentally end up checking your credentials in.

The example page shows you a variety of elements. You can click on each and see the event generated by viewing the JavaScript console.

Contributing

Setup

CommonWeb uses Gulp for building, so you will need to have Node.js installed. You can get up and running with the standard npm flow:

npm install

If you don't already have Gulp installed, you will need to install that globally.

npm install --global gulp

Building

You can build by calling the build Gulp task.

gulp build

You can also setup automatica rebuilds whenever a file changes by starting a watch. This can either be done directly with Gulp, or with the npm hook.

gulp

# or

npm start
Wishlist
  • Tests
  • Timeout and continue if a backend takes too long
  • Session ID and session age properties
  • Capture even more common interactions (e.g. time on page)
  • Create dashboards and visualizations based on this data!
  • AJAX Form Handling

License

FOSSA Status

More Repositories

1

dashboards

Responsive dashboard templates πŸ“Šβœ¨
HTML
11,022
star
2

explorer

Data Explorer by Keen - point-and-click interface for analyzing and visualizing event data.
TypeScript
746
star
3

keen-js

https://keen.io/ JavaScript SDKs. Track users and visualise the results. Demo http://keen.github.io/keen-dataviz.js/
580
star
4

pingpong

HTTP monitoring for developers. Richer analytics, greater flexibility.
CSS
334
star
5

keen-tracking.js

A light, fast and flexible javascript tracking library
JavaScript
254
star
6

keen-dataviz.js

Data Visualization Charting Library
JavaScript
222
star
7

cohorts

Cohort Builder by Keen IO
111
star
8

keen-cli

A command line interface for Keen IO
Ruby
53
star
9

data-modeling-guide

Data Modeling Guide
53
star
10

github-analytics

GitHub Analytics with Keen IO
JavaScript
43
star
11

keen-analysis.js

A light JavaScript client for Keen
JavaScript
39
star
12

dashboards-dot-community

This is a collaborative project to help community managers be better at recording the impact of their activities and communicating the results.
27
star
13

keen-botkit

Analytics for Botkit by Keen IO
JavaScript
26
star
14

radialflows

Radial flow (sunburst) data visualization
Ruby
26
star
15

keen-arduino

A SDK to send events to Keen IO from an Arduino Yun
C++
15
star
16

open-data-collectors

A set of Pushpop jobs that collect data for anyone to use
Ruby
15
star
17

dashboard-builder

An easy to use JavaScript dashboard builder for event tracking
JavaScript
15
star
18

community-team

a little bit about us
14
star
19

dashboard-starter-sinatra

Sinatra template app for creating a Keen IO dashboard
JavaScript
13
star
20

community-code-of-conduct

Keen IO Community Code of Conduct
13
star
21

keen-css

Keen IO CSS Framework
CSS
13
star
22

keen

Mono-repository for Front-End projects
TypeScript
12
star
23

keen-gem-example

A Sinatra app that uses the keen gem to publish events asynchronously
Ruby
10
star
24

slate_algolia

Easily index your Slate-powered docs in Algolia
Ruby
10
star
25

dashboard-creator

TypeScript
8
star
26

keen.github.io

A collection of tools for building on Keen
CSS
7
star
27

keen-react-charts

A React Component for Keen-Dataviz.js
JavaScript
6
star
28

ecommerce-analytics-guide

Keen IO E-Commerce Analytics Guide
HTML
6
star
29

learn

Event Data Class by Keen IO
JavaScript
6
star
30

theme-builder

A custom CSS theme builder for Keen-Dataviz.js
JavaScript
5
star
31

community_ideas

A hub for tracking all of the things we want to build for the community
5
star
32

keen-cc3200

An SDK to send events to Keen IO from a Ti cc3200 board.
C
5
star
33

discoveries-demo

JavaScript
4
star
34

net-keenio-perl

A Perl library for the Keen IO analytics API (under construction)
Perl
4
star
35

keen-play-error-reporter

Sentry exception reporter for play-based apps.
Scala
4
star
36

keen-core.js

Core functionality powering keen-tracking.js and keen-analysis.js; not intended for direct use.
JavaScript
3
star
37

devise_keen

Track user events in the devise gem with Keen IO.
Ruby
3
star
38

discovery-manager.js

JavaScript
3
star
39

amp

Keen-AMP integration
HTML
3
star
40

keen-dataviz-webpack-boilerplate

JavaScript
2
star
41

analytics-in-sixty-seconds

Fastest client.draw in the West
HTML
2
star
42

comapp

JavaScript
1
star
43

react-dashboards

JavaScript
1
star
44

keen-tracking-adwords-example

JavaScript
1
star
45

keen-dataviz-maps

1
star
46

keen-ez-etl

A tiny script for exporting events from one project, modifying them, and loading them into another
Ruby
1
star