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

marketing.js

v0.0.6

Published

A flexible marketingchannel recognition and attribution library for the browser

Downloads

6

Readme

marketing.js

Build Status npm version

A highly flexible marketingchannel recognition and attribution library. Records a visitor's touchpoints, provides access to the touchpoint history and offers attribution models to operate on the recorded data.

Usage

Installation

Install the library from npm as usual. It has no external dependencies and should work in all modern browsers.

npm install marketing.js

Load the library in your preferred style, this example uses ES6 imports as they meanwhile tend to be the new de-facto standard. Since the engine alone is pretty useless we load the engine, an attribution model, and some channel handlers in our example.

import {
  AttributionEngine,
  LastTouchAttributionModel,
  SearchEngineChannel,
  URLMatchingChannel,
} from 'marketing.js';

After that, create a simple AttributionModel instance. This is used to decide which channel(s) will get attributed to what amount. For our testcase we use the pretty common "Last Touch Model", which attributes the last touchpoint within a conversion journey.

const model = new LastTouchAttributionModel();

Configuration

Create the engine and pass the model and the marketing channel configuration. The channel configuration - when seen from a technical perspective - is quite simple and straightforward. It simply defines a set of rules that are executed sequentially to match against certain environment criteria. Nevertheless the entire business logic around marketing channels and attribution handling can be quite complex and requires a bit of background knowledge.

const engine = new AttributionEngine(model, [
  new SearchEngineChannel('seo', 'SEO'),
  new URLMatchingChannel('sea', 'SEA (Adwords)', 'adword', 'adword'),
]);

Execution

Now everything is set up to get the touchpoint for the current page impression by calling the engine's execute method. This looks at URL, query string and referrer (depending on the types of channels in the configuration) and performs the channel recognition. It also adds the recognized Touchpoint to the internal list with the touchpoint history.

const currentTouchpoint = engine.execute();
console.log(currentTouchpoint.getChannel().getId());

Finally, we can query the attributed Touchpoint(s) for the visitor, based on our chosen LastTouchAttributionModel (looks at the single winning channel within the last 30 days). Note that this method returns an array of AttributionItem objects because we need to provide a Touchpoint and its associated weight on the attribution. Also we need an array here, as some attribution models may attribute multiple channels (e.g. "linear" or "time decay" models).

const attributionItems = engine.getAttributionItems();
if (attributionItems.length > 0) {
  console.log(attributionItems[0].getTouchpoint().getChannel().getLabel())
}

The above code is just a convenience handler to allow calling AttributionModel.execute without explictly accessing the model. We could also directly call the execute method on the model and pass the engine's touchpoint history instead:

const attributionItems = model.execute(engine.getTouchpointHistory());

API

Coming soon, check the code for inline JSDOC comments until then ...