1.2.0 • Published 8 years ago

@financial-times/n-spoor-client v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

n-spoor-client Build Status

Node client to send events to Spoor

npm install -S @financial-times/n-spoor-client

Usage

import SpoorClient from '@financial-times/n-spoor-client';

function expressRoute(req, res) {
  const spoor = new SpoorClient({req});
  spoor.submit({
    category: 'foo-bar',
    action: 'baz',
    context: {
      quux: 'frob'
    }
  }).then(
    () => console.log('event successfully logged'),
    ({payload, status, request}) => console.log(`submission failed, status ${status}`)
  );
}

API

new SpoorClient(options)

Initialize a Spoor client with options:

OptionDescription
sourceString to tell Spoor where the event came from. Required in constructor or submit.
categoryString for Spoor event categorisation. Required in constructor or submit.
reqThe default Express request for all events. You must set either req or both cookies and ua either in constructor or submit.
cookiesOptional explicit Cookie HTTP header. Defaults to req.get('ft-cookie-original').
uaOptional explicit User-Agent HTTP header. Defaults to req.get('user-agent').
productString for Spoor context.product. Defaults to "next".
apiKeyDefaults to process.env.SPOOR_API_KEY
submitIfBoolean. If false, the client will not submit events.
inTestModeBoolean. Sets a context flag to tell Spoor the event is a test event.

client.submit(event)

Send an event to Spoor. Returns a promise which resolves when the event is successfully sent to Spoor, or rejects with a status object when submission fails. The event should be an object with keys:

OptionDescription
sourceString to tell Spoor where the event came from. Required in constructor or submit.
categoryString for Spoor event categorisation. Required in constructor or submit.
reqThe default Express request for all events. You must set either req or both cookies and ua either in constructor or submit.
cookiesOptional explicit Cookie HTTP header. Defaults to req.get('ft-cookie-original').
uaOptional explicit User-Agent HTTP header. Defaults to req.get('user-agent').
actionString name of the event action.
contextObject containing metadata pertaining to the event. Required.
apiKeyDefaults to process.env.SPOOR_API_KEY
productString for Spoor context.product. Defaults to the SpoorClient constructor product value, which in turn defaults to "next".

Originally part of next-signup.

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago