3.3.15 • Published 2 years ago

cognira-useractivitytracking-react-library v3.3.15

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Cognira's user activity tracking react library

Made with create-react-library

NPM JavaScript Style Guide

Cognira's user activity tracking is a library built with ReactJS that needs minimal effort to be plugged to a react application. It's aimed at tracking user activity like clicks, scroll, navigation, actions ...

Prerequisites

In order to use this library you need to install it and follow the implementation steps below.

Install

npm install --save cognira-useractivitytracking-react-library

Implementation

Step1: Configure App.js

import React, { useEffect } from 'react';
import { Routes, Route, useNavigate } from 'react-router-dom';
import { TrackElement, TrackScroll, TrackPath } from 'cognira-useractivitytracking-react-library'
import 'cognira-useractivitytracking-react-library/dist/index.css'

// create a context for the click tracking so we can use it later on the main routes
export const TrackContext = React.createContext(); 

function App() {

    //usenavigate to detect location change
    const navigate = useNavigate();

    //Start tracking scroll once the application is mounted
    useEffect(() => {
        TrackScroll()
    }, [])

    //When we change the location trigger the trackpath function that will return the time spent on the route
    useEffect(() => {
        let startTime = Date.now() 
        let path = window.location.pathname
        return () => {
            TrackPath(startTime, path);
        }
    }, [navigate])

        return (
        <div className="App">
            {/* Wrap the children off app component in the trackcontext provider so you can use it anywhere in the application */}
            {/* The TrackContext value must be the TrackElement function imported from the library */}
            <TrackContext.Provider value={TrackElement}>
                <div className="layout">
                        <Routes>
                            <Route path='/example-route1/*' element={ <Component1/> } />
                            <Route path='/example-route2/*' element={ <Component2/> } />
                        </Routes>
                </div>
            </TrackContext.Provider>
        </div>
    );
}

export default App;

Step2: Configure main routes

import React, { useEffect, useContext } from 'react'
//Import TrackContext from App.js
import { TrackContext } from '../App';

export default function Component1() {

    //Get the TrackContext value with the useContext hook
    const TrackElement = useContext(TrackContext);

    //The function will start tracking the elements when the route and its children are mounted
    useEffect(() => {
        Track();
    }, [])

    return (
        <React.Fragment>
            <Children />
        </React.Fragment>
    );
}

Step3: Choose how to track your elements

You can track the clicks on elements with two ways:

*Standard click tracking:
    If your element is a button or an input field and you only want to track if it's clicked as a whole element,
    you just need to add the track attribute to the jsx and give it the identifier of the element as a value.

*Click tracking with heatmaps:
    If your element is a complex element like a datagrid or an entire modal and you want to track where users are clicking exactly,
    you just need to add the trackheat attribute to the jsx and give it the identifier of the element as a value.
*Click tracking with hoc:
    if your element is a modal, popover or a dialog you can wrap it in the library's HOC component and add the track attribute to it. if your element is mounted in a portal you need to disable that.
    

examples:

<CustomButton text={ 'Login' } onClick={ loginSubmit } track='buttonLogin'></CustomButton>

<div trackheat={ props.trackheat }>
    <DataGrid rows={ props.rows } columns={ props.columns } />
</div>

<HOC>
    <Popover disablePortal={ true }>
        <div className={ classes.userPopover } trackheat='popovercontainer'>
            <div className={ classes.popoverListItem }><AccountCircleIcon style={ { marginRight: '5px' } } /> Profile</div>
            <div className={ classes.popoverListItem }><SettingsIcon style={ { marginRight: '5px' } } /> Settings</div>
            <div className={ classes.popoverListItem } onClick={ logout }><LogoutIcon style={ { marginRight: '5px' } } /> Logout</div>
        </div>
    </Popover>
</HOC>
-VERY IMPORTANT: you can't use the tracking attributes on custom made components like MUI components ect..

Step4: Add the redux middleware

If you are using redux in your application you can add our redux middleware to track the user actions, their status and the time of the action. in the redux store configuration file:

import { configureStore } from '@reduxjs/toolkit';
import exampleReducer from '../features/products/productsSlice';
//import the logger middleware from the library
import { logger } from 'cognira-useractivitytracking-react-library'

