armut-sentinel
v4.0.1
Published
Armut logger tool
Downloads
26
Readme
armut-sentinel
is a JavaScript library for saving mouse events sending it to a custom API for further analysis. You can use armut-sentinel
with any framework you want since it's framework agnostic.
Installation
To install the latest version of the library you can use npm:
npm install armut-sentinel
Getting a build
So there are two build commands in the package.json
.
npm run build
: Use this one if you want to get a quick build without deciding whether unit tests are succeeded or not. Not recommended for publish. However, can be useful for build in development environment.npm run build:safe
: As the name suggests, this one generates a build but first it runs all the unit tests so if any of these tests fail, your build will fail too. This commands is very useful for publishing since it guarentees that there is no problem with the current version.
Let's talk about the build process. First we compile Typescript code into JavaScript(npm run compile
) after removing dist
directory. Then we transpile the compiled JavaScript code using babel into dist
directory.(npm run transpile
). Lastly, we run webpack
for getting a bundle. In dist
directory, two files will be generated: index.bundle.js
minified and bundled version of source code, and index.d.ts
which is a declaration file for our source code to infer types.
Documentation
ArmutSentinel.getExperimentAndVariantId(cookie: Cookie): ExperimentIdType
Gets a special id from the input cookie that is used for Google Analytics.
ArmutSentinel.checkCookie(cookieName: string): MaybeEmptyString<Cookie>
A recursive function that tries to get the cookie running with predefined retry
times. If cannot find the cookie after limited attempts it returns to an empty string.
ArmutSentinel.xhrSend(): void
A recursive function that checks if is there any requests waiting in the queue and if there is any initiates the request. Terminates when there is no request left.
ArmutSentinel.collect(event: MouseEvent, sessionId?: string, screenName?: string): void
Upon getting a new event, it gathers all the necessary information and pushes it to the items
array to be send in the request body.
ArmutSentinel.send(
apiUrl: string,
apiName: string,
sentinelData: EnhancedSentinelDataModel,
onSuccess?: VoidFunction<void>,
onError?: VoidFunction<void>
): void
Bread and butter of the library. Enhances sentinelData with apt fields. Detects environment using window object. Adds given event listeners to xhr request and sets the headers for it. Then adds adds the request to the queue and consumes it using xhrSend
.
License
This project is licensed under MIT.