@beakyn/activity-tracker
v2.4.2
Published
<img src="https://static1.squarespace.com/static/5897ae3d1b10e38edfec3e32/t/58986a0dcd0f689b985fb123/1532278715866/?format=1500w" height="30" />
Downloads
48
Keywords
Readme
Beakyn Activity Tracker
This is a custom redux-beacon integration that allows us to have our very own User Activity tracking API as a target.
Table of Contents
Usage
First of all, you must add both redux-beacon
and @beakyn/activity-tracker
as dependencies.
Then, you should have a config
object with the following properties:
appName
(string
): The application which is being trackedtenant
(string
): The current tenanttoken
(string
): The logged user jwt tokenurl
(string
): The Activity API instance urlresourceId
(string
): Either the user email or their ID, depending onresourceType
resourceType
(ResourceType
): Either.email
or.user
, depending onresourceId
For example:
import { ResourceType } from '@beakyn/activity-tracker';
const config = {
appName: 'My Applictation',
tenant: 'My tenant',
token: '...',
url: '...',
resourceId: '...',
resourceType: ResourceType.email,
};
Note: This module detects if it's running in localhost and does nothing there to avoid polluting your analytics with local data. In order to allow traking while on development – and debug sent requests or similar – you may want to add a
devMode: true
property to your config object.
Next step is to define a custom event map like the following:
import { actions as bknAuthActions } from 'bkn-auth';
import { ActivityService } from '@beakyn/activity-tracker';
const { trackEvent } = ActivityService.getInstance(config);
const eventsMap = {
[bknAuthActions.logout.getType()]: trackEvent(action => {
return {
feature: 'App',
action: 'Logged out',
};
}),
};
Last but not least, head over to your Redux store:
import { applyMiddleware, compose, createStore } from 'redux';
import { createMiddleware } from 'redux-beacon';
import { ActivityMiddleware, ResourceType } from '@beakyn/activity-tracker';
import { rootReducer, RootState } from './rootReducer';
import { config, eventsMap } from './utils/activity'; // Or somewhere else you have both
const activityInstance = ActivityMiddleware(config);
const activityMiddleware = createMiddleware(eventsMap, activityInstance);
const middlewares = [activityMiddleware];
const storeEnhancers = [applyMiddleware(...middlewares)];
export const store = createStore<RootState>(
rootReducer,
compose(...storeEnhancers)
);
Then you're done! 🚀
License
This project is licensed under the terms of the MIT license.