0.0.4 • Published 2 years ago

@konso/value-tracking v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Value Tracking

Installation


npm i @konso/value-tracking

Example


import { createValueTrackingClient, LogEvents } from "@konso/value-tracking";

const tracker = createValueTrackingClient({
  apiURL: 'https://devapis.konso.io',
  bucketId: '1fc41560',
  apiKey: 'REa9xeOvk6fRxAcNEyebk+5nC5LnbeCr+bJTBpoLm5E=',
  appName: 'test',
})

tracker.on(LogEvents.onError, (error) => console.log(error));
tracker.on(LogEvents.onSuccessful, (message) => console.log(message));

function trackerMiddleware(client) {
  if (!client) {
    throw new Error('you should provide client for value-tracking')
  }

  return function (req, res, next) {
    client.track(10, { ip: req.ip, browser: req.headers['user-agent']})
    next();
  }
}

const app = express();

app.use(trackerMiddleware(tracker));

createValueTrackingClient

createValueTrackingClient - the function takes a parameters object and returns an instance of the ValueTracking class

const tracker = createValueTrackingClient({
  apiURL: 'https://devapis.konso.io',
  bucketId: '1fc41560',
  apiKey: 'REa9xeOvk6fRxAcNEyebk+5nC5LnbeCr+bJTBpoLm5E=',
  appName: 'test',
})
ParameterTypeRequired
apiKeystringtrue
apiURLstringtrue
bucketIdstringtrue
appNamestringfalse

Methods


track

track(eventId: string, extraOptions: ValueTrackingExtraOptions)

Parameters

ParameterTypeRequiredValue
eventIdstringtrue
extraOptionsObjecttrue{correlationId?: string,value?: string,custom?: string,ip?: string,browser?: string,user?: string,owner?: string}

on

on(eventName: LogEvents, callback: (text: string) => void);

Parameters

ParameterTypeRequiredValue
eventNamestringtrue'onSuccessful', 'onError' or keys of LogEvent object
callbackfunctiontrue(text: string) => void