export const store = configureStore({
    reducer: {
        example: exampleReducer,
    },
    //add the middleware to redux default middleware
    middleware:  (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
});

Congrats your application is ready to track.

License

MIT ©

3.3.6

2 years ago

3.3.13

2 years ago

3.3.14

2 years ago

3.3.15

2 years ago

3.2.23

2 years ago

3.2.26

2 years ago

3.2.25

2 years ago

3.2.28

2 years ago

3.2.27

2 years ago

3.2.29

2 years ago

3.2.20

2 years ago

3.2.22

2 years ago

3.2.21

2 years ago

2.11.0

2 years ago

2.10.30

2 years ago

2.11.1

2 years ago

2.10.31

2 years ago

2.10.32

2 years ago

2.10.33

2 years ago

2.10.34

2 years ago

2.10.35

2 years ago

2.10.36

2 years ago

2.10.37

2 years ago

2.10.38

2 years ago

2.10.39

2 years ago

3.2.35

2 years ago

3.2.2

2 years ago

3.2.34

2 years ago

3.2.1

2 years ago

3.2.37

2 years ago

3.2.0

2 years ago

3.2.36

2 years ago

3.2.39

2 years ago

3.2.6

2 years ago

3.2.38

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

2.11.8

2 years ago

2.11.9

2 years ago

2.11.6

2 years ago

2.11.7

2 years ago

3.2.31

2 years ago

2.11.4

2 years ago

3.2.30

2 years ago

2.11.5

2 years ago

3.2.33

2 years ago

2.11.2

2 years ago

3.2.32

2 years ago

2.11.3

2 years ago

2.10.40

2 years ago

2.10.41

2 years ago

2.11.10

2 years ago

2.10.42

2 years ago

2.11.11

2 years ago

2.10.43

2 years ago

2.11.12

2 years ago

2.10.44

2 years ago

2.11.13

2 years ago

2.10.45

2 years ago

2.10.46

2 years ago

2.10.47

2 years ago

2.10.48

2 years ago

2.10.49

2 years ago

2.10.1

2 years ago

2.3.0

2 years ago

2.10.2

2 years ago

2.10.10

2 years ago

2.10.11

2 years ago

2.10.0

2 years ago

2.10.12

2 years ago

2.10.13

2 years ago

2.10.14

2 years ago

2.10.15

2 years ago

2.10.16

2 years ago

3.2.9

2 years ago

2.10.17

2 years ago

3.2.8

2 years ago

2.10.18

2 years ago

3.2.7

2 years ago

2.10.19

2 years ago

3.2.13

2 years ago

3.1.3

2 years ago

3.2.12

2 years ago

3.1.2

2 years ago

3.2.15

2 years ago

3.1.1

2 years ago

3.2.14

2 years ago

3.1.0

2 years ago

3.2.17

2 years ago

3.1.7

2 years ago

3.2.16

2 years ago

3.1.6

2 years ago

3.2.19

2 years ago

3.1.5

2 years ago

3.2.18

2 years ago

3.1.4

2 years ago

2.10.9

2 years ago

2.10.7

2 years ago

2.10.8

2 years ago

2.10.5

2 years ago

2.10.6

2 years ago

3.2.11

2 years ago

2.10.3

2 years ago

3.2.10

2 years ago

2.10.4

2 years ago

2.10.20

2 years ago

2.10.21

2 years ago

2.10.22

2 years ago

2.10.23

2 years ago

2.10.24

2 years ago

2.10.25

2 years ago

2.10.26

2 years ago

2.10.27

2 years ago

2.10.28

2 years ago

2.10.29

2 years ago

3.2.68

2 years ago

3.2.67

2 years ago

3.2.69

2 years ago

3.2.60

2 years ago

3.2.62

2 years ago

3.2.61

2 years ago

3.2.64

2 years ago

3.2.63

2 years ago

3.2.66

2 years ago

3.2.65

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.2.71

2 years ago

3.2.70

2 years ago

3.2.73

2 years ago

3.2.72

2 years ago

3.2.75

2 years ago

3.2.74

2 years ago

3.2.77

2 years ago

3.2.76

2 years ago

3.2.46

2 years ago

3.2.45

2 years ago

3.2.48

2 years ago

3.2.47

2 years ago

3.2.49

2 years ago

3.2.40

2 years ago

3.2.42

2 years ago

3.2.41

2 years ago

3.2.44

2 years ago

3.2.43

2 years ago

2.1.5

2 years ago

2.9.0

2 years ago

3.0.9

2 years ago

3.2.57

2 years ago

3.2.56

2 years ago

3.2.59

2 years ago

3.2.58

2 years ago

3.2.51

2 years ago

3.2.50

2 years ago

3.2.53

2 years ago

3.2.52

2 years ago

3.2.55

2 years ago

3.2.54

2 years ago

3.0.12

2 years ago

3.0.13

2 years ago

2.9.9

2 years ago

3.0.10

2 years ago

3.0.11

2 years ago

3.0.16

2 years ago

3.0.17

2 years ago

3.0.14

2 years ago

3.0.15

2 years ago

2.9.2

2 years ago

2.9.1

2 years ago

2.9.4

2 years ago

2.9.3

2 years ago

2.9.6

2 years ago

2.9.5

2 years ago

2.9.8

2 years ago

2.9.7

2 years ago

3.1.12

2 years ago

3.1.11

2 years ago

3.1.14

2 years ago

3.1.13

2 years ago

3.1.16

2 years ago

3.1.15

2 years ago

3.1.18

2 years ago

3.1.17

2 years ago

3.1.10

2 years ago

3.1.20

2 years ago

3.1.19

2 years ago

2.10.50

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.3.4

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

2.2.1

2 years ago

2.1.2

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.0.9

2 years ago

2.1.0

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

5.0.0

2 years ago

4.0.0

2 years ago

1.0.0

2 years ago