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

markovattribution

v0.0.5

Published

Allows attribution to sources based on markov distribution.

Downloads

4

Readme

Markov Chain Channel Attribution

This library is based off of Sergey Bryl's fantastic article on Markov chain attribution. Tests included in the library are based off the results found in that tutorial. The object of this library is to use markov chain math to find the removal effect of individual channels in customer journey paths. This is a data-driven equivalent to heuristic attribution methods such as "first touch" and "last touch".

Instantiation

To use the object, create an instance:

const Markov = require('markovattribution')

var markov = new Markov(config)

Data array

The object should be primed with an array of objects in the following format:

{conversions:1, value:1000.00, path:'C1 > C2 > C3'}

For example:

const Markov = require('markovattribution')

const data = [
  {conversions:1, value:1000.00, path:'C1 > C2 > C3'},
  {conversions:0, value:0, path:'C1'},
  {conversions:0, value:0, path:'C2 > C3'},
]

var markov = new Markov(config)

Configuration

The object can be passed a configuration object in the following format:

const Markov = require('markovattribution')

const data = [
  {conversions:1, value:1000.00, path:'C1 > C2 > C3'},
  {conversions:0, value:0, path:'C1'},
  {conversions:0, value:0, path:'C2 > C3'},
]
const config = {
  devMsg: true,    // if true, reports info to the console
  separator: ' > ' // string used to separate channel entries in the conversion data
}

var markov = new Markov(config)

Instance methods

The instance of the object exposes the following methods:

channels(conversions)

Returns the transient channels in data in an array. Example:

const Markov = require('markovattribution')

const data = [
  {conversions:1, value:1000.00, path:'C1 > C2 > C3'},
  {conversions:0, value:0, path:'C1'},
  {conversions:0, value:0, path:'C2 > C3'},
]
const config = {
  devMsg: true,    // if true, reports info to the console
  separator: ' > ' // string used to separate channel entries in the conversion data
}

var markov = new Markov(config)

console.log(markov.channels(data))

returns:

> ['C1','C2','C3']

prob(matrix)

Returns the probability of the graph to reach the conversion state when starting from the "start" state. Example:

const Markov = require('markovattribution')

const data = [
  {conversions:1, value:1000.00, path:'C1 > C2 > C3'},
  {conversions:0, value:0, path:'C1'},
  {conversions:0, value:0, path:'C2 > C3'},
]
const config = {
  devMsg: true,    // if true, reports info to the console
  separator: ' > ' // string used to separate channel entries in the conversion data
}

var markov = new Markov(config)

console.log(markov.prob(data))

returns:

> 0.3333333333333

removalEffect(conversions, channel, fullprob)

Returns the raw (unweighted) removal effect of channel for the set of conversions data. Example:

const Markov = require('markovattribution')

const data = [
  {conversions:1, value:1000.00, path:'C1 > C2 > C3'},
  {conversions:0, value:0, path:'C1'},
  {conversions:0, value:0, path:'C2 > C3'},
]
const config = {
  devMsg: true,    // if true, reports info to the console
  separator: ' > ' // string used to separate channel entries in the conversion data
}

var markov = new Markov(config)

var fullProbability = markov.prob()

console.log(markov.removalEffect(data, 'C1', fullProbability))

returns:

> 0.5

channelAttribution(conversions)

Returns an object containing channel attribution information about each of the channels in the conversions dataset. Object returned is in the following format:

{
  <channel1name>: {
    conversions: <weighted conversions>,
    removal: <raw removal effect>,
    value: <weighted value>,
    weighted: <weighted removal effect>,
  },
  ...
  <channelNname> :{...}
}

Example:

const Markov = require('markovattribution')

const data = [
  {conversions:1, value:1000.00, path:'C1 > C2 > C3'},
  {conversions:0, value:0, path:'C1'},
  {conversions:0, value:0, path:'C2 > C3'},
]
const config = {
  devMsg: true,    // if true, reports info to the console
  separator: ' > ' // string used to separate channel entries in the conversion data
}

var markov = new Markov(config)

console.log(markov.channelAttribution(data))

returns:

> {
    C1: {
      conversions: 0.2,
      removal: 0.5,
      value: 200,
      weighted: 0.2,
    },
    C2: {
      conversions: 0.4,
      removal: 1,
      value: 400,
      weighted: 0.4,
    },
    C3: {
      conversions: 0.4,
      removal: 1,
      value: 400,
      weighted: 0.4,
    }
  }