Numbers Produce Meaning

    @beakyn/activity-tracker
    TypeScript icon, indicating that this package has built-in type declarations

    2.4.1-alpha2 • Public • Published

    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 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.

    Keywords

    none

    Install

    npm i @beakyn/activity-tracker

    DownloadsWeekly Downloads

    2

    Version

    2.4.1-alpha2

    License

    MIT

    Unpacked Size

    125 kB

    Total Files

    35

    Last publish

    Collaborators

    • nelsoneldoro
    • jpbeakyn
    • juanpujol
    • abraaoalves
    • falcaoaugustos
    • brunolazarus
    • hileomsi
    • murilopaixao