node package manager


Url referrer and campaign parsing utilities


inbound is a referrer parsing library for node.js / express web apps.

npm install inbound
var inbound = require('inbound');
inbound.referrer.parse(url, referrer, function (err, description) {

url (string) is the page url, equivalent to client-side javascript's window.location.href or express.js req.url

referrer (string) is the referrer, equivalent to client-side javascript's document.referrer or express.js req.header('referrer')

var inbound = require('inbound'),
    express = require('express');
var app = express();
app.use(function (req, res, next) {
  var referrer = req.header('referrer');
  var href = req.url;
  inbound.referrer.parse(href, referrer, function (err, desc) {
    req.referrer = desc;
app.get('/', function (req, res, next) {
  return res.send(req.referrer);
var port = 8000;
console.log('Server listening on port : ' + port);

Here is an example of a visitor clicking a twitter link and ending up at a New Yorker article.

var url = "
var referrer = "";
inbound.referrer.parse(url, referrer, function (err, description) {
  "referrer": {
    "type": "social",
    "network": "twitter"

Here's an example of a visitor clicking a campaign email from gmail, and arriving at a blog:

var url = "";
var referrer =  ",t/rt=h/ver=am293eyFlXI.en./sv=1/am=!v8Czf-oeNMn1FOzaNKsLQrJy-oNN3RSSYMAZTBUxCzwgQcXtLnTEHCkGr437GpFE2Dliuw/d=1";
inbound.referrer.parse(url, referrer, function (err, description) {
  "referrer": {
     "type": "email",
     "client": "gmail",
     "from": ",t/rt=h/ver=am293eyFlXI.en./sv=1/am=!v8Czf-oeNMn1FOzaNKsLQrJy-oNN3RSSYMAZTBUxCzwgQcXtLnTEHCkGr437GpFE2Dliuw/d=1",
     "link": ""
  "campaign": {
    "source": "feedburner",
    "medium": "feed",
    "campaign": "Feed: contrast/blog (The Intercom Blog)"

Internal referrers occur when a visitor navigates between two pages of the same domain. Example: =>

If there is a referrer present but it's unrecognized above, we'll just call it a link referrer.

When a visitor navigates to a site by typing in the url into the address bar, document.referrer is blank. This is called a direct referral. (There are some other reasons this can happen as well.)

If you want to count the number of people who came from a specific referrer, you might want to make the following map:

referrer => { set_of_visitors }

However, referrers and urls tend to have differences that don't really matter to you, but are slightly different.

Use the inbound.shorten API to make the referrers and domains unique.

// "" 
// " 

Matchers help identify and attach more semantic information to referral sources. We'd your help on adding the hundreds of social, search, ad, and other referral sources not matched yet by inbound.

To add matchers:

  1. Using existing matchers as an example, create your matcher at /lib/matchers/.
  2. Add your matcher to the priority list of matchers in index.js.
  3. Add your test cases to the test cases file.
  4. Run and confirm that your test cases pass: npm test
  5. Add your matcher to the readme.
  6. Submit your pull request!
  1. The visitor came directly to your site by typing the link into the browser's bar.
  2. The visitor clicked a link on an https:// page and arrived at a http:// page, such as clicking a link to on a email. (Chrome will strip the referrer since you're downgrading security).
  3. You were 301 redirected via a proxy that didn't maintain the referrer header.

Even though most matchers do synchronous string matching, leaving the API asynchronous allows matchers that fill in more semantic information about the referrer by hitting some sort of API.

 W W W||W W W
    ( OO )__________
     /  |           \
    /o o|    MIT     \
    \___/||_||__||_|| *
         || ||  || ||
        _||_|| _||_||