srb

Collect and analyse performance and popularity data about your websites.

npm install srb
10 downloads in the last day
10 downloads in the last week
24 downloads in the last month

srb

NPM

Build Status Dependency Status devDependency Status

Collect and analyse performance and popularity data about your websites.

[ THIS IS EXPERIMENTAL AND NOWHERE NEAR FINISHED - USE AT YOUR OWN RISK ]

Before you install

Make sure node and npm are installed and in your PATH. Then install phantomjs globally.

$ npm install -g phantomjs

Installation

$ npm install srb --save

API

The module's functionality is split into:

  • srb.collect()
  • srb.analyse()
  • srb.transform()

srb.collect( domainOrURL[, options ] )

The srb.collect() method returns a readable stream that will emit data as tasks are completed.

var srb = require('srb');

// Run all data collection tasks and pipe output to stdout.
srb.collect('foo.com').pipe(process.stdout);

// Collect data and listen on data events as objects.
srb.collect('foo.com', { objectMode: true })
  .on('data', function (data) {
    // `data` is an object with task name and results
  })
  .on('end', function () {
    // All tasks have been run!
  });

// Run only specified data collection tasks.
srb.collect('foo.com', { include: [ 'pages', 'insights' ] });

// Run for URL instead of domain name.
srb.collect('http://foo.com/bar');

Options

The second argument to srb.collect() is an object with options:

var options = {
  // By default `srb.collect()` returns a readable stream that emits data as
  // strings, so that it can be piped to other streams. If you want the data
  // events to emit a JavaScript object instead set `objectMode` to true.
  objectMode: false,
  // List of data collection tasks to exclude.
  exclude: [],
  // If present, only tasks listed in this option are run.
  include: [ 'pages', 'screen', 'insights', 'identity' ],
  // Options specific to the `pages` task.
  pages: {
    max: 5,
    exclude: [ 'login', /^blog/ ],
    include: []
  },
  // Options specific to the `thumb` task.
  thumb: {
    width: 100,
    height: 100
  },
  // Options specific to the `screen` task.
  screen: {
    sizes: [ '320x480', '800x600' ]
  },
  // Options specific to the `identity` task.
  identity: {
    twitter: "YOUR SITE'S OFFICIAL TWITTER USERNAME",
    facebook: "YOUR SITE'S OFFICIAL FACEBOOK PAGE ID",
    google: "YOUR SITE'S OFFICIAL GOOGLE+ PAGE ID"
  },
  // Options specific to the `social` task.
  social: {},
  // Options specific to the `alexa` task.
  alexa: {},
  // Options specific to the `insights` task.
  insights: {
    // The PageSpeed rules to run. If unspecified, all rules for the current
    // strategy are used.
    rules: [
      'AvoidLandingPageRedirects',
      'EnableGzipCompression',
      'LeverageBrowserCaching',
      'MainResourceServerResponseTime',
      'MinifyCss',
      'MinifyHTML',
      'MinifyJavaScript',
      'MinimizeRenderBlockingResources',
      'OptimizeImages',
      'PrioritizeVisibleContent'
    ],
    // Valid values are desktop and mobile.
    strategy: 'desktop',
    // Supported locales here:
    // https://developers.google.com/speed/docs/insights/languages
    locale: 'en_US'
  },
  // Options specific to the `meta-files` task.
  metaFiles: {},
  // Options specific to the `w3c` task.
  w3c: {},
  // Some tasks require credentials to access 3rd party APIs. All of these
  // credentials are optional. If omitted, some tasks will return partial or
  // empty results.
  credentials: {
    // You need to create an application on https://dev.twitter.com/ and create
    // an access token.
    twitter: {
      consumerKey: 'YOUR-CONSUMER-KEY',
      consumerSecret: 'YOUR-CONSUMER-SECRET',
      accessToken: 'YOUR-ACCESS-TOKEN',
      accessTokenSecret: 'YOUR-ACCESS-TOKEN-SECRET'
    },
    // See: https://cloud.google.com/
    google: {
      // After you create your app on Google's Cloud Console the API KEY can be
      //found under the "Server Key" options.
      key: 'YOUR-API-KEY'
    },
    // See: http://aws.amazon.com/awis/
    aws: {
      key: 'YOUR-AWS-KEY',
      secret: 'YOUR-AWS-SECRET'
    }
  }
};

More info about the data collection tasks here.

srb.analyse( [ options ] )

Blah blah blah...

var srb = require('srb');
var options = {
  include: [ 'popularity', 'performance' ]
};
var analyst = srb.analyse(options);

srb.collect('foo.com').pipe(analyst).pipe(process.stdout);

Analyse stored data

var fs = require('fs');
var srb = require('srb');
var analyst = srb.analyse();

fs.createReadStream('./data.json').pipe(analyst).pipe(process.stdout);

Options

  • exclude - List of analysis tasks to exclude. ie: [ 'popularity' ].
  • include - If present, only tasks listed in this option are run.

More info about the analysis tasks here.

srb.transform( [ options ] )

It's a readable/writable stream that data performs a data transformation according to the (RFC6902 - JSON-Patch standard).

JSON-Patch is used as the standard implementation.

var srb = require('srb');

var collectOptions = {
  include: [ 'pages' ],
  pages: {
    max: 3
  }
}

// remove the headers and body properties from the original result
var tranformOptions = {
  task: 'pages',
  patch: [
    {op: 'remove', path: '/0/body'},
    {op: 'remove', path: '/0/headers'},
    {op: 'remove', path: '/1/body'},
    {op: 'remove', path: '/1/headers'},
    {op: 'remove', path: '/2/body'},
    {op: 'remove', path: '/2/headers'}
  ]
};

var collector = srb.collect(collectOptions);
var transformer = srb.transform(transformOptions);

srb.collect('foo.com').pipe(transformer).pipe(process.stdout);

License

The MIT License

npm loves you