New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@beakyn/activity-tracker

Package Overview
Dependencies
Maintainers
8
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beakyn/activity-tracker

latest
npmnpm
Version
2.4.2
Version published
Weekly downloads
12
200%
Maintainers
8
Weekly downloads
 
Created
Source

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
  • License

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 tracked
  • tenant (string): The current tenant
  • token (string): The logged user jwt token
  • url (string): The Activity API instance url
  • resourceId (string): Either the user email or their ID, depending on resourceType
  • resourceType (ResourceType): Either .email or .user, depending on resourceId

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.

FAQs

Package last updated on 21 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts