1.1.1 • Published 3 years ago

@blablacar/tracktor v1.1.1

Weekly downloads
309
License
MIT
Repository
github
Last release
3 years ago

Tracktor JS Library

https://www.npmjs.com/package/@blablacar/tracktor

Tracktor is a user behavior tracking solution. Through the usage of events, it is sending the user actions, after which the events are computed and integrated into the BlaBlaCar datawarehouse.

Tracktor JS Library is basically a queue in charge of collecting and periodically pushing standardized events into Tracktor.

Creating an event

Send an email to data-track@blablacar.com to request the implementation of a new event.

Event composition

FieldTypeDescription
nameStringName of the event
versionNumberVersion of the event
payloadObjectPayload defined in the event whitelist

Event schema proposal template

{
  "name": { "enum": ["EVENT_NAME"] },
  "version": { "enum": ["EVENT_NUMBER (number)"] },
  "payload": {
    "properties": {
      "FIELD_1": { "type": "string" },
      "FIELD_2": { "type": "number" },
      ...
    },
    "required": ["FIELD_1"]
  }
}

Event Testing

Here are the process to test the validity of your library implementation, and the reception in the expected format of your events:

  • TODO Use the test event (ongoing)
  • TODO Use the preprod kibana to track your test event (ongoing)

How to use?

If you are using Tracktor on a new domain, send an email to data-track@blablacar.com in order to ensure the backend whitelisting. Please, also agree with an app name.

Documentation

Environment

The library is functional both client side and server side, so it works fine with isomorphism apps.

Event Buffer

The library is using an internal event buffer to push the events. You can create several TracktorJS instances, they will all use the same Event Buffer (particularly interesting server side, the event buffer is not request based).

You will need to configure the event buffer, at least to provide the backend URL:

FieldTypeDescriptionDefault
sendUrlStringBackend url where the events will land
appNameStringName of your application to easily filter the logs
emit_frequencyNumberDelay to flush the event queue when there is at least one event pushed2000
event_max_countNumberMaximum number of events able to be pushed at once20
event_max_sizeNumberMaximum event size able to be pushed (single event)2500
request_max_sizeNumberMaximum events size able to be pushed (several events)10000
retries_frequencyNumberNumber max of retry when the event buffer flush is failing5
onSendFailureFunctionCallback on request failfunction(){}

All of these values can be overriden for every instance created by Tracktor once by doing:

import TracktorJS from '@blablacar/tracktor'

const config = {
  appName: 'app-web',
  sendUrl: 'http://domain.com',
  onSendFailure: error => {
    console.log(error)
  },
}
TracktorJS.initializeEventBuffer(config)

Create an instance

import TracktorJS from '@blablacar/tracktor'
const userConfig = {
  userAgent:
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
  hostname: 'www.hostmame.com',
}
const storage = {
  get: getCookie,
  set: setCookie,
}
new TracktorJS(userConfig, storage)

We explained earlier, Tracktor is a user behavior tracking solution, so the constructor includes two required parameters:

UserConfig

userConfig fieldsTypeRequiredGenerated if not provided
userAgentStringtruefalse
hostnameStringtruefalse
localeStringfalsefalse
userIdStringfalsefalse
ipStringfalsefalse
deviceIdStringfalsetrue
sessionStampNumberfalsetrue
visitorIdStringfalsetrue
deviceBrandStringfalsedefaults to 'UNKNOWN'
deviceModalStringfalsedefaults to 'UNKNOWN'
osNameStringfalsedefaults to 'UNKNOWN'
osVersionStringfalsedefaults to 'UNKNOWN'

Storage

The storage is essential for Tracktor, for the deviceId, sessionStamp and visitorId. These values need to be persistent, and regarding your app, you might like to store it in a very different way (cookies for node, local storage for browser etc.).

storage fieldsSignatureRequiredDescription
get(key) => numberstringtrueRetrieve the value from your storage
set(key, value, options) => voidtrueSet the value in your storage

Example:

Cookie (Node JS, Express)

const storage = {
  get: name => req.cookies[name],
  set: (...args) => res.cookie(...args),
}

Cookie (JS)

import Cookies from 'js-cookie'

const storage = {
  get: Cookies.get,
  set: Cookies.set,
}

Local Storage (JS)

const storage = {
  get: (...args) => localStorage.getItem(...args),
  set: (...args) => localStorage.setItem(...args),
}

Send an event

const EVENT_NAME = {
  name: 'event_name', // whitelisted event name
  version: 1, // whitelisted version
}
const payload = {
  route: '/', // whitelisted payload
}
Tracktor.push(EVENT_NAME, payload)

Flush the queue

Tracktor.flush()

Retrieve the User config

Since some internal values can be generated, the full userConfig is not always known by the user of the library.

Tracktor.userConfig
1.1.1

3 years ago

1.1.0

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.4

5 years ago

1.0.0-beta.3

5 years ago

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

0.3.2

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago