Code Monkey home page Code Monkey logo

analytics's Introduction

Digital Optimization Group - Javascript Analytics

https://docs.digitaloptgroup.com/analytics/getting-started

This library is made to work with Digital Optimization Group's Headless A/B testing CMS. It provides a range of event tracking automatically, plus it provides a public api to allow custom event tracking.

At 15kb gzipped it's lighter than Google Analytics.

What's tracked by this library?

  • a/b test variations actually appearing in a user's viewport (not just assignment)
  • time a variation is in a user's viewport
  • time on site and time on page
  • visibility of the page (is tab visible?)
  • mouse distance
  • total scrolling distance by page
  • scroll depth per page
  • errors
  • arbitrary outcomes set up by the user of this library
  • page views
  • orientation changes (mobile devices)
  • mousedown activity on a variation

All events are placed on a timeline so that outcomes can be properly attributed to variations actually appearing in the viewport. For example, we shouldn't attribute an order that occured before a variation was in the viewport to that variation when running an a/b test.

Usage

npm

npm install --save @digitaloptgroup/analytics

yarn

yarn add @digitaloptgroup/analytics

Initialze

import { initTracker } from "@digitaloptgroup/js-analytics";

const config = {
  apiKey: "your-api-key",
  projectId: "your-project-id",

  // optional advanced configuration
  // see advanced further down this README
  vid: "visitor_id",
  rid: "request_id",
  startTimestamp: "proxy_startTimestamp"
};

const {
  pathChange,
  outcome,
  caughtError,
  getIntersectionObserver
} = initTracker(config);

Track Pageviews

const pathname = "/about-us";
pathChange(pathname);

Track Outcomes

Tracking events with outcome is intended as a means to track any custom user actions that you would like to associate with your a/b test variations.

outcome takes two arguments outcomeName and metadata. The name must be a string. The metadata must be an array containing an arbitrary number of objects with the type signature { key: string, value: string }.

const outcomeName = "addToCart";
const metadata = [
  { key: "sku", value: "product_123" },
  { key: "price", value: "125.99" }
];
outcome(outcomeName, metadata);

Caught Errors

If you would like to report a caught error you may do so with caughtError.

const metadata = [
  { key: "type", value: "auth_failed" },
  { key: "url", value: "/login" }
];
caughtError(metadata);

Observe / Unobserve Variation

initIntersectionObserver provides viewport tracking for a/b test variations. It is intended to be used with Digital Optimization Group's Headless CMS.

Automatically Tracked Events

In addition to the events listed above, this library automatically tracks the following events:

Euclidian Mouse Distance

The library will sample mouse position every 250ms and calculate the euclidean distance from prior x and y coordinates. It will report the total every 3 seconds.

Page Scrolling

The depth and distance of scrolling activity will be reported in 3 second windows.

Orientation Change

Orientation change will be reported for mobile devices.

Rapid Clicking (or Rage Clicking)

If multiple clicks are recorded within a very small pixel range the number of clicks and the underlying innerHTML will be reported.

Time on Page

Time on page events will be emitted in a decreasing interval.

Time on Site

Time on site events will be emitted in a decreasing interval.

Mousedown on variation

Mousedown events occuring on a tracked variation will be reported.

analytics's People

Contributors

shalomvolchok avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mysticaltech

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.